Skip to main content

@svatah/yam-gateway

Model gateway: local and frontier backends, caching, redaction, provenance

Exports

ExportKindSignature
anthropicGatewayfunctionexport function anthropicGateway(options: AnthropicGatewayOptions = {}): Gateway
AnthropicGatewayOptionsinterfaceexport interface AnthropicGatewayOptions
assertNoSecretfunctionexport function assertNoSecret(Throw if a secret survived.
CacheEntryinterfaceexport interface CacheEntry
cacheKeyfunctionexport function cacheKey(parts: CacheKeyParts): string
CacheKeyPartsinterfaceexport interface CacheKeyParts
costOffunctionexport function costOf(model: string, tokens: TokenCounts): numberDollars for one call.
credentialInEnvironmentfunctionexport function credentialInEnvironment(env: NodeJS.ProcessEnv = process.env): booleanWhether a credential is resolvable without asking for one.
DEFAULT_MAX_TOKENSvariableDEFAULT_MAX_TOKENS = 4_096The default ceiling. Grounding answers are small; thinking is not billed against it.
DEFAULT_MODELvariableDEFAULT_MODEL = "claude-opus-5"
DiskCacheclassexport class DiskCache implements GatewayCacheOne JSON file per answer, under a directory the caller names.
Efforttypealiasexport type Effort = "low" | "medium" | "high" | "xhigh" | "max";How hard the model should think (output_config.effort).
emptyUsagefunctionexport function emptyUsage(): GatewayUsage
fakeGatewayfunctionexport function fakeGateway(options: FakeGatewayOptions): Gateway
FakeGatewayOptionsinterfaceexport interface FakeGatewayOptions
formatUsdfunctionexport function formatUsd(amount: number): string$0.0123, for a line a person reads.
Gatewayinterfaceexport interface Gateway
GatewayAnswerinterfaceexport interface GatewayAnswer<T>An answer, with what it cost to get (REQ-AGT-3, REQ-NFR-2).
GatewayCacheinterfaceexport interface GatewayCache
GatewayImageinterfaceexport interface GatewayImageAn image, for the vision fallback only (REQ-REC-2).
GatewayRefusalclassexport class GatewayRefusal extends ErrorThe model declined (LLD §10: "refusal stop reason handled as a tier failure").
GatewayRequestinterfaceexport interface GatewayRequest<T>One question.
GatewayShapeErrorclassexport class GatewayShapeError extends ErrorThe model answered, and the answer was not the shape that was asked for.
GatewayUnavailableclassexport class GatewayUnavailable extends ErrorA backend that was configured and could not be reached, or has no credential.
GatewayUsageinterfaceexport interface GatewayUsageRunning totals, for the per-invocation cost line REQ-NFR-2 asks for.
localGatewayfunctionexport function localGateway(options: LocalGatewayOptions): Gateway
LocalGatewayOptionsinterfaceexport interface LocalGatewayOptions
LocalProvidertypealiasexport type LocalProvider = "ollama" | "llamacpp";
LocalRequestBodyinterfaceexport interface LocalRequestBodyThe body sent to a local server, for the same reason render() exists.
MemoryCacheclassexport class MemoryCache implements GatewayCacheAnswers in memory, for tests and for one process's repeated questions.
NO_CACHEvariableNO_CACHE: GatewayCache A cache that keeps nothing. The default when no directory is configured.
pricedfunctionexport function priced(model: string): booleanWhether the cost of this model is a measured number rather than a zero.
Pricesinterfaceexport interface PricesWhat a call cost (REQ-NFR-2: "estimated and actual tokens and cost printed per
PRICESvariablePRICES: Readonly<Record<string, Prices>>
REDACTEDvariableREDACTED = "«redacted»"The marker a redacted secret leaves behind. Matches the runtime's.
redactTextfunctionexport function redactText(text: string, secrets: ReadonlySet<string> | undefined): stringReplace every secret occurrence in a string.
renderfunctionexport function render<T>(request: GatewayRequest<T>, options: RenderOptions): RenderedRequest
RenderedRequestinterfaceexport interface RenderedRequestThe body client.messages.create is called with.
renderLocalfunctionexport function renderLocal<T>(
RenderOptionsinterfaceexport interface RenderOptions
resolveDigestfunctionexport async function resolveDigest(The digest of the weights a server is actually serving (REQ-COMP-3).
schemaOffunctionexport function schemaOf<T>(request: GatewayRequest<T>): Record<string, unknown>The JSON Schema the model is constrained to.
SEEDvariableSEED = 7A fixed seed, so two compiles of one project agree (REQ-COMP-3, REQ-COMP-7).
TokenCountsinterfaceexport interface TokenCounts