API Reference
Suggest Indexes

🧰 API: Suggest Indexes

You can call our Suggest Indexes endpoint in order to generate suggested indexes for the specified SQL query.

Method

Method: POST

URL: https://ai-query2.p.rapidapi.com/index_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 for index suggestions
  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/index_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 JOIN rental r ON c.customer_id = r.customer_id JOIN payment p ON r.rental_id = p.rental_id WHERE 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": "CREATE INDEX idx_customer_id ON customer (customer_id);\nCREATE INDEX idx_rental_customer_id ON rental (customer_id);\nCREATE INDEX idx_rental_rental_date ON rental (rental_date);\nCREATE INDEX idx_payment_rental_id ON payment (rental_id);\nCREATE INDEX idx_payment_amount ON payment (amount);"
}