Skip to main content

Drop-in Tessera integration for Pydantic AI. One line of config routes your Pydantic AI Agent's LLM calls through Tessera's auto-route + auto-cache + auto-compress + auto-batch proxy. Free 60M tokens/mo. Production: 20% of measured savings.

Project description

tessera-pydantic-ai

Drop-in cost optimization for Pydantic AI. Two function calls — one for the underlying SDK client kwargs, one for the Pydantic AI Provider wrapper — and every agent.run_sync() / agent.run() call lands on the Tessera optimization proxy. Auto-route to cheaper-equivalent models, exact + provider-prompt-cache hits, prompt compression with per-stack quality canary, batch arbitrage on async-tolerant calls. Free Dev tier: 60M tokens/month, no card. Production: 20% of measured savings, $0 if we save you nothing.

Companion to tessera-sdk (vanilla provider SDKs), tessera-langchain (LangChain integration), tessera-vercel-ai (Vercel AI SDK integration), tessera-llamaindex (LlamaIndex integration), tessera-mastra (Mastra Agent framework integration), tessera-crewai (CrewAI multi-agent integration), and tessera-autogen (AutoGen 0.4+ multi-agent integration). Same proxy, same mechanic stack, Pydantic AI-shaped API.

PyPI version License: Apache-2.0


What it looks like

from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIChatModel
from tessera_pydantic_ai import tessera_openai_provider

provider = tessera_openai_provider(
    openai_api_key="sk-...",        # your OpenAI key
    tessera_api_key="tsr_...",      # free from tesseraai.io/dev
)

agent = Agent(OpenAIChatModel("gpt-4o", provider=provider))

result = agent.run_sync("Summarize this customer support ticket in 2 sentences.")

One factory call, one Model wrap, one Agent. Your existing Pydantic AI code — tools, structured outputs, run_sync/run, streaming — works unchanged. Anthropic mirror:

from pydantic_ai import Agent
from pydantic_ai.models.anthropic import AnthropicModel
from tessera_pydantic_ai import tessera_anthropic_provider

provider = tessera_anthropic_provider(
    anthropic_api_key="sk-ant-...",
    tessera_api_key="tsr_...",
)
agent = Agent(AnthropicModel("claude-sonnet-4-6", provider=provider))

Prefer explicit control over the underlying AsyncOpenAI / AsyncAnthropic client? Use the pass-through config functions:

from openai import AsyncOpenAI
from pydantic_ai.providers.openai import OpenAIProvider
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai import Agent
from tessera_pydantic_ai import tessera_openai_config

client = AsyncOpenAI(
    api_key="sk-...",
    organization="org-mine",
    **tessera_openai_config(api_key="tsr_..."),
)
provider = OpenAIProvider(openai_client=client)
agent = Agent(OpenAIChatModel("gpt-4o", provider=provider))

Install

pip install tessera-pydantic-ai pydantic-ai openai anthropic

Pydantic AI + the underlying SDK clients (openai, anthropic) are NOT declared as dependencies of this package — install whichever providers you actually use. Tessera's factories import them lazily at call time so importing this package never blows up over missing optional deps.

Get a free Tessera API key (60M tokens/mo, no card) at tesseraai.io/dev — sign-up takes ~30 seconds and returns an instant tsr_… key plus magic-link dashboard access.


Provider support

Provider Pydantic AI Provider class Tessera config function Convenience factory
OpenAI OpenAIProvider tessera_openai_config tessera_openai_provider
Anthropic AnthropicProvider tessera_anthropic_config tessera_anthropic_provider

v0.1 ships OpenAI + Anthropic. Mistral / Groq / Cohere are queued for v0.2 — the Pydantic AI Provider classes for those have a similar custom-client pattern but the exact signature has not been end-to-end verified. Per our diagnostic-vocab-in-writing discipline (every public-surface claim verified before publish), we'd rather ship 2 honest-and-tested providers than 5 claimed-but-unverified ones. See tessera-langchain, tessera-llamaindex, or tessera-vercel-ai for verified Mistral / Groq / Cohere integrations on those frameworks today.

The generic dispatcher tessera_config("openai" | "anthropic", api_key="tsr_...") returns the right kwargs dict regardless of provider. Unknown-provider calls raise ValueError with a v0.2 pointer.


Worked example

Real customer-support agent on gpt-4o, 5B tokens/month, OpenAI list prices:

Stage Cost / mo Saved
Baseline — OpenAI direct via Pydantic AI $24,000
+ Tessera (route, cache, prompt-cache headers, compress, M9 ceiling, batch) $9,400 $14,600
Tessera fee (20% × savings) $2,920
You net pay $12,320 $11,680 / mo saved

Quality canary across the full mechanic stack: mean-score 0.96 (floor 0.95) — 0.95 SLA held all 30 days. Full breakdown: /blog/cut-openai-bill-38-percent-without-quality-regression.


What Tessera does on every Agent call

Same mechanic stack as the main tessera-sdk. Each mechanic is opt-in per workload, observable per request, and bypasses when its quality canary drops below the per-stack 0.95 floor.

