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

z-ai/glm-5.3-flash

Bifrost gateway

bifrost/z-ai/glm-5.3-flash

Bifrost โ†’ OpenRouter

bifrost/openrouter/z-ai/glm-5.3-flash:free

OpenRouter variants

openrouter/z-ai/glm-5.3-flash:free

Bedrock-style

anthropic.claude-sonnet-4-6, amazon.nova-pro-v1:0

Ollama tags

ollama/llama2:13b

Fine-tunes

ft:gpt-3.5-turbo

Discovery surfaces

bare name only โ€” glm-5.3-flash

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.

  1. Exact โ€” the id, case preserved, is a key.

  2. Case-folded exact โ€” the lowercased id is a key.

  3. Exact, tag retained โ€” the id plus its :tag is a key (Bedrock ids such as amazon.nova-pro-v1:0 carry the version in the tag).

  4. 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-4 resolves to openrouter/anthropic/claude-opus-4, not to the Anthropic-direct key, because the transport the caller named was OpenRouter.

  5. Tag dropped โ€” :free and friends are stripped (z-ai/glm-5.3-flash:free โ†’ z-ai/glm-5.3-flash).

  6. 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).

  7. 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:

  1. Name match โ€” exact name (2) beats snapshot (1). A snapshot is the requested name plus a short version token, so glm-5.3-flash-001 matches glm-5.3-flash, while mistral-7b-instruct-v0 does not match mistral.

  2. 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, and z-ai-org are the same vendor.

  3. Preference โ€” configured provider order, resolved from DEFAULT_PROVIDER_PREFERENCE: openrouter, bifrost, litellm, portkey, then deepseek, 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.

  4. Catalogue order โ€” the final tie-break, so resolution is deterministic for a given catalogue.

Outcomes

Outcome Meaning Registry behavior

Resolved(key)

A catalogue entry was found

Metadata and pricing read from key

Ambiguous(candidates)

Several entries match equally and no preference decides

First candidate is used; callers should log

Unresolved

No entry matches

lookup returns null, callers fall back to a minimal ModelMetadata(id)

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 and bifrost/-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 local z-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.