Task shortlist
Cheapest AI models for SQL generation
Text-to-SQL needs schema names, relationships and the user's question in the same prompt. The output is short, but a wrong join or filter can be costly. This shortlist filters for paid models with at least 32K context and a capability floor, then ranks them by capability per dollar.
- Models in shortlist
- 10
- Lowest task-weighted price
- $0.106
- Lowest input price
- $0.030
- Highest capability
- 53.9
The short answer
The first row is DeepSeek DeepSeek V4.1 Flash 1017, at $0.106 per million task-weighted tokens and a value score of 306.1. The strongest model in the filtered list is Google Gemini 4 Hydrogen with a capability index of 53.9. Price and capability are not the same thing; use the table to choose a shortlist, then test it on your own examples.
Models ranked for this task
Task-weighted price uses 55% input and 45% output. The last column is a fixed reference workload of 1M input plus 250K output tokens per month, shown for comparison across pages.
| Model | Input / 1M | Output / 1M | Context | Capability | Task-weighted price | 1M + 250K monthly |
|---|---|---|---|---|---|---|
| DeepSeek V4.1 Flash 1017DeepSeek | $0.030 | $0.200 | 1.0M | 32.6value 306.1 | $0.106 | $0.080 |
| Claude Haiku 5.5Anthropic | $0.100 | $0.500 | 1M | 36.5value 130.4 | $0.280 | $0.225 |
| Muse EmberMeta | $0.100 | $0.500 | 1.0M | 36value 128.6 | $0.280 | $0.225 |
| GLM 5.3Z.ai | $0.070 | $1.40 | 1.0M | 31.7value 47.4 | $0.668 | $0.420 |
| Hy4Tencent | $0.417 | $1.25 | 1.0M | 34.6value 43.7 | $0.792 | $0.730 |
| GPT-6.1 TerraOpenAI | $1.00 | $5.00 | 1.1M | 51.3value 18.3 | $2.80 | $2.25 |
| Qwen4 MaxAlibaba Qwen | $1.43 | $4.28 | 1M | 42.9value 15.8 | $2.71 | $2.49 |
| Muse Spark 1.3Meta | $1.25 | $4.25 | 1.0M | 36.6value 14.1 | $2.60 | $2.31 |
| Gemini 3.8 FlashGoogle | $0.825 | $4.13 | 1.0M | 30.8value 13.3 | $2.31 | $1.86 |
| Gemini 4 HydrogenGoogle | $1.50 | $7.50 | 1.0M | 53.9value 12.8 | $4.20 | $3.38 |
What matters for this task
- The prompt must include table names, column types and relationships, not just the question.
- Dialect differences matter: PostgreSQL, MySQL and SQL Server do not accept the same syntax.
- A cheap model that invents a column can be more expensive than a stronger one.
- Run generated SQL with read-only credentials and a row limit.
What the table does not tell you
- The dataset does not measure SQL accuracy or schema grounding.
- Large schemas may need retrieval or a curated schema summary.
- Always review destructive statements and test against a replica.
Other task shortlists
Questions
What is the cheapest model for SQL generation?
The table ranks models by capability per dollar among paid models with at least 32K context. Validate candidates on your own schema and dialect, because general capability does not guarantee correct joins.
Can I give the model my entire database schema?
Yes, if it fits and the schema is accurate. For large databases, send only the tables relevant to the question and resolve relationships before generation.
Is it safe to execute generated SQL?
Use a read-only account, a statement timeout and a row limit. Keep write and delete operations behind a human approval step.
Prices come from the public model feed and are shown as a recorded snapshot. Confirm the current rate and usage terms on the vendor page before committing to a large workload.