Downsizing logodownsizing
Documentation

Using Downsizing with PydanticAI

Point PydanticAI's model client at Downsizing to route your agents' model calls through Downsizing.


Prerequisites

Before configuring PydanticAI, make sure your Downsizing account can make requests — pay-per-use or a connected subscription both work. PydanticAI ships its model integrations behind optional extras on the pydantic-ai-slim package; install the one for the API you want to use:

bash
pip install "pydantic-ai-slim[anthropic]"
bash
pip install "pydantic-ai-slim[openai]"

(Installing the full pydantic-ai package pulls in both, plus every other provider extra.)

Option A: Anthropic-compatible endpoint (recommended)

PydanticAI's AnthropicProvider wraps an anthropic SDK client, so point that client's base_urlat Downsizing's Anthropic-compatible endpoint and pass it into the provider:

python
from anthropic import AsyncAnthropic
from pydantic_ai import Agent
from pydantic_ai.models.anthropic import AnthropicModel
from pydantic_ai.providers.anthropic import AnthropicProvider

client = AsyncAnthropic(
    api_key="dws_YOUR_API_KEY",
    base_url="http://localhost:3001/YOUR_INFERENCE_ID/anthropic",
)

model = AnthropicModel(
    "claude-opus-4-8",
    provider=AnthropicProvider(anthropic_client=client),
)

agent = Agent(model)

Pass the resulting model to any Agent in your application, or override it per-run via agent.run(..., model=model).

Option B: OpenAI-compatible endpoint

For OpenAI-style models, use OpenAIResponsesModel, which targets the Responses API, together with OpenAIProvider. Set base_urlto Downsizing's OpenAI-compatible endpoint:

python
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIResponsesModel
from pydantic_ai.providers.openai import OpenAIProvider

model = OpenAIResponsesModel(
    "gpt-5",
    provider=OpenAIProvider(
        base_url="http://localhost:3001/YOUR_INFERENCE_ID/openai/v1",
        api_key="dws_YOUR_API_KEY",
    ),
)

agent = Agent(model)

PydanticAI also ships OpenAIChatModel, which targets the older Chat Completions API — prefer OpenAIResponsesModelabove when using Downsizing's OpenAI-compatible endpoint.

Configuration

Find your Inference ID and API key on the Inference API page. Replace YOUR_INFERENCE_ID with your workspace UUID and dws_YOUR_API_KEY with your Downsizing API key in either snippet above.

Verify

Run the agent to confirm traffic is routing through Downsizing:

python
result = agent.run_sync("Say hello in one short sentence.")
print(result.output)

If you get a response back, Downsizing is set up correctly. You can also check your savings dashboard to see the request appear in your usage metrics.


Spot an error or something not working? Tell us on Discord or email docs@downsizing.dev.