Set it up
You need a Nerdly key (it starts with sk-nerd-): sign in on the API page to get one, and add credit in Billing.
- Install Pydantic AI and put the key in an environment variable.shell1
pip install pydantic-ai2export NERDLY_API_KEY="sk-nerd-…" - Wrap an OpenAICompatibleProvider in OpenAIChatModel and hand it to Agent; output_type returns a typed result.python1
import os2from pydantic import BaseModel3from pydantic_ai import Agent4from pydantic_ai.models.openai import OpenAIChatModel5from pydantic_ai.providers.openai_compatible import OpenAICompatibleProvider67provider = OpenAICompatibleProvider(8"nerdly",9base_url="https://api.nerdly.us/v1",10api_key=os.environ["NERDLY_API_KEY"],11)12model = OpenAIChatModel("deepseek-v4-flash-0731", provider=provider)131415class Solution(BaseModel):16function_name: str17code: str181920agent = Agent(model, output_type=Solution, system_prompt="You write small, correct Python functions.")21result = agent.run_sync("Write a Python function that checks if a string is a palindrome.")22print(result.output)23print(result.usage) - NativeOutput sends the JSON schema through response_format instead of a tool call.python1
from pydantic_ai import NativeOutput23agent = Agent(model, output_type=NativeOutput(Solution))
The examples use deepseek-v4-flash-0731, the most used coding model on Nerdly today; put any id from the models page in its place.
Which model to pick
- Qwen4 35B A3B Uncensored (
qwen4-35b-a3b-uncensored): $0.48 in, $2.40 out per million tokens, 1M context, about 1.4¢ an agent step. - Ergo Uncensored (
ergo-uncensored): $4.40 in, $13.32 out per million tokens, 1M context, about $0.11 an agent step. - GLM-5.3 Abliterated (
glm-5.3-abliterated): $2.33 in, $4.66 out per million tokens, 131K context, about 5.6¢ an agent step. - DeepSeek V4 Flash 0731 (
deepseek-v4-flash-0731): $0.08 in, $0.12 out per million tokens, 1M context, about 0.19¢ an agent step. - DeepSeek V4.1 Flash 1017 (
deepseek-v4.1-flash-1017): $0.25 in, $1.20 out per million tokens, 1M context, about 0.74¢ an agent step. - Claude Opus 5.5 (
claude-opus-5-5): $2.80 in, $10 out per million tokens, 1M context, about 7.6¢ an agent step.
What a session costs
50 chat turns (about 2,000 tokens in and 500 out each) on DeepSeek V4 Flash 0731 cost about 1.1¢, paid from your balance. Every request Pydantic AI sends is priced by its tokens at the model’s rate; a cheaper model costs less, a larger one more.
Things that trip people up
- By default output_type comes back as a tool call, so the model must take tools; NativeOutput needs a model that takes response_format.
- UnexpectedModelBehavior after retries means the model answered in prose instead of the output tool.
- ModelHTTPError with status 404 means base_url lacks /v1.
- Older tutorials show OpenAIModel with OpenAIProvider(base_url=...); both reach the same endpoint, and the docs recommend OpenAICompatibleProvider.
Pydantic AI’s own documentation: ai.pydantic.dev.
More guides
Questions.
Something else? Email hello@nerdly.us
Run Pydantic AI on any model.
Get a key, add credit from $10, and point the tool at Nerdly.
Get a key