The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Refactor: apply early return (#6369)
Hakan Taşköprüa0c5fee61d91
diff --git a/litellm/litellm_core_utils/llm_response_utils/get_headers.py b/litellm/litellm_core_utils/llm_response_utils/get_headers.pyindex 58a5f1715b8..cd49b5a4a87 100644--- a/litellm/litellm_core_utils/llm_response_utils/get_headers.py+++ b/litellm/litellm_core_utils/llm_response_utils/get_headers.py@@ -15,27 +15,28 @@ def get_response_headers(_response_headers: Optional[dict] = None) -> dict:dict: _response_headers with OpenAI headers and llm_provider-{header}"""- if _response_headers is not None:- openai_headers = {}- if "x-ratelimit-limit-requests" in _response_headers:- openai_headers["x-ratelimit-limit-requests"] = _response_headers[- "x-ratelimit-limit-requests"- ]- if "x-ratelimit-remaining-requests" in _response_headers:- openai_headers["x-ratelimit-remaining-requests"] = _response_headers[- "x-ratelimit-remaining-requests"- ]- if "x-ratelimit-limit-tokens" in _response_headers:- openai_headers["x-ratelimit-limit-tokens"] = _response_headers[- "x-ratelimit-limit-tokens"- ]- if "x-ratelimit-remaining-tokens" in _response_headers:- openai_headers["x-ratelimit-remaining-tokens"] = _response_headers[- "x-ratelimit-remaining-tokens"- ]- llm_provider_headers = _get_llm_provider_headers(_response_headers)- return {**llm_provider_headers, **openai_headers}- return {}+ if _response_headers is None:+ return {}++ openai_headers = {}+ if "x-ratelimit-limit-requests" in _response_headers:+ openai_headers["x-ratelimit-limit-requests"] = _response_headers[+ "x-ratelimit-limit-requests"+ ]+ if "x-ratelimit-remaining-requests" in _response_headers:+ openai_headers["x-ratelimit-remaining-requests"] = _response_headers[+ "x-ratelimit-remaining-requests"+ ]+ if "x-ratelimit-limit-tokens" in _response_headers:+ openai_headers["x-ratelimit-limit-tokens"] = _response_headers[+ "x-ratelimit-limit-tokens"+ ]+ if "x-ratelimit-remaining-tokens" in _response_headers:+ openai_headers["x-ratelimit-remaining-tokens"] = _response_headers[+ "x-ratelimit-remaining-tokens"+ ]+ llm_provider_headers = _get_llm_provider_headers(_response_headers)+ return {**llm_provider_headers, **openai_headers}def _get_llm_provider_headers(response_headers: dict) -> dict: