| 2341 | |
| 2342 | |
| 2343 | class ProxyBaseLLMRequestProcessing: |
| 2344 | def __init__(self, data: dict, served_model: str | None = None): |
| 2345 | self.data = data |
| 2346 | self.served_model = served_model |
| 2347 | self._tags_before_guardrails: frozenset[str] | None = None |
| 2348 | self.route_type: str | None = None |
| 2349 | |
| 2350 | @property |
| 2351 | def litellm_call_id(self) -> str | None: |
| 2352 | return request_litellm_call_id(self.data) |
| 2353 | |
| 2354 | @staticmethod |
| 2355 | def _merge_passthrough_streaming_headers( |
| 2356 | response_headers: httpx.Headers | dict | None, |
| 2357 | custom_headers: Mapping[str, str], |
| 2358 | ) -> dict: |
| 2359 | """ |
| 2360 | Merge upstream passthrough headers with proxy/custom headers. |
| 2361 | |
| 2362 | Proxy/custom headers win on key collisions. |
| 2363 | """ |
| 2364 | excluded_headers: Final = { |
| 2365 | "transfer-encoding", |
| 2366 | "content-encoding", |
| 2367 | "set-cookie", |
| 2368 | "connection", |
| 2369 | "keep-alive", |
| 2370 | "proxy-authenticate", |
| 2371 | "proxy-authorization", |
| 2372 | "te", |
| 2373 | "trailer", |
| 2374 | "upgrade", |
| 2375 | } |
| 2376 | |
| 2377 | merged_headers: Final = { |
| 2378 | key: value for key, value in dict(response_headers or {}).items() if key.lower() not in excluded_headers |
| 2379 | } |
| 2380 | merged_headers.update(custom_headers) |
| 2381 | return merged_headers |
| 2382 | |
| 2383 | @staticmethod |
| 2384 | def get_custom_headers( |
| 2385 | *, |
| 2386 | user_api_key_dict: UserAPIKeyAuth, |
| 2387 | call_id: str | None = None, |
| 2388 | model_id: str | None = None, |
| 2389 | cache_key: str | None = None, |
| 2390 | api_base: str | None = None, |
| 2391 | version: str | None = None, |
| 2392 | model_region: str | None = None, |
| 2393 | response_cost: float | str | None = None, |
| 2394 | hidden_params: Mapping[str, object] | None = None, |
| 2395 | fastest_response_batch_completion: bool | None = None, |
| 2396 | request_data: dict | None = {}, |
| 2397 | timeout: float | httpx.Timeout | None = None, |
| 2398 | litellm_logging_obj: LiteLLMLoggingObj | None = None, |
| 2399 | read_timing_from_logging_obj: bool = True, |
| 2400 | **kwargs, |
no outgoing calls