OpenAIChatModel at Venice and keep using the rest of the PydanticAI API as usual.
Prerequisites
- Python 3.9 or later
- A Venice API key
Setup
Install PydanticAI with OpenAI support:pydantic-ai package, which includes the OpenAI extras.
Add your Venice API key to the environment:
Configure Venice as the model provider
Venice speaks the OpenAI Chat Completions API. UseOpenAIChatModel with OpenAIProvider and Venice’s base URL:
Use
OpenAIChatModel (Chat Completions), not OpenAIResponsesModel / the openai: shorthand. Venice’s primary compatibility path is /chat/completions. Pinning Chat Completions avoids Responses-only behavior that OpenAI-default models use in newer PydanticAI versions.Environment variables
OpenAIProvider also reads OPENAI_API_KEY and OPENAI_BASE_URL. You can configure Venice that way instead of passing arguments in code:
Run an agent
await agent.run(...):
Stream a response
Userun_stream when you want tokens as they arrive:
Structured output
Pass a Pydantic model asoutput_type to validate the agent’s final answer:
Tools
Register tools with@agent.tool_plain (no agent context) or @agent.tool (needs RunContext):
Venice-specific parameters
Pass Venice-only options throughModelSettings.extra_body. For example, enable built-in web search with venice_parameters:
venice_parameters list (web scraping, citations, characters, thinking controls, and E2EE toggles).
Recommended models
| Use case | Model | Why |
|---|---|---|
| General agents | venice-uncensored | Fast, cheap, uncensored |
| Tool calling / structured output | zai-org-glm-5-1 | Strong private flagship for agents |
| Complex reasoning | zai-org-glm-5-1 | Better multi-step planning |
| Budget / high volume | qwen3-5-9b | Low cost per token |
| Code-focused agents | qwen3-coder-480b-a35b-instruct | Optimized for code |
GET /models or the models overview.
Privacy advantage
PydanticAI is often used for agents that touch application data, user context, or internal tools. Pairing it with Venice keeps that workflow on private, uncensored inference:- Zero data retention on private models — prompts and tool payloads are not kept after the request
- Uncensored analysis when agents need blunt critique or red-teaming
- OpenAI-compatible plumbing so you can migrate existing PydanticAI apps by changing the provider base URL and API key
Troubleshooting
Model not found or unexpected endpoint errors
Model not found or unexpected endpoint errors
Use a current model ID from the models page. Set
base_url to https://api.venice.ai/api/v1 with no trailing path — PydanticAI appends /chat/completions.Responses API / openai: prefix failures
Responses API / openai: prefix failures
Prefer
OpenAIChatModel with an explicit OpenAIProvider. Avoid the bare openai: agent shorthand, which may target OpenAI’s Responses API instead of Chat Completions.Tools or structured output are ignored
Tools or structured output are ignored
Pick a model that supports function calling, describe when tools should run in
instructions, and keep tool docstrings precise — PydanticAI builds JSON schemas from signatures and docs.PydanticAI Docs
Agents, tools, dependencies, and output types
Venice Models
Browse models and supported capabilities