Interface: IModelRegistry
Defined in: internal/model-registry/types.ts:24
Global catalog of usable models: facts, not tenant choices. Global by design; no tenantId.
Implemented by ModelRegistry; the type of IAIGatewayDeps.modelRegistry, so a host may pass its own in overrides.
Methods
estimateCostUsd()
estimateCostUsd(
args):Promise<number>
Defined in: internal/model-registry/types.ts:78
estimateCostUsd -- the USD estimate of one call, from its token counts
About
uncached × costIn + cache reads × costCacheRead + cache writes × costCacheWrite + output × costOut, per million tokens.
The uncached input is inputTokens minus the cached and the cache-write tokens, never below zero (a provider that reports
more cached tokens than the total yields no negative count). The cache rates are the caps' (costCacheReadPerMTokUsd,
costCacheWritePerMTokUsd) or their provider defaults: Anthropic 0.1 × and 1.25 × the input price, any other provider the
input price. Works for a disabled model too: a call that was in flight when the model got disabled is still reported.
Who needs it
LLMClient, after every call, for the UsageGuard and the trace.
Parameters
args
cachedInputTokens?
number
Of inputTokens, the ones read from the provider's cache.
cacheWriteInputTokens?
number
Of inputTokens, the ones written to the provider's cache.
inputTokens
number
Prompt tokens, the cached ones included.
modelId
string
Our model id.
outputTokens
number
Completion tokens.
Returns
Promise<number>
getModel()
getModel(
args):Promise<IModelInfo>
Defined in: internal/model-registry/types.ts:40
getModel -- one model entry, enabled
About
The facts of a model, for a call that is about to use it.
Reads the cached catalog and returns a copy of the entry. An unknown id is a 404, a disabled one a 400: a call never reaches a model the platform switched off.
Who needs it
prepareCall (the profile's model, step 1), AIProfileStore.upsertProfile (the profile's models must exist and be
enabled), LLMClient (provider and provider id of every call), the guardrails' judge, AIGateway.resume.
Parameters
args
modelId
string
Returns
Promise<IModelInfo>
listModels()
listModels(
args?):Promise<IModelInfo[]>
Defined in: internal/model-registry/types.ts:55
listModels -- the catalog, for an administration screen or a profile editor
About
Every model the platform knows, enabled ones by default, one provider on request.
Read from the cache; copies, in the repository's order.
Who needs it
The host's administration screen and profile editor; the dev sandbox.
Parameters
args?
enabledOnly?
boolean
Skip disabled entries. Default true.
provider?
Filter by provider.
Returns
Promise<IModelInfo[]>
refresh()
refresh():
Promise<void>
Defined in: internal/model-registry/types.ts:149
refresh -- drops the cache and reloads the catalog from the repository
About
For a host that changed the repository behind the registry's back.
The next reads are served from the reloaded catalog; nothing else changes.
Returns
Promise<void>
removeModel()
removeModel(
args):Promise<void>
Defined in: internal/model-registry/types.ts:138
removeModel -- deletes a model entry
About
Gone for good: prefer
setEnabledto keep the entry and its history.
An unknown model is the 404 of getModel. The registry is global and knows no profiles: a profile that names the
removed model is refused at its next call with the same 404, so switch the profiles first.
Parameters
args
modelId
string
Returns
Promise<void>
setEnabled()
setEnabled(
args):Promise<void>
Defined in: internal/model-registry/types.ts:121
setEnabled -- switches a model off, or on again, without deleting it
About
A disabled model is refused by every call that names it; its entry, its profiles and its history stay.
Saves the entry with the new flag and drops the cache, so the next call reads it. An unknown model is the 404 of
getModel. A call in flight on the model finishes and is reported (estimateCostUsd reads disabled entries too).
Who needs it
The administration screen of the platform; a profile that names the model is not touched and fails at its next call.
Parameters
args
enabled
boolean
New state.
modelId
string
Our model id.
Returns
Promise<void>
upsertModel()
upsertModel(
args):Promise<void>
Defined in: internal/model-registry/types.ts:105
upsertModel -- inserts or replaces a model entry
About
The administration write: the entry as given, whole, and the cache dropped.
Saves through the repository and drops this instance's cache, so the next read sees the entry; other instances see it after their TTL. No validation of the entry beyond its type: the host's screen is the editor.
Who needs it
The host's administration screen; the tests and the first run, to seed the catalog.
Parameters
args
model
Returns
Promise<void>