POST
/
v1
/
ai
/
sql
import { JigsawStack } from "jigsawstack";

const jigsaw = JigsawStack({ apiKey: "your-api-key" });

const response = await jigsaw.text_to_sql({
  "database": "postgresql",
  "prompt": "Find all transactions with amounts exceeding $10,000, sorted by transaction date",
  "sql_schema": "\n          CREATE TABLE Transactions (\n            transaction_id INT PRIMARY KEY, \n            user_id INT NOT NULL,\n            total_amount DECIMAL(10, 2) NOT NULL, \n            transaction_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n            status VARCHAR(20) DEFAULT 'pending',\n            FOREIGN KEY(user_id) REFERENCES Users(user_id)\n          )\n        "
})
{
  "success": true,
  "sql": "SELECT * FROM Transactions WHERE total_amount > 10000 ORDER BY transaction_date;"
}

Request Parameters

Body

prompt
string
required

The natural language prompt that will be translated to an SQL query. Minimum length: 10 characters

sql_schema
string

The database schema where the query will be run. Not required if file_store_key is specified.

database
string

The database type to generate SQL for. Supported values are postgresql, mysql, or sqlite. Specifying this parameter improves SQL generation accuracy by applying database-specific syntax and optimizations.

file_store_key
string

The key used to store the database schema on Jigsawstack file Storage. Not required if sql_schema is specified.

Either file_store_key or sql_schema can be provided not both.
x-api-key
string
required

Your JigsawStack API key

Response Structure

success
boolean

Indicates whether the call was successful.

sql
string

The generated SQL query based on the natural language prompt and provided schema.

import { JigsawStack } from "jigsawstack";

const jigsaw = JigsawStack({ apiKey: "your-api-key" });

const response = await jigsaw.text_to_sql({
  "database": "postgresql",
  "prompt": "Find all transactions with amounts exceeding $10,000, sorted by transaction date",
  "sql_schema": "\n          CREATE TABLE Transactions (\n            transaction_id INT PRIMARY KEY, \n            user_id INT NOT NULL,\n            total_amount DECIMAL(10, 2) NOT NULL, \n            transaction_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n            status VARCHAR(20) DEFAULT 'pending',\n            FOREIGN KEY(user_id) REFERENCES Users(user_id)\n          )\n        "
})
{
  "success": true,
  "sql": "SELECT * FROM Transactions WHERE total_amount > 10000 ORDER BY transaction_date;"
}