Pydantic AI providers and model factory for OpenCode Zen and OpenCode Go.
Project description
pydantic-ai-opencode
Pydantic AI providers and a model factory for OpenCode Zen and OpenCode Go.
OpenCode exposes multiple model families through one gateway per service, but those families use different wire formats. This package chooses the right Pydantic AI model class and provider for each OpenCode model id.
Install
pip install pydantic-ai-opencode
or from this checkout:
uv sync
Authentication
Set an API key:
export OPENCODE_API_KEY="..."
or log in with the OpenCode CLI:
opencode auth login
The library checks OPENCODE_API_KEY first, then the matching entry in
~/.local/share/opencode/auth.json, for example:
{
"opencode-go": {
"type": "api",
"key": "..."
}
}
Quick Start
from pydantic_ai import Agent
from pydantic_ai_opencode import opencode_model
agent = Agent(
opencode_model("opencode-go/glm-5.1"),
instructions="You are concise and helpful.",
)
result = agent.run_sync("Explain Pydantic AI in one sentence.")
print(result.output)
Model Factory
Use opencode_model() with OpenCode model ids:
from pydantic_ai_opencode import opencode_model
model = opencode_model("opencode/gpt-5.5")
model = opencode_model("opencode/claude-opus-4-7")
model = opencode_model("opencode/gemini-3.1-pro")
model = opencode_model("opencode-go/glm-5.1")
model = opencode_model("opencode-go/minimax-m2.7")
You can pass an explicit API key, a custom OpenCode auth file, Pydantic AI model settings, a profile override, or a shared httpx.AsyncClient:
from httpx import AsyncClient
from pydantic_ai_opencode import opencode_model
client = AsyncClient(timeout=30)
model = opencode_model(
"opencode-go/qwen3.6-plus",
api_key="...",
http_client=client,
)
Direct Providers
Use provider classes directly when you need to build the Pydantic AI model yourself or provide a custom SDK client:
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai_opencode import OpenCodeGoProvider
model = OpenAIChatModel(
"glm-5.1",
provider=OpenCodeGoProvider(api_key="..."),
)
agent = Agent(model)
Public providers:
OpenCodeZenProvider: Zen OpenAI client for GPT Responses and chat modelsOpenCodeZenAnthropicProvider: Zen Anthropic client for Claude modelsOpenCodeZenGoogleProvider: Zen Google client for Gemini modelsOpenCodeGoProvider: Go OpenAI client for chat modelsOpenCodeGoAnthropicProvider: Go Anthropic client for MiniMax messages models
Routing
The factory routes models according to OpenCode service and wire format:
opencode/gpt-*:OpenAIResponsesModelopencode/claude-*:AnthropicModelopencode/gemini-*:GoogleModelopencode/<chat-model>:OpenAIChatModelopencode-go/<chat-model>:OpenAIChatModelopencode-go/minimax-*:AnthropicModel
List known models:
from pydantic_ai_opencode import list_models
print(list_models("opencode-go"))
Development
uv sync --extra dev
uv run --extra dev pytest
uv run --extra dev ruff check .
uv build
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_ai_opencode-0.1.0.tar.gz.
File metadata
- Download URL: pydantic_ai_opencode-0.1.0.tar.gz
- Upload date:
- Size: 91.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99ca63dfdfdeaa83ca88c2cfd41b6a4d439224592aaaefffdf6b4aaff09e59d5
|
|
| MD5 |
a72c02b52ed966787a9145482ca87d37
|
|
| BLAKE2b-256 |
a7b6d45a5f281e578bd3064ec21c9013301ce4e1758713a15464a3b3cecf8d6d
|
File details
Details for the file pydantic_ai_opencode-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pydantic_ai_opencode-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca4eeba33a8c629d3d0cf80422656d6eed5b490fd33349b4748cf2c25f5654d9
|
|
| MD5 |
df0ad73a5770a9afa81b38b3d696573e
|
|
| BLAKE2b-256 |
c85d7a0e7c6ca6ac01551416b3efacb7984cb83acdf8213a401194fa3887072f
|