VynarisEarly beta Kimi K3Get your API key

Text-to-SQL agent cost per answered question: the 2.2x retry tax

Text-to-SQL agent cost: $0.31-$23.50 per 1,000 answered questions cached. Caching the schema cuts 67-86%; the 2.2-attempt retry loop is a 2.7x tax.

A text-to-SQL agent costs $0.31 to $23.50 per 1,000 answered questions across six models, cached, a 76x spread, with prices verified 2026-07-27. Two levers set that bill, and neither is the model you pick. Caching the static schema cuts 67% to 86%. And the retry loop, 2.2 execution attempts per answered question, is a 2.6x to 3.3x double-spend most cost models never count. This is a reproducible model, per answered question, you can re-run with your own schema size and retry rate.

The finding, before the model

A talk-to-your-database agent turns a plain-English question into SQL, runs it, and returns rows. The token shape has two features that decide the bill, and both cut against the advice you would use for a chat app.

First, the schema is static. The same table definitions and few-shot examples ride on the front of every call, so prompt caching is decisive here: the 6,000-token schema prefix caches to a tenth of its input price, and to a fiftieth on DeepSeek. This is the mirror image of a meeting summarizer, where the input is unique every time and caching saves almost nothing.

Second, the query either runs or it errors, and a failed query re-prompts the model with the database's error text. That is a retry, and at an average of 2.2 attempts per question you pay for the schema prefix about 2.2 times. But the same fact that costs you money also hands you something rare: a free, hard signal of correctness. The database is the judge, and it never sends an invoice.

We built this from public pricing only. No product data. Every token count below is an assumption you can edit, and every price is from a provider's live page, captured 2026-07-27.

The verdict, cached, per 1,000 answered questions

