Repository navigation
feat(messages): passthrough /v1/messages to native endpoints via supported_endpoints #31685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mateo-berri
merged 7 commits into
litellm_internal_staging
from
litellm_lit3750_messages_passthrough
Jun 30, 2026
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ab17460
feat(messages): passthrough /v1/messages to native endpoints via supp…
mateo-berri 926593e
fix(messages): preserve standard-cased caller headers in native passt…
mateo-berri b600631
fix(openai_like/messages): delegate to parent transform and inject an…
cursoragent 107b468
fix: normalize anthropic-beta header key case before beta injection
cursoragent 1f49ef3
style: collapse anthropic-beta header normalization to single line
mateo-berri fd2d145
fix(messages): forward anthropic-beta to native passthrough upstream
mateo-berri 4c1ce65
chore: remove accidentally committed local QA logs and config
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Empty file.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| from typing import Any, Optional | ||
|
|
||
| from litellm.llms.anthropic.experimental_pass_through.messages.transformation import ( | ||
| AnthropicMessagesConfig, | ||
| ) | ||
|
|
||
| DEFAULT_ANTHROPIC_API_VERSION = "2023-06-01" | ||
|
|
||
|
|
||
| class OpenAILikeAnthropicMessagesConfig(AnthropicMessagesConfig): | ||
| """ | ||
| Forwards Anthropic /v1/messages requests to an OpenAI-compatible server that | ||
| also natively exposes the Anthropic Messages API, with no translation. | ||
|
|
||
| Opted into per deployment via ``model_info.supported_endpoints`` containing | ||
| ``"/v1/messages"``. The inbound Anthropic payload (system, cache_control, | ||
| thinking, tools, ...) is forwarded essentially unchanged to | ||
| ``{api_base}/v1/messages``, so Anthropic-only features that the | ||
| Anthropic->OpenAI translation would otherwise drop are preserved. Response | ||
| parsing and streaming are inherited from the native Anthropic config. | ||
| """ | ||
|
|
||
| def validate_anthropic_messages_environment( | ||
| self, | ||
| headers: dict[str, str], | ||
| model: str, | ||
| messages: list[Any], | ||
| optional_params: dict, | ||
| litellm_params: dict, | ||
| api_key: Optional[str] = None, | ||
| api_base: Optional[str] = None, | ||
| ) -> tuple[dict[str, str], Optional[str]]: | ||
| present = {key.lower() for key in headers} | ||
| needs_auth = bool(api_key) and "authorization" not in present and "x-api-key" not in present | ||
| defaults: dict[str, str] = { | ||
| **({"authorization": f"Bearer {api_key}"} if needs_auth else {}), | ||
| **({"anthropic-version": DEFAULT_ANTHROPIC_API_VERSION} if "anthropic-version" not in present else {}), | ||
| **({"content-type": "application/json"} if "content-type" not in present else {}), | ||
| } | ||
| combined = {**headers, **defaults} | ||
| normalized = { | ||
| ("anthropic-beta" if key.lower() == "anthropic-beta" else key): value for key, value in combined.items() | ||
| } | ||
| merged = self._update_headers_with_anthropic_beta( | ||
| headers=normalized, | ||
| optional_params=optional_params, | ||
| ) | ||
| return merged, api_base | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| def get_complete_url( | ||
| self, | ||
| api_base: Optional[str], | ||
| api_key: Optional[str], | ||
| model: str, | ||
| optional_params: dict, | ||
| litellm_params: dict, | ||
| stream: Optional[bool] = None, | ||
| ) -> str: | ||
| if not api_base: | ||
| raise ValueError("api_base is required to forward Anthropic /v1/messages to a native endpoint") | ||
| base = api_base.rstrip("/") | ||
| if base.endswith("/v1/messages"): | ||
| return base | ||
| if base.endswith("/v1"): | ||
| base = base[: -len("/v1")] | ||
| return f"{base}/v1/messages" | ||
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
Empty file.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.