Model Resolution
How a model id supplied by a user, an ACP client, or a gateway is mapped onto an
entry in the shipped model catalogue
(core/infrastructure/src/main/resources/model_metadata.json).
Why resolution exists
The catalogue is a fork of LiteLLM’s
model_prices_and_context_window.json. Its keys are provider-scoped
(zai/glm-5.2, azure_ai/DeepSeek-V4-Flash-0731), but the ids that reach the
application rarely match a key exactly:
| Source | Id shape |
|---|---|
Direct provider |
|
Bifrost gateway |
|
Bifrost โ OpenRouter |
|
OpenRouter variants |
|
Bedrock-style |
|
Ollama tags |
|
Fine-tunes |
|
Discovery surfaces |
bare name only โ |
Where it lives
ModelKeyMatcher in us.nineworlds.book.domain.models (:core:domain) is pure
string logic over an injected list of catalogue keys โ no I/O, no coroutines, no
clock, no randomness. ModelMetadataRegistry (:core:infrastructure) loads the
JSON and delegates to it, so metadata and pricing always agree on which entry a
given id refers to.
Returned keys preserve the catalogue’s own spelling, including uppercase: 568 of 4,596 shipped keys (12%) contain uppercase, and a handful of keys differ only by case with different values, so case folding is a fallback after an exact case-preserving match โ never the primary lookup.
Resolution order
The first rule that produces a catalogue key wins.
-
Exact โ the id, case preserved, is a key.
-
Case-folded exact โ the lowercased id is a key.
-
Exact, tag retained โ the id plus its
:tagis a key (Bedrock ids such asamazon.nova-pro-v1:0carry the version in the tag). -
Transport stripped โ leading
bifrost/,openrouter/,litellm/,portkey/segments are removed one at a time, and the first remainder that is a key wins. Stripping is incremental, not greedy:bifrost/openrouter/anthropic/claude-opus-4resolves toopenrouter/anthropic/claude-opus-4, not to the Anthropic-direct key, because the transport the caller named was OpenRouter. -
Tag dropped โ
:freeand friends are stripped (z-ai/glm-5.3-flash:freeโz-ai/glm-5.3-flash). -
Dotted vendor stripped โ Bedrock flattens the vendor into the name, so with no
/present, the text after the final.is retried (anthropic.claude-sonnet-4-6โclaude-sonnet-4-6). -
Scored candidates โ the remaining rules rank every key that matches by model name.
Ordering matters and is load-bearing: rule 4 must precede rule 5, otherwise
bifrost/amazon.titan-image-generator-v2:0 loses its version tag and lands on
the untagged model.
Candidate scoring
When no rule above resolves, candidates are restricted to keys whose model name matches โ exact name first, then snapshots of it โ and ranked by tuple, most significant element first:
-
Name match โ exact name (2) beats snapshot (1). A snapshot is the requested name plus a short version token, so
glm-5.3-flash-001matchesglm-5.3-flash, whilemistral-7b-instruct-v0does not matchmistral. -
Provider โ the key’s provider is the one the caller named (3); the provider appears earlier in the requested path (2); the key has no provider segment, making it the generic entry (1); otherwise (0). Provider spellings are canonicalised, so
z-ai,zai,zai-org, andz-ai-orgare the same vendor. -
Preference โ configured provider order, resolved from
DEFAULT_PROVIDER_PREFERENCE:openrouter,bifrost,litellm,portkey, thendeepseek,deepinfra,baseten,together_ai,fireworks_ai,replicate. Transports first because bifrost routes through OpenRouter; then first-party; then the hosts that publish the model most cheaply. -
Catalogue order โ the final tie-break, so resolution is deterministic for a given catalogue.
Outcomes
| Outcome | Meaning | Registry behavior |
|---|---|---|
|
A catalogue entry was found |
Metadata and pricing read from |
|
Several entries match equally and no preference decides |
First candidate is used; callers should log |
|
No entry matches |
|
Ambiguous exists so the alternative โ silently guessing and billing a model at
another provider’s rates โ is visible instead. With the default preference list
configured, genuine ties are rare; one example is two hosts publishing
DeepSeek-V4.1-Flash-1017 at equal depth with no configured preference.
Costing caveat
Pricing is a guide, not a contract. Real charges are settled on the
OpenRouter side and vary daily, so a resolved entry that differs by provider is
acceptable. What is not acceptable is resolving to a different model, because
the context window drives token budgeting: openrouter/z-ai/glm-5.2 resolving to
Cloudflare’s copy under-counted the window at 262,144 instead of 1,000,000.
Verification
-
ModelKeyMatcherTestโ behavioral contract, one behavior per test -
ModelCatalogResolutionTestโ golden-file guard: every key in the shipped catalogue must resolve to itself, raw andbifrost/-prefixed -
scripts/simulate_registry_resolution.pyโ measures a proposed rule change against the whole catalogue before it is implemented -
scripts/compare_model_metadata.pyโ diffs upstream LiteLLM releases against the fork and produces a merge that preserves localz-ai/*conventions
Current state: 5,311 / 5,311 catalogue keys resolve to themselves exactly,
with no misresolutions. Two keys redirect to a case-twin under a bifrost/
prefix (both resolve correctly unprefixed); that limit is asserted explicitly in
ModelCatalogResolutionTest rather than left implicit.