Model                                                                      Cost / 1k answered  When to pick it
-------------------------------------------------------------------------  ------------------  ---------------------------------------------------------------------------
[deepseek-v4-flash](https://vynaris.com/models#deepseek-v4-flash)          $0.31               Default. Cheapest floor, cache hit at 0.02x, if it clears your accuracy bar
[gemini-3.5-flash-lite](https://vynaris.com/models#gemini-3-5-flash-lite)  $1.87               A cheap non-DeepSeek option inside Google's stack
[gpt-5.4-mini](https://vynaris.com/models#gpt-5-4-mini)                    $3.87               OpenAI-native shops wanting a mid workhorse
[claude-haiku-4.5](https://vynaris.com/models#claude-haiku-4-5)            $4.70               Strong SQL quality per dollar, tight cache discount
[gemini-3.6-flash](https://vynaris.com/models#gemini-3-6-flash)            $7.05               When Flash-Lite misses on complex joins
[claude-opus-5](https://vynaris.com/models#claude-opus-5)                  $23.50              Escalation target for the hard tail, not the default

The cached spread is 76x, from $0.31 to $23.50. It is wider than the uncached 39x spread, because DeepSeek's cache-hit tier drops its schema cost harder than the flat 0.1x the others offer. Caching does not just lower the bill here; it re-orders how far apart the models sit.

The workload (edit these)

One answered question is the outcome unit: a user asks something in English, the agent writes SQL, the query runs, rows come back.

Assumption                Value                                                            Note
------------------------  ---------------------------------------------------------------  -------------------------------------------------------
Schema + few-shot prefix  6,000 [input tokens](https://vynaris.com/glossary/input-tokens)  static, cacheable, sent every call
Question text             150 tokens                                                       the dynamic part of the first call
Retry context added       350 tokens / failed attempt                                      the bad SQL (~200) plus the DB error (~150)
SQL out                   200 [output tokens](https://vynaris.com/glossary/output-tokens)  per attempt
Attempts per question     2.2 average                                                      distribution: 30% one try, 35% two, 20% three, 15% four
Clarify round-trip        15% of questions                                                 one extra call to ask a disambiguating question

That attempt distribution is the number to argue with. An average of 2.2 attempts means roughly 60% of first-pass queries fail to execute, which matches published execution-error rates on complex schemas. Lower it and the whole bill falls, because every retry re-sends the schema and generates another SQL block. Per answered question this rolls up to about 14,100 cacheable prefix tokens, 1,000 dynamic input tokens, and 458 output tokens. The prefix count is 93% of input, which is exactly why caching it is the main event.

The model fee, six models

Same workload, same cost-per-token math, six SQL-capable models, uncached versus cached-schema. Prices verified 2026-07-27.

Model                  Uncached / 1k  Cached / 1k  Caching saves
---------------------  -------------  -----------  -------------
deepseek-v4-flash      $2.24          $0.31        86.3%
gemini-3.5-flash-lite  $5.67          $1.87        67.1%
gpt-5.4-mini           $13.39         $3.87        71.1%
claude-haiku-4.5       $17.39         $4.70        73.0%
gemini-3.6-flash       $26.08         $7.05        73.0%
claude-opus-5          $86.95         $23.50       73.0%
Horizontal grouped bar chart, single blue hue, log x-axis, of text-to-SQL cost per 1,000 answered questions uncached versus cached-schema for six models: deepseek-v4-flash $2.24/$0.31, gemini-3.5-flash-lite $5.67/$1.87, gpt-5.4-mini $13.39/$3.87, claude-haiku-4.5 $17.39/$4.70, gemini-3.6-flash $26.08/$7.05, claude-opus-5 $86.95/$23.50
Text-to-SQL cost per 1,000 answered questions, uncached vs cached schema. Caching the static schema cuts 67-86%. Prices verified 2026-07-27.

Caching a static prefix is worth a flat 73% on the Anthropic and Google models, because the schema is the same 6,000 tokens on every one of the 2.2 attempts and it reads back at 10% of input price. DeepSeek beats that: its cache hit is priced at $0.0028 per million, 2% of its miss rate, so the schema on a cached call is close to free and the saving reaches 86%. The lesson is not "DeepSeek is cheapest" (it is, but that can change). The lesson is that this workload has a large repeated prefix, so if your framework does not cache it, you are paying the uncached column for no reason.

The retry double-spend

The retry is the tax nobody puts in the spreadsheet. Compare the real 2.2-attempt loop against a fantasy where every query runs first try, both with the schema cached.

Model                  1-attempt fantasy / 1k  Real 2.2-attempt / 1k  Retry tax
---------------------  ----------------------  ---------------------  ---------
deepseek-v4-flash      $0.09                   $0.31                  3.28x
gemini-3.5-flash-lite  $0.72                   $1.87                  2.58x
claude-haiku-4.5       $1.75                   $4.70                  2.69x
claude-opus-5          $8.75                   $23.50                 2.69x

The retry tax runs 2.6x to 3.3x. It is a touch higher than the raw 2.2 attempts because each retry also carries the growing error context, and highest on DeepSeek, where the cached schema is so cheap that the retries' fresh output tokens dominate the bill. This is a distinct cost from routing escalation. A confidence-gated cascade double-spends when it escalates a question to a second, pricier model. The retry double-spend happens on the same model, before any routing, every time a query comes back with a syntax or column error. Cut your first-pass execution rate and you cut this tax directly, which is why schema-linking quality and few-shot examples pay for themselves faster than a model swap.

Where routing changes the unit economics

Routing a text-to-SQL agent has a property most LLM workloads never get: a free, correct ground-truth signal. The query runs or it does not. So you can escalate on an actual execution failure, not on a guessed confidence score. Run a cheap model first, and hand off to a stronger one only when the cheap model's SQL errors twice.

Consider deepseek-v4-flash as the first tier, up to two attempts, escalating to claude-opus-5 only when both cheap attempts fail to execute. With a 55% per-attempt failure rate on the cheap model, that escalation fires on 30.3% of questions. You can pre-fill your own schema and output size in the calculator to see the shape on your data.

Strategy (cached)                                Cost / 1k answered
-----------------------------------------------  ------------------
All claude-opus-5                                $23.50
Routed: deepseek first, opus on execution error  $5.16
All claude-haiku-4.5                             $4.70
All deepseek-v4-flash                            $0.31

Read that table honestly. The routed blend is 78% below all-Opus, but it is 10% more expensive than simply running everything on cached Haiku, and about 17x the all-DeepSeek floor. Routing to a frontier model does not save you money against a competent cheap model that already resolves most questions. What it buys is correctness on the hard 30% the cheap model cannot get to run. The reason to route here is quality on the tail, and the reason the routing is efficient is the free signal: your escalation rate equals the cheap model's real failure rate, with no wasted escalations and no judge model to pay for, which is the overhead a confidence-based router carries.

When 2.2 cheap attempts beat one frontier call

Here is the number that should settle most model debates for this workload. A full 2.2-attempt retry loop on cached deepseek-v4-flash costs $0.31 per 1,000 questions. One clean, single-attempt call on cached claude-opus-5 costs $8.75. The cheap model, retries and all, is 28x cheaper than one frontier call that never fails.

So the frontier model has to do more than answer correctly. It has to answer correctly often enough that its near-zero retry rate offsets a 28x higher per-call price, and it almost never does at this workload's token shape. Frontier models earn their place as the escalation target for queries a cheap model provably cannot run, not as the default that answers the easy 70% at 28x the cost.

Build notes

A token model does not capture the constraints that actually decide a text-to-SQL agent.

When this workload does not need a router

The honest tradeoff: if one cheap model writes correct SQL often enough for your schema, do not build a router. At cached deepseek-v4-flash you are at $0.31 per 1,000 answered questions, and cached claude-haiku-4.5 is $4.70 with strong SQL quality. A router only earns its keep when the cheap model's execution-failure rate is high enough that the escalated frontier model meaningfully lifts the share of questions that resolve correctly. If your queries are simple lookups and single joins, a cheap model clears them and the router is complexity with no payoff. Route to raise correctness on a hard tail you can measure, never to shave a bill that caching already made small.

FAQ

What does a text-to-SQL agent cost per answered question? In model fees, $0.0003 to $0.0235 per answered question across deepseek-v4-flash through claude-opus-5, cached, on a workload of a 6,000-token schema prefix, ~1,000 dynamic input tokens, 458 output tokens, and 2.2 attempts. Per 1,000 answered questions that is $0.31 to $23.50 cached. Prices verified 2026-07-27.

Why does caching matter so much here? The database schema and few-shot examples are static and make up 93% of input, and they re-send on every one of the 2.2 attempts. Caching that prefix reads it back at 10% of input price, or 2% on DeepSeek, cutting the bill 67% to 86%. This is the opposite of a summarizer, where the input is unique and caching does nothing.

What is the retry double-spend? A text-to-SQL query either runs or errors, and a failed query re-prompts the model with the error text. At 2.2 attempts per question, you pay 2.6x to 3.3x what a single clean attempt would cost. Lowering your first-pass execution-failure rate cuts this tax directly, faster than switching models.

When should I escalate to a frontier model? When the query actually fails to execute, not when a confidence score looks low. The database gives you a free, correct pass/fail signal, so you escalate only real failures with no wasted frontier calls. In the model above, a cheap-first router escalates on 30.3% of questions and lands at $5.16 per 1,000.

Is a frontier model ever the cheap choice? Almost never as the default. A full 2.2-attempt loop on cached deepseek-v4-flash is 28x cheaper than one single-attempt call on cached claude-opus-5. Frontier models belong on the escalation path for questions a cheap model cannot get to run, not on the easy majority.

Sources

Prices change. We re-verify every figure in this post monthly and stamp updates. Numbers here are current as of 2026-07-27.

The lesson from the model: a text-to-SQL agent's bill is set before you pick a model. Cache the static schema, because it is 93% of input and repeats on every retry. Count the retry loop, because 2.2 attempts is a 2.7x tax hiding in plain sight. And escalate on the database's free pass/fail signal, not on a guessed confidence. Vynaris is an OpenAI-compatible gateway that caches the repeating prefix, routes on real execution outcomes, and shows the per-answered-question cost so you watch the number that matters. One base URL swap. Get an API key at vynaris.com.