You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LiteLLM uses provider-prefixed model names (e.g. anthropic/claude-opus-4-8) for routing. When bare model IDs were passed to the Anthropic endpoint, LiteLLM had to infer the provider, which could lead to ambiguous or incorrect routing. The OpenAI endpoint already had a local helper to handle this, but it was narrow in scope and not reusable.
Changes
Introduces a shared normalize_litellm_model_name(model, provider) utility in handler.py that prepends an explicit provider prefix to any model name that doesn't already carry a known LiteLLM provider prefix. The Anthropic endpoint now uses this to ensure model names are prefixed before being forwarded to LiteLLM. The existing OpenAI-specific _normalize_model_name helper is removed and replaced with calls to the shared utility.
How did you test this code?
A new test (test_bare_claude_model_is_prefixed_for_litellm_routing) verifies that a bare model ID sent to the Anthropic /v1/messages endpoint is forwarded to LiteLLM as anthropic/<model>. Existing tests were updated to assert the prefixed model name, and the 429-fallback test now additionally asserts that the Bedrock retry uses the correct bedrock/ prefixed model name.
services/llm-gateway/src/llm_gateway/api/anthropic.py, line 215-222 (link)
model label in metrics differs from the model sent to LiteLLM
handle_llm_request receives model=body.model (bare, e.g. claude-opus-4-8) while request_data["model"] is the normalized anthropic/claude-opus-4-8. This bare value is used for all Prometheus labels and structured-log bindings, so any Anthropic request will surface under the unprefixed model name in dashboards while the sibling _handle_responses handler emits openai/<model> in its metrics. The _handle_responses handler passes model=normalized_model to both data["model"] and handle_llm_request, so that endpoint is self-consistent. Passing model=body.model instead of the normalized model is harmless at runtime, but creates a label inconsistency across endpoints.
Prompt To Fix With AI
This is a comment left during a code review.
Path: services/llm-gateway/src/llm_gateway/api/anthropic.py
Line: 215-222
Comment:
**`model` label in metrics differs from the model sent to LiteLLM**`handle_llm_request` receives `model=body.model` (bare, e.g. `claude-opus-4-8`) while `request_data["model"]` is the normalized `anthropic/claude-opus-4-8`. This bare value is used for all Prometheus labels and structured-log bindings, so any Anthropic request will surface under the unprefixed model name in dashboards while the sibling `_handle_responses` handler emits `openai/<model>` in its metrics. The `_handle_responses` handler passes `model=normalized_model` to both `data["model"]` and `handle_llm_request`, so that endpoint is self-consistent. Passing `model=body.model` instead of the normalized model is harmless at runtime, but creates a label inconsistency across endpoints.
How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---### Issue 1 of 1
services/llm-gateway/src/llm_gateway/api/anthropic.py:215-222
**`model` label in metrics differs from the model sent to LiteLLM**`handle_llm_request` receives `model=body.model` (bare, e.g. `claude-opus-4-8`) while `request_data["model"]` is the normalized `anthropic/claude-opus-4-8`. This bare value is used for all Prometheus labels and structured-log bindings, so any Anthropic request will surface under the unprefixed model name in dashboards while the sibling `_handle_responses` handler emits `openai/<model>` in its metrics. The `_handle_responses` handler passes `model=normalized_model` to both `data["model"]` and `handle_llm_request`, so that endpoint is self-consistent. Passing `model=body.model` instead of the normalized model is harmless at runtime, but creates a label inconsistency across endpoints.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
LiteLLM uses provider-prefixed model names (e.g.
anthropic/claude-opus-4-8) for routing. When bare model IDs were passed to the Anthropic endpoint, LiteLLM had to infer the provider, which could lead to ambiguous or incorrect routing. The OpenAI endpoint already had a local helper to handle this, but it was narrow in scope and not reusable.Changes
Introduces a shared
normalize_litellm_model_name(model, provider)utility inhandler.pythat prepends an explicit provider prefix to any model name that doesn't already carry a known LiteLLM provider prefix. The Anthropic endpoint now uses this to ensure model names are prefixed before being forwarded to LiteLLM. The existing OpenAI-specific_normalize_model_namehelper is removed and replaced with calls to the shared utility.How did you test this code?
A new test (
test_bare_claude_model_is_prefixed_for_litellm_routing) verifies that a bare model ID sent to the Anthropic/v1/messagesendpoint is forwarded to LiteLLM asanthropic/<model>. Existing tests were updated to assert the prefixed model name, and the 429-fallback test now additionally asserts that the Bedrock retry uses the correctbedrock/prefixed model name.Automatic notifications
Docs update