BerriAI/litellm · error · Exception

Required 'OPENAI_API_KEY' in environment to make pass-throug

Error message

Required 'OPENAI_API_KEY' in environment to make pass-through calls to OpenAI.

What it means

Guard in the OpenAI pass-through: after checking the credential router, no OpenAI API key is available, so the proxy falls back to the OPENAI_API_KEY environment variable, which is unset — the request to api.openai.com cannot be authenticated.

Source

Thrown at litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py:1962

        - /openai/v1/chat/completions
        - /openai/v1/assistants
        - /openai/v1/threads

        Dedicated passthrough (for Responses API):
        - /openai_passthrough/v1/responses
        - /openai_passthrough/v1/responses/{response_id}
        - /openai_passthrough/v1/responses/{response_id}/input_items

    [Docs](https://docs.litellm.ai/docs/pass_through/openai_passthrough)
    """
    base_target_url: Final = os.getenv("OPENAI_API_BASE") or "https://api.openai.com/"
    # Add or update query parameters
    openai_api_key: Final = passthrough_endpoint_router.get_credentials(
        custom_llm_provider=litellm.LlmProviders.OPENAI.value,
        region_name=None,
    )
    if openai_api_key is None:
        raise Exception("Required 'OPENAI_API_KEY' in environment to make pass-through calls to OpenAI.")

    return await BaseOpenAIPassThroughHandler._base_openai_pass_through_handler(
        endpoint=endpoint,
        request=request,
        fastapi_response=fastapi_response,
        user_api_key_dict=user_api_key_dict,
        base_target_url=base_target_url,
        api_key=openai_api_key,
        custom_llm_provider=litellm.LlmProviders.OPENAI,
    )


def _join_url_paths(base_url: httpx.URL, path: str, custom_llm_provider: litellm.LlmProviders) -> str:
    """
    Properly joins a base URL with a path, preserving any existing path in the base URL.
    """
    # Combine paths via the shared helper so any '..' in the path cannot
    # climb above the configured base path.

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Set OPENAI_API_KEY in the proxy environment.
  2. Alternatively configure the key on the model entry via the UI or config.yaml.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py:1962 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/9b0f46d545897ea2. Report an issue: GitHub.