Mechanic What it does Typical savings
Auto-route (m1) Route to a cheaper-equivalent model gated by a daily promptfoo canary on your eval set 15–35% on routed calls
Auto-cache (m2) sha256 cache on the canonical request body, 7-day TTL, Cloudflare edge KV 5–40% depending on prompt repetition
Auto-compress (m3) Per-role heuristic compression (system + user toggles independent). Preserves code fences and JSON shapes. 5–15% on prompt tokens
Prompt cache (m6) Inject provider-native cache headers — OpenAI cached-input (50% off), Anthropic cache_control: ephemeral (90% off cache reads) 50–90% on cached prefixes
Context prune (m7) Conservative trim on long conversations (system + last 8 turns; TF-IDF rerank on RAG attachments) 5–25% on multi-turn workloads
Output-length ceiling (m9) Daily compute fits p90 of completion length per workload, injects maxTokens = p90 × 1.3 5–15% on completion cost
Batch arbitrage (m10) Route async-tolerant Agent calls to provider Batch APIs (OpenAI Batch + Anthropic Message Batches both 50% off) 50% on batch-eligible traffic
Cross-provider failover (m11) When primary upstream returns 5xx / connection error / timeout, retry on OpenRouter (opt-in, default OFF) Reliability primitive, n/a cost
Per-provider circuit breaker Rolling 5xx-rate state machine per upstream — when a provider degrades, auto-route skips its intra-provider alternative mappings until the half-open probe succeeds. n/a — keeps the savings stack honest

Pricing

  • Free Dev — 60M tokens/month, 30 requests/minute, all mechanics on, no card. Forever.
  • Production — over 60M tokens/month or higher rate limit. 20% of measured savings only. Zero savings, zero fee. Prepaid Stripe balance, $100 minimum top-up. No subscription, no commit, no minimum monthly.

Existing customers of tessera-sdk, tessera-langchain, tessera-llamaindex, tessera-vercel-ai, or tessera-mastra keep their rate_locked_pct (if any) on this package too — same tsr_… key, same billing record.


FAQ

Q: How is this different from the other tessera-* packages?

Same proxy. Same mechanics. Same billing. The six packages target different code surfaces:

  • tessera-sdk — patches OpenAI / Anthropic / etc. client constructors directly via tessera.activate(key). Use when calling provider SDKs without a framework.
  • tessera-langchain — wires into LangChain ChatModel constructors. Use when you're on LangChain.
  • tessera-llamaindex — wires into LlamaIndex LLM adapter constructors. Use when you're on LlamaIndex.
  • tessera-vercel-ai — wires into the Vercel AI SDK provider factories. Use when you're on ai core + @ai-sdk/*.
  • tessera-mastra — Vercel AI SDK shape but Mastra-positioned. Use when you're on Mastra Agents.
  • tessera-pydantic-ai (this package) — wires into Pydantic AI Provider classes. Use when you're on Pydantic AI.

Pick whichever fits your codebase. Side-by-side install is supported — all six resolve to the same proxy and same billing record.

Q: Why only OpenAI and Anthropic in v0.1?

Honesty over feature breadth. The Pydantic AI Provider class for each LLM accepts a custom underlying-SDK client (e.g. OpenAIProvider(openai_client=...)); we have end-to-end verified that pattern against the OpenAI and Anthropic SDK client constructors. The Mistral / Groq / Cohere Provider classes exist in Pydantic AI but their custom-client shape has not been tested in our CI. Per our public-surface-claim discipline (every claim verified before ship), the unverified providers stay queued for v0.2. The two shipped providers cover ~85% of customer LLM traffic per our outreach research.

Q: Does this break my tools / structured outputs / streaming?

No. The Pydantic AI Provider object that wraps the underlying SDK client is unchanged in shape — agent.run_sync(), agent.run(), tool calls, structured outputs, and streaming all work unchanged. Auto-route gates on tool-calling capability so an agent using tools never gets routed to a non-tool-capable model.

Q: What happens if Tessera's proxy is down?

Your Agent gets HTTP errors instead of LLM responses. On the proxy side, a per-provider circuit breaker tracks rolling 5xx rates and skips degraded providers in auto-route decisions. Cross-provider failover (m11) is opt-in and re-routes to OpenRouter when the primary upstream is down — see the workload toggle in the dashboard.

Q: What happens to my OpenAI / Anthropic rate limits?

They pass through. Tessera does not aggregate quotas across customers. Your provider rate limits apply normally; the proxy enforces only the Tessera tier limits (30 rpm Free Dev, 60 rpm Production by default — higher on request).

Q: Are you storing my prompts and completions?

No. We log only token counts, cost deltas, mechanics_stack, and provider response status. Prompts and completions are never persisted. Full data handling on tesseraai.io/security.

Q: Why are there two API surfaces (tessera_openai_config vs tessera_openai_provider)?

The config function returns the kwargs dict you spread into AsyncOpenAI(...) — explicit, easy to combine with other settings (organization, custom http_client, retry config, etc.). The convenience factory imports AsyncOpenAI + OpenAIProvider for you and pre-merges. Use whichever you find more readable. Both ship in the same package.


Links

Apache-2.0. Built by Tessera (Fintechagency OÜ). Issues: github.com/tessera-llm/tessera-pydantic-ai/issues.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tessera_pydantic_ai-0.1.0.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tessera_pydantic_ai-0.1.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file tessera_pydantic_ai-0.1.0.tar.gz.

File metadata

  • Download URL: tessera_pydantic_ai-0.1.0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for tessera_pydantic_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 33e63b9c38f5cc291c1ab129455f6d68482b072aa69ecb0b6af3ed69429cd568
MD5 68f1b02539d38a06a355ef9c66b447d2
BLAKE2b-256 a920b0738696ac5a3b8708bede1fba41e75b51ed0adc85eda03eee8efd6127c9

See more details on using hashes here.

File details

Details for the file tessera_pydantic_ai-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tessera_pydantic_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83dfcec61b642d8d50635e25bd1da21efa539d2356755b252a5fa0f7901ea0f7
MD5 8c27480c1d87f207dab49a70db9b2bc2
BLAKE2b-256 004e79c12b9b0d1d11289de934e8d5c00c9c1d242fd3fc9b899b902a4f8f73ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page