UtilMesh
Menu

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.

Filter used on this page: 32K+ context, capability score 30+, paid model. Batch and free listings are excluded from the main table.
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.

ModelInput / 1MOutput / 1MContextCapabilityTask-weighted price1M + 250K monthly
DeepSeek V4.1 Flash 1017DeepSeek$0.030$0.2001.0M32.6value 306.1$0.106$0.080
Claude Haiku 5.5Anthropic$0.100$0.5001M36.5value 130.4$0.280$0.225
Muse EmberMeta$0.100$0.5001.0M36value 128.6$0.280$0.225
GLM 5.3Z.ai$0.070$1.401.0M31.7value 47.4$0.668$0.420
Hy4Tencent$0.417$1.251.0M34.6value 43.7$0.792$0.730
GPT-6.1 TerraOpenAI$1.00$5.001.1M51.3value 18.3$2.80$2.25
Qwen4 MaxAlibaba Qwen$1.43$4.281M42.9value 15.8$2.71$2.49
Muse Spark 1.3Meta$1.25$4.251.0M36.6value 14.1$2.60$2.31
Gemini 3.8 FlashGoogle$0.825$4.131.0M30.8value 13.3$2.31$1.86
Gemini 4 HydrogenGoogle$1.50$7.501.0M53.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.