Python
The AI Gateway supports Python through two official SDKs.
OpenAI-compatible API - Use the OpenAI Python SDK with AI Gateway, including support for:
- Chat completions and streaming
- Tool calls and structured outputs
- Image attachments and PDFs
- Embeddings and prompt caching
- Reasoning and provider routing
Anthropic-compatible API - Use the Anthropic Python SDK with AI Gateway, including support for:
- Messages and streaming
- Tool calls and extended thinking
- Web search and file attachments
- Claude Code integration
Install your preferred SDK:
Both SDKs support the same authentication methods:
- API key: Use your AI Gateway API key
- OIDC token: Use your Vercel OIDC token (for deployments on Vercel)
Several Python frameworks have dedicated AI Gateway integrations:
- Pydantic AI - Agent framework with native for structured outputs and type validation
- LlamaIndex - Build knowledge assistants with the package
- LiteLLM - Unified LLM interface with native model prefix
See Framework Integrations for the full list.
Was this helpful?