Skip to main content
PydanticAI is a Python agent framework from the Pydantic team. It gives you typed dependencies, tool calling, structured outputs, and streaming on top of LLM providers. Venice works as an OpenAI-compatible backend — point OpenAIChatModel at Venice and keep using the rest of the PydanticAI API as usual.

Prerequisites

Setup

Install PydanticAI with OpenAI support:
You can also install the full pydantic-ai package, which includes the OpenAI extras. Add your Venice API key to the environment:
Keep API keys out of source control. Prefer environment variables or a secret manager in production.

Configure Venice as the model provider

Venice speaks the OpenAI Chat Completions API. Use OpenAIChatModel 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

Async usage is the same pattern with await agent.run(...):

Stream a response

Use run_stream when you want tokens as they arrive:

Structured output

Pass a Pydantic model as output_type to validate the agent’s final answer:
Browse models that support structured responses and function calling before relying on tool-based structured output in production.

Tools

Register tools with @agent.tool_plain (no agent context) or @agent.tool (needs RunContext):

Venice-specific parameters

Pass Venice-only options through ModelSettings.extra_body. For example, enable built-in web search with venice_parameters:
You can also override settings per run:
See the API specification for the full venice_parameters list (web scraping, citations, characters, thinking controls, and E2EE toggles).
Use caseModelWhy
General agentsvenice-uncensoredFast, cheap, uncensored
Tool calling / structured outputzai-org-glm-5-1Strong private flagship for agents
Complex reasoningzai-org-glm-5-1Better multi-step planning
Budget / high volumeqwen3-5-9bLow cost per token
Code-focused agentsqwen3-coder-480b-a35b-instructOptimized for code
Model IDs rotate over time — confirm current IDs with 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

Confirm VENICE_API_KEY (or OPENAI_API_KEY) is set in the process that runs the agent. Restart the shell or process after changing environment variables.
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.
Prefer OpenAIChatModel with an explicit OpenAIProvider. Avoid the bare openai: agent shorthand, which may target OpenAI’s Responses API instead of Chat Completions.
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