Welcome to the Python AI SDK
A pure Python re-implementation of Vercel’s popular AI SDK for TypeScript. Get started with AI in minutes, not hours.Quick Start
Get up and running in under 5 minutes with our quick start guide.
Why the Python AI SDK?
Python is the defacto language for AI. However, to actually get started with AI, you’ll need to 1. use a bloated external framework and install a bunch of dependencies, or 2. use an incredibly confusing API client (to simply call an LLM, you needclient.chat.completions.create(**kwargs).result.choices[0].message.content).
Features
- Zero-configuration functions that work consistently across providers
- First-class streaming & tool-calling support
- Strong Pydantic types throughout - you know exactly what you’re getting
- Strict structured-output generation and streaming via Pydantic models
- Provider-agnostic embeddings with built-in batching & retry logic
- Tiny dependency footprint - no bloated external frameworks
Quick Examples
Text Generation
Streaming
Structured Output
Core Functions
Text Generation
Generate text synchronously with
generate_text or stream in real-time with stream_text.Object Generation
Parse model output directly into your own Pydantic models with automatic validation.
Embeddings
Create vector embeddings with
embed and embed_many, plus semantic similarity with
cosine_similarity.Tools
Turn any Python function into an LLM-callable tool with a single decorator.
Supported Providers
OpenAI
GPT models, embeddings, and function calling with full streaming support.
Anthropic
Claude models with OpenAI-compatible API interface.
Installation
Install via UV (Python package manager):Key Benefits
1. Zero Configuration
No complex setup - just import and use:2. Provider Agnostic
Swap providers without changing code:3. Strong Typing
Full Pydantic integration for type safety:4. Built-in Streaming
Real-time text generation:5. Automatic Tool Calling
Define tools once, use everywhere:Documentation Sections
Getting Started
Introduction
Learn about the SDK’s philosophy and core concepts.
Concepts
Understand the fundamental concepts and patterns.
Examples & Guides
Basic Text
Simple text generation examples.
Streaming
Real-time streaming examples.
Structured Output
Working with Pydantic models.
Tool Agent
Building agents with tool calling.
Embeddings Search
Semantic search with embeddings.
Reference
Text Generation
generate_text and stream_text functions.Object Generation
generate_object and stream_object functions.Embeddings
embed, embed_many, and cosine_similarity functions.Tools
tool function for LLM-callable functions.Providers
Supported AI providers and their features.
Types
Type definitions and schemas.
Community & Support
GitHub
View source code, report issues, and contribute.
PyPI
Install the package from PyPI.
Support
Get help with implementation questions.