Basics
Build applications with the AI SDK for Python.
The AI SDK for Python is built around a small set of primitives. Each primitive does one job and uses regular Python values where possible, so you can combine the SDK with your own application code instead of moving your code into a framework-specific shape.
What you can build
Start with the model call, then add the pieces your app needs:
- Stream text or structured JSON from a model.
- Generate images, video, and speech with dedicated models.
- Embed text, transcribe audio, and rerank documents.
- Send images, audio, documents, and generated files through messages.
- Define Python tools and let an agent execute them.
- Pause tools for approval with hooks.
- Run subagents as tools and stream their output.
- Bridge agent streams to AI SDK UI clients over Server-Sent Events (SSE).
Main primitives
Modelidentifies the provider model to call.Messagecarries conversation history as typed parts.ai.streamyields model events and aggregates the assistant message.ai.opsruns dedicated model operations that return standalone values.@ai.toolexposes Python functions to models.Agentruns the stream -> tool -> stream loop.ai.hookpauses a workflow for external input.
Example map
Focused samples live in category directories under examples/:
examples/models/stream.pystreams text from a model.examples/models/generate.pyreturns a buffered model response.examples/media/image_generation.pygenerates images.examples/media/embeddings.pyembeds text.examples/media/transcription.pytranscribes audio.examples/media/reranking.pyreranks documents.examples/agents/basic.pyruns the default agent loop.examples/agents/custom_loop.pyoverridesAgent.loop.examples/agents/streaming_tool.pystreams partial output from a tool.examples/agents/subagent.pyruns a subagent as a tool.
End-to-end demos live in
examples/apps/web_agent,
examples/apps/coding_agent,
examples/apps/durable_agent_temporal,
examples/apps/durable_agent_workflows,
and examples/apps/slack_agent.