Structured output with Instructor or function calling is convenient, but the schema you inject is billed as input tokens on every request. This tool estimates that overhead from your actual schema and projects the monthly cost.
How it works
When you ask for structured output, the library serializes your Pydantic model or JSON schema and places it in the prompt (or as a tool/function definition). The model reads that schema to know the output shape — and you pay input-token cost for it each call.
The calculator estimates tokens from the pasted schema using a character-based heuristic tuned for structured text (≈1 token per 3.6 characters, close to BPE tokenizers on JSON and code). It then computes:
overhead/request = schema_tokens × input_price / 1e6
monthly cost = overhead/request × requests_per_day × 30
Worked example
A moderately rich schema of ~900 characters estimates to ~250 tokens. At 1,000,000 requests/month and $1/1M input tokens:
- Overhead per request: 250 × $1 / 1e6 = $0.00025
- Monthly cost: $0.00025 × 1,000,000 = $250/month
That is $3,000/year purely to repeatedly describe the same output shape — a clear candidate for prompt caching or schema trimming.
What drives schema size
Several common practices cause schemas to bloat well beyond what the model needs:
Verbose field descriptions. Instructor encourages adding Field(description="...") to
every attribute. When descriptions run long — a full sentence per field on a
model with 20 fields — you can easily add 400 extra tokens.
Deep nesting. A Pydantic model that embeds sub-models that embed further
sub-models triggers $defs expansion in the JSON schema output. Each additional
level of nesting adds both structural characters and repeated references.
Redundant optional fields. An output schema that includes 10 optional fields
“just in case” injects all of them on every request even when the model returns
none of them. Consider splitting into a smaller required schema with a catch-all
extras: dict for genuinely variable data.
Tool descriptions. When using OpenAI-style tool/function calling, the
description field of the tool object is also billed as input tokens, not just
the parameter schema. Keep tool descriptions concise.
Strategies to reduce overhead
Prompt caching is the highest-leverage fix. A schema is static across calls, which makes it an ideal candidate for prefix caching. Most providers bill cached input tokens at a substantial discount. Position the schema at the very beginning of the system prompt so the cache hit is maximised.
Schema trimming. Remove field descriptions the model does not need to produce
a correct output. Strip title fields (Pydantic adds them by default, the model
ignores them). Remove default values from the schema if they are not structurally meaningful.
Separate hot and cold fields. Send a minimal schema for common responses and only include extra fields for complex request types. Two smaller schemas can be cheaper than one large general one if the complex type is rare.
Tips
- Prompt caching is the single biggest lever; a stable schema is ideal cache content and is billed at a fraction of the normal rate on hits.
- Drop verbose field descriptions and docstrings the model does not need.
- Flatten unnecessary nesting — deeply nested
$defsinflate token counts. - Confirm the exact count with a real tokenizer before optimizing aggressively, and model total spend with the LLM API Cost Calculator.