Pydantic AI with an OpenAI-compatible API: setup
Run Pydantic AI agents, tools and typed outputs on Claude, GPT or Gemini through one key: OpenAIProvider setup, a FallbackModel chain and structured results.
In Pydantic AI, pass OpenAIProvider(base_url="https://api.uplinkswitch.com/v1", api_key=...) to OpenAIChatModel("claude-sonnet-5-5", provider=...), and every UplinkSwitch chat model runs your agents, tools and typed outputs. Use the Chat Completions model class: the docs recommend OpenAIChatModel over the Responses class for OpenAI-compatible services.
A typed agent
import os
from pydantic import BaseModel
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.openai import OpenAIProvider
provider = OpenAIProvider(base_url="https://api.uplinkswitch.com/v1",
api_key=os.environ["UPLINKSWITCH_API_KEY"])
model = OpenAIChatModel("claude-sonnet-5-5", provider=provider)
class Ticket(BaseModel):
category: str
priority: int
agent = Agent(model, output_type=Ticket)
print(agent.run_sync("Checkout page throws 500 for every EU card.").output)A fallback chain in the framework
Pydantic AI's FallbackModel tries models in order when one raises an error. With one provider object you can chain across vendors on the same key:
from pydantic_ai.models.fallback import FallbackModel
chain = FallbackModel(OpenAIChatModel("claude-sonnet-5-5", provider=provider),
OpenAIChatModel("gpt-6.1-sol", provider=provider))
agent = Agent(chain)The gateway also fails over between routes of the same model on its own, so the framework chain only has to handle a whole model being unavailable.
Models that suit typed output and tools
| Model id | Price per 1M (in / out) | Good for |
|---|---|---|
claude-sonnet-5-5 | $1.164 / $2.91 | Tool-heavy agents |
gpt-6.1-sol | $0.582 / $2.91 | Structured extraction |
claude-haiku-5-5 | $0.0582 / $0.1455 | High-volume classification |