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 need client.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

from ai_sdk import generate_text, openai

model = openai("gpt-4.1-mini")
res = generate_text(model=model, prompt="Tell me a haiku about Python")
print(res.text)

Streaming

import asyncio
from ai_sdk import stream_text, openai

async def main():
    model = openai("gpt-4.1-mini")
    stream_res = stream_text(model=model, prompt="Write a story")

    async for chunk in stream_res.text_stream:
        print(chunk, end="", flush=True)

asyncio.run(main())

Structured Output

from ai_sdk import generate_object, openai
from pydantic import BaseModel

class Person(BaseModel):
    name: str
    age: int

model = openai("gpt-4.1-mini")
res = generate_object(
    model=model,
    schema=Person,
    prompt="Create a person named Alice, age 30"
)
print(res.object)  # Person(name='Alice', age=30)

Core Functions

Supported Providers

Installation

Install via UV (Python package manager):
uv add ai-sdk-python
Or with pip:
pip install ai-sdk-python
That’s it - no extra build steps or config files.

Key Benefits

1. Zero Configuration

No complex setup - just import and use:
from ai_sdk import generate_text, openai
res = generate_text(model=openai("gpt-4.1-mini"), prompt="Hello!")

2. Provider Agnostic

Swap providers without changing code:
# Works with any provider
model = openai("gpt-4.1-mini")  # or anthropic("claude-3-haiku-20240307")
res = generate_text(model=model, prompt="Hello!")

3. Strong Typing

Full Pydantic integration for type safety:
from pydantic import BaseModel
from ai_sdk import generate_object

class User(BaseModel):
    name: str
    age: int

res = generate_object(model=model, schema=User, prompt="Create a user")
user = res.object  # Fully typed User instance

4. Built-in Streaming

Real-time text generation:
async for chunk in stream_text(model=model, prompt="Tell a story").text_stream:
    print(chunk, end="", flush=True)

5. Automatic Tool Calling

Define tools once, use everywhere:
add = tool(name="add", description="Add numbers",
           parameters={...}, execute=lambda x, y: x + y)

res = generate_text(model=model, prompt="What's 2+2?", tools=[add])

Documentation Sections

Getting Started

Examples & Guides

Reference

Community & Support


The Python AI SDK is designed to be simple yet powerful. Start with the basics and gradually explore advanced features like tool calling and structured output.