Learning resourcesReviewed · Pydantic

Pydantic AI Gateway documentation

This guide explains Pydantic AI Gateway for developers who want one API key for models from several AI providers, but it requires a Pydantic Logfire account and does not state service prices. It covers Python and TypeScript integrations, coding assistants, provider routing, observability and spending controls.

Researched 15 Nov 2026

In short.

This page is Pydantic's documentation for Pydantic AI Gateway, a service that gives developers one API key for calling AI models from OpenAI, Anthropic, Google Cloud, Groq and AWS Bedrock; it is for developers using Pydantic AI, the OpenAI or Anthropic SDKs, Vercel AI SDK, Claude Code or Codex, it requires a Pydantic Logfire account, and it does not state prices. It documents one-key provider access, native API formats, failover, weighted load balancing and spending limits. A significant limitation is that allowing requests without pricing data excludes their costs from tracking and spending limits. Examples cover Pydantic AI, provider SDKs, Vercel AI SDK, Claude Code and Codex. No examples were executed; reliability, performance and billing accuracy remain unassessed.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage includes the complete selected page at [https://pydantic.dev/docs/ai/overview/gateway/index.md]: overview, account setup, all integration examples, request-cost accounting, endpoint routing and pricing-data troubleshooting. The introductory documentation-index and agent-query notices concern documentation access and do not establish Gateway runtime requirements. Linked pages, repositories, pricing information and legal terms are excluded. No code or service configuration was executed; model availability, runtime behavior, reliability, performance and billing accuracy remain untested.

The overview

Identity

