API Reference
Optimize a SQL Query

🧰 API: Optimize a SQL Query

You can call our SQL optimization endpoint in order to rewrite the specified SQL query.

Method

Method: POST

URL: https://ai-query2.p.rapidapi.com/optimize_sql

Headers:
  X-RapidAPI-Key: Your Rapid API Key, received once subscribed to a plan
  X-RapidAPI-Host: ai-query2.p.rapidapi.com

Params:
  prompt: SQL query to optimize
  model: One of oa_v3, oa_v3_16k, oa_v4, va_v1 or va_v1_32k. Defaults to oa_v3_16k.
  data_source_type: One of postgresql, mysql, mariadb, sqlserver, redshift, snowflake, bigquery or oracle

Example

Request
import requests
 
url = "https://ai-query2.p.rapidapi.com/optimize_sql/"
 
payload = {
	"prompt": "SELECT c.customer_id, c.first_name, c.last_name, r.rental_id, r.rental_date, r.return_date, p.amount FROM customer c, rental r, payment p WHERE c.customer_id = r.customer_id AND r.rental_id = p.rental_id AND p.amount > 100 AND r.rental_date > NOW() - INTERVAL 6 MONTH;",
	"model": "oa_v3_16k",
	"data_source_type": "postgresql"
}
headers = {
	"content-type": "application/json",
	"X-RapidAPI-Key": "Your Rapid API Key, received once subscribed to a plan",
	"X-RapidAPI-Host": "ai-query2.p.rapidapi.com"
}
 
response = requests.post(url, json=payload, headers=headers)
 
print(response.json())
Response
{
  "response": "SELECT c.customer_id, c.first_name, c.last_name, r.rental_id, r.rental_date, r.return_date, p.amount \nFROM customer c\nJOIN rental r ON c.customer_id = r.customer_id\nJOIN payment p ON r.rental_id = p.rental_id\nWHERE p.amount > 100 \nAND r.rental_date > DATE_SUB(NOW(), INTERVAL 6 MONTH);"
}