# SQL from Natural Language (Text-to-SQL Generator)

> SQL from Natural Language (Text-to-SQL Generator) is a paid API for AI agents from x402-deployer.x402-deployer.workers.dev, paid per call via x402, $0.02/call, status unknown (last checked 2026-09-15).

Converts a natural language prompt into a SQL query for a specified database dialect, returning the SQL, an explanation, referenced tables, destructiveness flag, and warnings.

## Facts

- Endpoint: POST https://x402-deployer.x402-deployer.workers.dev/sql-from-prompt
- Price: $0.02/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-15
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/x402-deployer-x402-deployer-workers-dev-a19a7ed4
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_0j5HGjMcktdN8y7rC90Kg

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability x402-deployer-x402-deployer-workers-dev-a19a7ed4 -d '<json body>'
```

Example prompt: Generate a SQL query for Postgres that finds all customers who placed more than 3 orders in the last 30 days — my tables are 'customers' (id, name, email) and 'orders' (id, customer_id, created_at, total). Tell me if the query is destructive and flag any warnings.

## When to prefer this

Use this endpoint when an agent or user needs to generate SQL from plain English without writing queries manually, especially when the target dialect (Postgres, MySQL, BigQuery, Snowflake, SQLite, MSSQL, DuckDB) matters and safety metadata like is_destructive and warnings are needed to prevent accidental data modification.

## Known failure modes

- Ambiguous prompt with no schema provided may produce incorrect or hallucinated table/column names
- Unsupported or mis-specified dialect may fall back to ANSI SQL
- Very complex multi-step queries may produce incomplete or split SQL
- Schema provided does not match the prompt, leading to incorrect column references
- Payment not included or insufficient USDC causes 402 rejection

## How this service works

Text to SQL / NL to SQL / AI SQL generator. Postgres, MySQL, SQLite, BigQuery, Snowflake, MSSQL, DuckDB, ANSI. Optional schema. Returns SQL + explanation + tables_referenced + is_destructive + warnings.

## Output

Returns the generated SQL query string, a plain-English explanation of what the query does, a list of tables referenced, a boolean is_destructive flag indicating whether the query could modify or delete data, and any warnings (e.g. missing indexes, full-table scans, potential data loss).

## Example request

```json
{
 "input": {
  "body": {
   "prompt": "Get all users where status equals active and created_at is in the last 30 days",
   "schema": "CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(255), email VARCHAR(255), status VARCHAR(50), created_at TIMESTAMP);",
   "dialect": "postgres"
  },
  "type": "http",
  "method": "POST",
  "bodyType": "json"
 }
}
```

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "required": [
  "input"
 ],
 "properties": {
  "input": {
   "type": "object",
   "required": [
    "type",
    "method",
    "bodyType",
    "body"
   ],
   "properties": {
    "body": {
     "required": [
      "prompt"
     ],
     "properties": {
      "prompt": {
       "type": "string",
       "description": "Natural-language description of the query to generate. Max 5,000 chars."
      },
      "schema": {
       "type": "string",
       "description": "Optional. Schema description (tables/columns) to ground the generated SQL. Max 30,000 chars."
      },
      "dialect": {
       "enum": [
        "postgres",
        "mysql",
        "sqlite",
        "bigquery",
        "snowflake",
        "mssql",
        "duckdb",
        "ansi"
       ],
       "type": "string",
       "description": "Optional. Target SQL dialect: postgres (default), mysql, sqlite, bigquery, snowflake, mssql, duckdb, or ansi."
      }
     }
    },
    "type": {
     "type": "string",
     "const": "http"
    },
    "method": {
     "enum": [
      "POST"
     ],
     "type": "string"
    },
    "bodyType": {
     "enum": [
      "json",
      "form-data",
      "text"
     ],
     "type": "string"
    }
   },
   "additionalProperties": false
  },
  "output": {
   "type": "object",
   "required": [
    "type"
   ],
   "properties": {
    "type": {
     "type": "string"
    },
    "example": {
     "type": "object",
     "properties": {
      "sql": {
       "type": "string"
      },
      "dialect": {
       "type": "string"
      },
      "is_destructive": {
       "type": "boolean"
      }
     }
    }
   }
  }
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/x402-deployer-x402-deployer-workers-dev-a19a7ed4/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from x402-deployer.x402-deployer.workers.dev](https://www.zero.xyz/host/x402-deployer.x402-deployer.workers.dev/llms.txt)
