🧰 API: Explain SQL
You can call our Explain SQL endpoint in order to generate an explanation for the specified SQL query.
Method
Method: POST
URL: https://ai-query2.p.rapidapi.com/explain_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 explain
model: One of oa_v3, oa_v3_16k, oa_v4, va_v1 or va_v1_32k. Defaults to oa_v3_16k.
Example
Request
import requests
url = "https://ai-query2.p.rapidapi.com/explain_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"
}
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": "1. Retrieve the customer ID, first name, and last name from the customer table.\n2. Retrieve the rental ID, rental date, and return date from the rental table.\n3. Retrieve the amount from the payment table.\n4. Join the customer table with the rental table using the customer ID as the common field.\n5. Join the rental table with the payment table using the rental ID as the common field.\n6. Filter the results to only include rows where the payment amount is greater than 100.\n7. Filter the results to only include rows where the rental date is within the last 6 months.\n8. Return the customer ID, first name, last name, rental ID, rental date, return date, and payment amount for the matching rows."
}