Python SDK
The OpenRouter Python SDK is a type-safe toolkit for building AI applications with access to 300+ language models through a unified API.
Why use the OpenRouter SDK?
Integrating AI models into applications involves handling different provider APIs, managing model-specific requirements, and avoiding common implementation mistakes. The OpenRouter SDK standardizes these integrations and protects you from footguns.
The SDK provides three core benefits:
Auto-generated from API specifications
The SDK is automatically generated from OpenRouter’s OpenAPI specs and updated with every API change. New models, parameters, and features appear in your IDE autocomplete immediately. No manual updates. No version drift.
Type-safe by default
Every parameter, response field, and configuration option is fully typed with Python type hints and validated with Pydantic. Invalid configurations are caught at runtime with clear error messages.
Actionable error messages:
Type-safe streaming:
Async support:
Installation
Requirements: Python 3.9 or higher
Get your API key from openrouter.ai/settings/keys.