Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /BerriAI_litellm /litellm /llms /openai /data_residency.py
| """ | |
| Helpers for resolving OpenAI data-residency (regional processing) from an | |
| api_base URL. | |
| OpenAI enforces hostname-per-region for projects with geography restrictions | |
| enabled and rejects requests sent to the wrong host, so the api_base hostname | |
| is the authoritative signal of which region a request was processed in. | |
| """ | |
| from typing import Final | |
| from urllib.parse import urlparse | |
| # Mapping of OpenAI regional hostnames to the corresponding data-residency | |
| # value used by the cost calculator. See | |
| # https://developers.openai.com/api/docs/pricing for the regional-processing | |
| # uplift these hostnames trigger. | |
| _OPENAI_REGIONAL_HOSTS: Final[dict[str, str]] = { | |
| "eu.api.openai.com": "eu", | |
| "us.api.openai.com": "us", | |
| } | |
| def infer_openai_data_residency(custom_llm_provider: str | None, api_base: str | None) -> str | None: | |
| """ | |
| Derive the OpenAI data-residency region from an api_base URL. | |
| Returns ``"eu"`` for the EU regional host, ``"us"`` for the US regional | |
| host, and ``None`` for the default global host, any non-OpenAI provider, | |
| or any non-OpenAI URL. | |
| """ | |
| if custom_llm_provider != "openai" or not api_base: | |
| return None | |
| try: | |
| host: Final = urlparse(api_base).hostname | |
| except (TypeError, ValueError): | |
| return None | |
| if not host: | |
| return None | |
| return _OPENAI_REGIONAL_HOSTS.get(host.lower()) | |
Xet Storage Details
- Size:
- 1.37 kB
- Xet hash:
- 51b2372fb1337b22f020918a2564839177cc2186da975663048a1c29e8226074
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.