Repository: pydantic/pydantic-ai
File: pydantic_ai_slim/pydantic_ai/providers/gateway.py (Python)

Code before:
@overload
@deprecated('Use `converse` or `anthropic` API type instead of `bedrock` provider type.')
def gateway_provider(
    upstream_provider: Literal['bedrock'],
    /,
    *,
    api_key: str | None = None,
    base_url: str | None = None,
) -> Provider[BaseClient]: ...


@overload
def gateway_provider(
    upstream_provider: str,
    /,
    *,
    api_key: str | None = None,
    base_url: str | None = None,
) -> Provider[Any]: ...


UpstreamProvider = Literal[
    'chat',
    'responses',
    'gemini',
    'converse',
    # Deprecated
    'openai',
    'openai-chat',
    'openai-responses',
    'google-vertex',
    'bedrock',
    # Those two are actually the same on both.
    'anthropic',
    'groq',
]


def gateway_provider(
    upstream_provider: UpstreamProvider | str,
    /,
    *,
    # Every provider
    api_key: str | None = None,
    base_url: str | None = None,
    # OpenAI, Groq, Anthropic & Gemini - Only Bedrock doesn't have an HTTPX client.
    http_client: httpx.AsyncClient | None = None,
) -> Provider[Any]:
    """Create a new Gateway provider.

    Args:

Review comment (suggestion):
This is a breaking change!!!

We do not document `gateway_provider` - I would like to follow the "if it's not documented, it's not public" approach.

---

We could also rename `upstream_provider` to `api_type` here.

---

If we are not okay with this, then the annoying path to deprecation it is...

Code after:
def gateway_provider(
    api_type: Literal['gemini'],
    /,
    *,
    api_key: str | None = None,
    base_url: str | None = None,
    http_client: httpx.AsyncClient | None = None,
) -> Provider[GoogleClient]: ...


@overload
def gateway_provider(
    api_type: str,
    /,
    *,
    api_key: str | None = None,
    base_url: str | None = None,
) -> Provider[Any]: ...


APIType = Literal['chat', 'responses', 'gemini', 'converse', 'anthropic', 'groq']


def gateway_provider(
    api_type: APIType | str,
    /,
    *,
    # Every provider
    api_key: str | None = None,
    base_url: str | None = None,
    # OpenAI, Groq, Anthropic & Gemini - Only Bedrock doesn't have an HTTPX client.
    http_client: httpx.AsyncClient | None = None,
) -> Provider[Any]:
    """Create a new Gateway provider.

    Args:
        api_type: Determines the API type to use.
        api_key: The API key to use for authentication. If not provided, the `PYDANTIC_AI_GATEWAY_API_KEY`
            environment variable will be used if available.
        base_url: The base URL to use for the Gateway. If not provided, the `PYDANTIC_AI_GATEWAY_BASE_URL`
            environment variable will be used if available. Otherwise, defaults to `https://gateway.pydantic.dev/proxy`.
        http_client: The HTTP client to use for the Gateway.
    """
    api_key = api_key or os.getenv('PYDANTIC_AI_GATEWAY_API_KEY')
    if not api_key:
        raise UserError(
            'Set the `PYDANTIC_AI_GATEWAY_API_KEY` environment variable or pass it via `gateway_provider(..., api_key=...)`'
            ' to use the Pydantic AI Gateway provider.'
        )

    base_url = base_url or os.getenv('PYDANTIC_AI_GATEWAY_BASE_URL', GATEWAY_BASE_URL)