The resource is the Pydantic AI Gateway documentation page at [https://pydantic.dev/docs/ai/overview/gateway/index.md]. It introduces the Gateway service and supplies account setup, integration examples, routing configuration and troubleshooting guidance.

The service provides access to multiple AI providers through a Gateway key managed in Pydantic Logfire. The page describes cloud and self-hosted availability through Logfire, but does not provide a self-hosting procedure.

Assessment

The guide is useful for developers evaluating centralized credentials, routing, cost controls and request visibility across AI providers. Its concrete environment variables, client configurations and endpoint settings make it more actionable than a product overview alone.

Its strongest decision-relevant detail is the explanation of spending-control exceptions. It does not establish production reliability, latency overhead, contractual guarantees or total operating cost.

Users

The examples address Python developers using Pydantic AI or provider SDKs, TypeScript developers using Vercel AI SDK, and developers configuring Claude Code or Codex. Teams already using Logfire may find the organization-based setup particularly relevant.

Beginners receive a clear account-and-key sequence, but the page assumes familiarity with environment variables, package installation and API clients. Administrators responsible for routing and budgets also need access to their organization's Gateway settings.

Capabilities

The page lists OpenAI, Anthropic, Google Cloud, Groq and AWS Bedrock support. It describes bringing provider API keys or paying for managed inference through the platform, with one Gateway key used by applications.

Documented controls include daily, weekly and monthly spending caps at project, user and API-key levels. Gateway endpoints support failover and weighted load balancing between providers serving the same model.

The service advertises Logfire request observability and enterprise features including SSO, custom roles and permissions. Sending observability data to other OpenTelemetry backends is marked as coming soon. Gemini image-generation routing is mentioned, but its detailed usage is outside this page.

Using it

Requirements

The documented setup requires a Logfire account, a chosen region, Gateway activation in organization settings and a Gateway API key. Provider access uses either configured provider credentials or managed inference.

For the Pydantic AI integration, the page specifies pydantic-ai version 1.16 or later. Other SDK and coding-tool minimum versions are not stated. Regional proxy URLs must match the Logfire region.

The page does not establish which plans include particular features, provider-specific account eligibility, or the infrastructure requirements for self-hosted Logfire.

Mechanism

The Gateway forwards requests using each provider's native API format instead of converting every provider to one common schema. Applications therefore still use the appropriate provider format. Pydantic AI selects it through model strings shaped as gateway/<api_format>:<model_name>.

A gateway endpoint groups providers under a slug. Higher numerical priorities are tried first; providers sharing a priority receive traffic according to their weights. Inactive providers are skipped. A lower-priority tier receives traffic when the higher-priority providers fail.

Pydantic AI can select a provider or endpoint using the route parameter of gateway_provider. SDK integrations instead configure the appropriate regional proxy URL and authenticate with the Gateway key.

Setup

The account sequence is to sign up at [https://logfire.pydantic.dev/], choose a region, activate Gateway in organization settings and create a Gateway API key. For Pydantic AI, the page then sets PYDANTIC_AI_GATEWAY_API_KEY and uses a gateway-prefixed model string.

The Claude Code instructions require logging out first, then configuring ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN. The Codex instructions use a custom provider configuration with the openai-responses proxy and wire_api set to responses. Existing Codex configuration should be amended rather than replaced.

OpenAI SDK, Anthropic SDK and Vercel AI SDK examples each use their matching proxy paths. Their URLs should not be treated as interchangeable: the page distinguishes chat, OpenAI, Anthropic and OpenAI Responses routes.

Example

The Python example creates a Pydantic AI Agent with gateway/openai:gpt-6.1-sol, calls run_sync with a question about the origin of hello world, and prints result.output. It illustrates the gateway-prefixed model string and shared credential configuration.

The routing example creates an Anthropic provider through gateway_provider and sets route to anthropic-routing, the slug of an endpoint configured in Logfire. The page also illustrates a routing arrangement with a 70/30 top-priority split and a lower-priority fallback tier.

These are documentation examples. Their displayed outputs, model availability and runtime behavior were not tested.

Assessment & evidence

Limitations

Native-format forwarding does not create one interchangeable request schema across providers. The documented endpoint routing concerns providers serving the same model; arbitrary cross-model substitution is not established.

Although the page says native-format forwarding gives immediate access to new model features, the default Require pricing data setting rejects requests for models the Gateway has no pricing data for, so a newly released model may be refused until pricing data is added or the toggle is disabled, which removes its cost from tracking and spending limits. The default pricing requirement can block models lacking pricing data: the page documents a 404 response for built-in providers and a 400 response for custom providers.

Support for other OpenTelemetry backends is marked as forthcoming. Retry timing, timeout behavior, streaming failover, rate limits, latency overhead and availability guarantees are not established by this page.

Reasoning

Central credentials and endpoint configuration could reduce credential and routing logic inside applications. That is an inference from the documented design, not a measured productivity result. Provider-native forwarding is particularly relevant when applications need provider-specific features.

The same design makes Logfire configuration and Gateway pricing metadata dependencies of application access and spending controls. Adoption therefore depends on whether centralized management is useful enough to justify those dependencies and the unknown service cost.

Alternatives

Direct provider access is the clearest alternative mentioned in the page, which describes documentation tabs for direct API use alongside Gateway examples. It suits developers who prefer configuring provider access directly and do not need the documented centralized controls.

Cloud and self-hosted Logfire are deployment choices for the same Gateway offering. The selected page supplies no comparison with competing gateways, so comparative pricing, feature coverage and performance remain unknown.

Evidence

The evidence is the complete captured documentation page at [https://pydantic.dev/docs/ai/overview/gateway/index.md], retained as selected-page.txt and captured at 2026-11-15T13:24:22.680Z. Its source revision is sha256:34a4d1ca091a1e9cfec0ca43934d108c038a04fae172849746684cf1c944c41c.

This is first-party documentation containing feature descriptions, configuration examples and troubleshooting details. It provides no independent benchmarks, measured operating results or executed integration evidence. Linked documentation, repositories and service pages are outside the selected scope.

Access & freshness

Costs

Actual prices are unknown. The page offers managed inference and bring-your-own-key access but supplies no subscription prices, inference rate table, gateway fees, minimum commitments or self-hosting costs.

For Pydantic AI, RequestUsage.cost and aggregated RunUsage.cost use Gateway-reported charges, including the documented free response-cache hit. Google and Bedrock integrations fall back to genai-prices estimates when Gateway cost data is absent. Response and embedding-result cost() methods always return estimates.

Spending limits depend on pricing data. With Require pricing data enabled, unpriced models are rejected before forwarding upstream. Disabling that setting allows those requests, but their costs are neither tracked nor counted toward spending limits. No billing reconciliation was performed.

Rights

The supplied page does not state a documentation or example-code license, redistribution permission, service-use terms or upstream model-use rights. Those permissions remain unknown from this evidence.

Prompt and output retention, training use, logging redaction and contractual data-residency guarantees are also unspecified. US and EU proxy examples establish configuration choices, not complete data-handling guarantees.

Freshness

The capture establishes what this page contained on 15 November 2026. The page does not state its publication date, last update date or a Gateway release version.

The pydantic-ai 1.16 minimum is a documented requirement, not evidence of the latest package release. Example model identifiers, current prices and features marked as coming soon require current confirmation before adoption.

Actions

Before adopting the Gateway, confirm pricing, plan eligibility, required models and data-handling terms through the service information at [https://pydantic.dev/ai-gateway]. Choose the integration and regional endpoint matching the application.

A useful evaluation would check a small request, streaming if needed, recorded charges, spending-limit enforcement and a configured provider failure. Include the unpriced-model behavior when assessing budget controls. These are suggested evaluation steps; none was performed.

Evidence for this report

selected-page.txtselected · checked 2026-11-15