This release is a pre-release and may not be stable for production use.
ai
[!WARNING] This framework is experimental. It is not stable and is not guaranteed to be maintained in the future. For evaluation purposes only.
Python toolkit for building model-powered apps and agent loops.
Install
uv add vercel-ai-sdk
import ai
Quick Start
import asyncio
import ai
@ai.tool
async def get_weather(city: str) -> str:
"""Get the current weather for a city."""
return f"Sunny, 72F in {city}"
async def main() -> None:
model = ai.ai_gateway("anthropic/claude-sonnet-4")
agent = ai.agent(tools=[get_weather])
messages = [
ai.system_message("You are a helpful weather assistant."),
ai.user_message("What's the weather in Tokyo?"),
]
async for msg in agent.run(model, messages):
if msg.text_delta:
print(msg.text_delta, end="", flush=True)
print()
if __name__ == "__main__":
asyncio.run(main())
API Surface
Models
ai.openai(model_id) provider — callable, returns Model
ai.anthropic(model_id) provider — callable, returns Model
ai.ai_gateway(model_id) provider — callable, returns Model
provider.list() list available model IDs from the provider API
ai.stream(model, messages, ...) streaming generation (supports tools=, output_type=)
ai.generate(model, messages, p) non-streaming generation (ImageParams, VideoParams)
ai.check_connection(model) verify credentials and model availability
ai.Client(base_url=, api_key=) explicit client — pass to provider call: ai.openai("gpt-5.4", client=c)
Agents
ai.agent(tools=[...]) agent with tool loop
ai.tool decorator: schema gen + validation + execution
ai.hook(name, payload=, ...) suspension point; resolve with ai.resolve_hook(...)
ai.resolve_hook(name, value) resolve a pending hook from outside the loop
ai.cancel_hook(name) cancel a pending hook
ai.yield_from(...) forward nested agent / streaming tool output
Messages
ai.system_message ai.user_message ai.assistant_message ai.tool_message
ai.tool_result ai.file_part ai.thinking
Middleware
ai.Middleware base class — subclass and override wrap methods
agent.run(..., middleware=[m]) run-scoped, first = outermost
Five wrap surfaces: wrap_agent_run, wrap_model, wrap_generate, wrap_tool, wrap_hook.
Each receives a context dataclass and a next callable. Default implementations pass through.
Integrations
ai.mcp.get_http_tools(url, ...) expose an MCP server as tools
ai.ai_sdk_ui AI SDK UI streaming adapter
Custom Agent Loops
Override the default loop when you need approval gates, routing, or custom orchestration:
@agent.loop
async def custom(context: ai.Context):
while True:
s = await ai.stream(
context.model, context.messages, tools=context.tools
)
async for msg in s:
yield msg
tool_calls = context.resolve(s.tool_calls)
if not tool_calls:
return
results = [await tc() for tc in tool_calls]
yield ai.tool_message(*results)
Examples
Small focused samples live in examples/samples/. End-to-end demos:
examples/fastapi-vite/-- FastAPI backend + Vite frontend with hook-based tool approvalexamples/multiagent-textual/-- Textual TUI with parallel agents and interactive hook resolutionexamples/temporal-direct/-- durable agent with a custom loop (every I/O call is a Temporal activity)examples/temporal-middleware/-- durable agent via middleware (default loop, I/O routed to Temporal activities)examples/samples/middleware_simple.py-- middleware that logs all five execution surfaces
Metadata
Release files for vercel-ai-sdk 0.0.1.dev10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vercel_ai_sdk-0.0.1.dev10.tar.gz | 54.9 kB | Without provenance | Details for vercel_ai_sdk-0.0.1.dev10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vercel_ai_sdk-0.0.1.dev10-py3-none-any.whl | Python 3 | none | any | Details for vercel_ai_sdk-0.0.1.dev10-py3-none-any.whl |
Total release size: 129.6 kB
Release files / vercel_ai_sdk-0.0.1.dev10.tar.gz
| Download URL | vercel_ai_sdk-0.0.1.dev10.tar.gz |
|---|---|
| Size | 54.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c60cc9a57a38000de41875ab240ec401b945f49ac3bb0cc5b503786b86168fd3
|
|
BLAKE2b-256 checksum How to use checksums |
7cf4058b2d8b6c9e347b953af92b5aabc32a29fa5bd42d4baaa6d4ab5b869671
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / vercel_ai_sdk-0.0.1.dev10-py3-none-any.whl
| Download URL | vercel_ai_sdk-0.0.1.dev10-py3-none-any.whl |
|---|---|
| Size | 74.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d86e38b2ef2234f962c2feb4caec1995d252df035238b8fd3b7bc3dbc043d47a
|
|
BLAKE2b-256 checksum How to use checksums |
e91d3d264609a8e40b6ea1aed46e48e80c45e80bba9e06dbae592d51288fc97f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for vercel-ai-sdk 0.0.1.dev10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.