API Integration
Each request requires an API key. A request costs 1 credit, a boosted request costs 5 credits.
Generate SQL
curl -X POST "https://www.text2sql.ai/api/sql/generate" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "prompt": "Find all items with id 1.", "type": "postgres", "schema": "items (id: int, ...)", "boosted": false }'
Prompt
Your requirements using natural language.
SQL type (optional)
POSTGRESQL
MYSQL
MSSQL
MARIADB
SNOWFLAKE
BIGQUERY
SQLITE
DB2
HIVE
SPARK
REDSHIFT
PLSQL
CLICKHOUSE
DYNAMODB
SQL schema (optional)
The schema can be represented using pseudo-code or SQL DDL:
CREATE TABLE TABLE_1 ( COLUMN_1 INT NOT NULL, COLUMN_2 VARCHAR(255), PRIMARY KEY (COLUMN_1) );
Boosted (Optional)
Use a more advanced AI model.
Response
{ "output": "SELECT * FROM items WHERE id = 1;", "generation": { "count": 1 } }
Fix SQL
curl -X POST "https://www.text2sql.ai/api/sql/fix" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "query": "SELECT * FROM users WHERE id = 1;", "prompt": "Find all items with id 1.", "error": "No such table: 'users'.", "type": "postgres", "schema": "items (id: int, ...)", "boosted": false }'
Query
The erroneous SQL query
Prompt (Optional)
The original requirements using natural language.
Error (Optional)
The encountered error message.
SQL type (optional)
See generation.
SQL schema (optional)
See generation.
Boosted (Optional)
See generation.
Response
See generation.
Explain SQL
curl -X POST "https://www.text2sql.ai/api/sql/explain" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "query": "SELECT * FROM items WHERE id = 1;" }'
Query
The SQL query to explain.
Response
{ "output": "Find all items with id 1.", "generation": { "count": 1 }, }
Regenerate API Key