Repository navigation
fix(azure_ai): add passthrough config so router-model relays reach the deployment's own endpoint #39863
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 35 commits into
litellm_internal_staging
from
litellm_lit_7022_azure_ai_passthrough_config
Sep 10, 2026
Merged
fix(azure_ai): add passthrough config so router-model relays reach the deployment's own endpoint #39863
Changes from 6 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
512e730
fix(azure_ai): add passthrough config so router-model relays reach th…
mateo-berri 4c9537f
chore: merge origin/litellm_internal_staging into litellm_lit_7022_az…
mateo-berri cf275cf
chore: merge origin/litellm_internal_staging into litellm_lit_7022_az…
mateo-berri a276690
fix(router): keep a model's own provider prefix for generic SDK calls
mateo-berri cd25eb9
fix(azure_ai): cost streaming relays and return upstream errors from …
mateo-berri 9ea9aa2
fix(azure_ai): count prompt tokens for streaming relays that carry no…
mateo-berri bbbdccb
fix(azure_ai): count relayed image prompt tokens without fetching the…
mateo-berri 3f69584
fix(router): rewrite the passthrough model group as a whole path segment
mateo-berri df6fb9e
fix(azure_ai): relay from the Foundry root and log non-chat relays fo…
mateo-berri 2f981d1
refactor(passthrough): inject the streaming prompt-token counter inst…
mateo-berri 6ed7269
Merge remote-tracking branch 'origin/litellm_internal_staging' into l…
mateo-berri 4706ace
fix(passthrough): charge remote high-detail images at the high-detail…
mateo-berri 614b151
chore: merge origin/litellm_internal_staging into litellm_lit_7022_az…
mateo-berri 5c23d29
fix(azure_ai): cost OCR relays per page so non-chat relays debit budgets
mateo-berri 22d7616
Merge remote-tracking branch 'origin/litellm_internal_staging' into l…
mateo-berri 6f99917
fix(router): rewrite multi-segment model groups as whole passthrough …
mateo-berri c698dde
fix(azure): let the caller's api-version win over the deployment's on…
mateo-berri 17b7003
fix(azure_ai): cost embeddings, responses, images, and rerank relays …
mateo-berri 12d9413
refactor(passthrough): share the relay shape table and price FLUX 2 p…
mateo-berri 02b18b4
fix(passthrough): match image URL schemes case-insensitively when cou…
mateo-berri 1de369a
fix(passthrough): bound azure relays to the key's model group and rej…
mateo-berri 52e9cfe
fix(azure): price streamed Responses relays and keep a full-URL api_b…
mateo-berri 9666a21
Merge remote-tracking branch 'origin/litellm_internal_staging' into l…
mateo-berri 13db79d
fix(azure_ai): price streamed Responses relays from their terminal event
mateo-berri db59e99
fix(azure): let the caller's api-version override a full-URL api_base…
mateo-berri 5e056a2
refactor(azure): move the passthrough deployment-segment helpers unde…
mateo-berri a892e67
fix(azure): match deployment segments case-insensitively and keep rel…
mateo-berri 4fa34ac
Merge remote-tracking branch 'origin/litellm_internal_staging' into HEAD
mateo-berri 5ea447e
fix(azure): keep the model group segment exact and casefold only depl…
mateo-berri 13745e8
chore: merge litellm_internal_staging into litellm_lit_7022_azure_ai_…
mateo-berri cc0c608
chore: merge litellm_internal_staging into litellm_lit_7022_azure_ai_…
mateo-berri a25ecca
fix(azure_ai): drop the api_base path segments a relay already repeats
mateo-berri 8627576
fix(azure_ai): keep a deployment named like the first native path seg…
mateo-berri a668195
Merge branch 'litellm_internal_staging' into litellm_lit_7022_azure_a…
mateo-berri 966a58d
Merge branch 'litellm_internal_staging' into litellm_lit_7022_azure_a…
mateo-berri 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
Some comments aren't visible on the classic Files Changed page.
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
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
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
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
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
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,124 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Mapping, Sequence | ||
| from typing import TYPE_CHECKING, Final | ||
|
|
||
| from pydantic import BaseModel, ConfigDict, ValidationError | ||
|
|
||
| from litellm.llms.azure_ai.common_utils import ( | ||
| AzureFoundryModelInfo, | ||
| api_key_header_for_base, | ||
| get_azure_ai_auth_headers, | ||
| ) | ||
| from litellm.llms.base_llm.passthrough.transformation import BasePassthroughConfig | ||
| from litellm.types.llms.openai import AllMessageValues | ||
|
|
||
| if TYPE_CHECKING: | ||
| from httpx import URL, Response | ||
|
|
||
| from litellm.litellm_core_utils.litellm_logging import Logging | ||
| from litellm.types.utils import CostResponseTypes | ||
|
|
||
|
|
||
| def strip_leading_model_segment(endpoint: str, model_names: tuple[str, ...]) -> str: | ||
| path: Final = endpoint.lstrip("/") | ||
| for model_name in model_names: | ||
| if not model_name: | ||
| continue | ||
| if path == model_name: | ||
| return "" | ||
| if path.startswith(f"{model_name}/"): | ||
| return path[len(model_name) + 1 :] | ||
| return path | ||
|
|
||
|
|
||
| class PassthroughMetadata(BaseModel): | ||
| model_config = ConfigDict(extra="ignore") | ||
|
|
||
| model_group: str = "" | ||
|
|
||
|
|
||
| def model_group_from(litellm_params: Mapping[str, object]) -> str: | ||
| try: | ||
| return PassthroughMetadata.model_validate(litellm_params.get("litellm_metadata")).model_group | ||
| except ValidationError: | ||
| return "" | ||
|
|
||
|
|
||
| class AzureAIPassthroughConfig(AzureFoundryModelInfo, BasePassthroughConfig): | ||
| def is_streaming_request(self, endpoint: str, request_data: Mapping[str, object]) -> bool: | ||
| return request_data.get("stream") is True | ||
|
|
||
| def get_complete_url( | ||
| self, | ||
| api_base: str | None, | ||
| api_key: str | None, | ||
| model: str, | ||
| endpoint: str, | ||
| request_query_params: Mapping[str, object] | None, | ||
| litellm_params: Mapping[str, object], | ||
| ) -> tuple[URL, str]: | ||
| base_target_url: Final = self.get_api_base(api_base) | ||
| if base_target_url is None: | ||
| raise ValueError("Azure AI api base not found: set `api_base` on the deployment or AZURE_AI_API_BASE") | ||
|
|
||
| native_endpoint: Final = strip_leading_model_segment(endpoint, (model, model_group_from(litellm_params))) | ||
| return ( | ||
| self.format_url(native_endpoint, base_target_url, request_query_params), | ||
| base_target_url, | ||
| ) | ||
|
|
||
| def validate_environment( | ||
| self, | ||
| headers: Mapping[str, str], | ||
| model: str, | ||
| messages: Sequence[AllMessageValues], | ||
| optional_params: Mapping[str, object], | ||
| litellm_params: Mapping[str, object], | ||
| api_key: str | None = None, | ||
| api_base: str | None = None, | ||
| ) -> dict[str, str]: # mutable-ok: base class contract returns dict for httpx | ||
| auth_headers: Final = get_azure_ai_auth_headers( | ||
| api_key=api_key, | ||
| litellm_params=litellm_params, | ||
| api_key_header=api_key_header_for_base(api_base), | ||
| ) | ||
| return {**headers, **auth_headers} # mutable-ok: base class contract returns dict for httpx | ||
|
|
||
| def logging_non_streaming_response( | ||
| self, | ||
| model: str, | ||
| custom_llm_provider: str, | ||
| httpx_response: Response, | ||
| request_data: Mapping[str, object], | ||
| logging_obj: Logging, | ||
| endpoint: str, | ||
| ) -> CostResponseTypes | None: | ||
| from litellm.llms.azure.passthrough.transformation import AzurePassthroughConfig | ||
|
|
||
| return AzurePassthroughConfig().logging_non_streaming_response( # pyright: ignore[reportUnknownMemberType] # the Azure config still types request_data as a bare dict | ||
| model=model, | ||
| custom_llm_provider=custom_llm_provider, | ||
| httpx_response=httpx_response, | ||
| request_data=dict(request_data), # mutable-ok: AzurePassthroughConfig wants a dict | ||
| logging_obj=logging_obj, | ||
| endpoint=endpoint, | ||
| ) | ||
|
|
||
| def handle_logging_collected_chunks( | ||
| self, | ||
| all_chunks: Sequence[str], | ||
| litellm_logging_obj: Logging, | ||
| model: str, | ||
| custom_llm_provider: str, | ||
| endpoint: str, | ||
| ) -> CostResponseTypes | None: | ||
| from litellm.llms.azure.passthrough.transformation import AzurePassthroughConfig | ||
|
|
||
| return AzurePassthroughConfig().handle_logging_collected_chunks( | ||
| all_chunks=all_chunks, | ||
| litellm_logging_obj=litellm_logging_obj, | ||
| model=model, | ||
| custom_llm_provider=custom_llm_provider, | ||
| endpoint=endpoint, | ||
| ) |
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
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
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
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.