API Integration
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": "mysql", "schema": "Items (id, ..." }'
Supported SQL types (optional):
postgresql, mysql, mssql, mariadb, snowflake, bigquery, sqlite, db2, hive, spark, redshift, plsql, clickhouse
Example SQL schema (optional and can be in any similar format):
Employee (id, name, department_id); Department (id, name, address); Salary_Payments (id, employee_id, amount: int, date: navchar);
Response:
{ "output": "SELECT * FROM items WHERE id = 1;", "generation": { "count": 1 } }
Explain SQL
curl -X POST "https://www.text2sql.ai/api/sql/explain" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "prompt": "SELECT * FROM items WHERE id = 1;" }'
Response:
{ "output": "Find all items with id 1.", "generation": { "count": 1 }, }
Regenerate API Key