What Does This Endpoint Do?
This endpoint allows you to query your database using plain English questions instead of writing SQL. Think of it like having a conversation with your database - you ask questions in natural language, and the API translates them into SQL queries and returns the results.When to Use Natural Language Queries
- For non-technical users who need to query data but don’t know SQL
- For quick data exploration without writing complex SQL queries
- For building conversational interfaces that need to translate user questions into database queries
- For prototyping when you want to quickly test ideas without writing formal queries
How It Works
- You provide a natural language question and specify which table to query
- The API translates your question into a SQL query
- The SQL query is executed against your database
- The results are returned along with the generated SQL for transparency
Request Body
Natural language question to query the database (e.g., “How many active users do we have?”)
The name of the table to query (e.g., “users”)
Response
Indicates if the query was executed successfully
The query results as an array of objects
The SQL query generated from the natural language question
Query execution time in milliseconds
A message indicating the status of the query execution
Code Examples
Example: Basic Natural Language Query
This example shows how to execute a simple natural language query to retrieve active user count.Example: Advanced Natural Language Query
This example shows how to execute a more complex natural language query to analyze sales data.Request Body Explained
The natural language question to ask about your data. Be as specific as possible for better results.Examples: “How many active users do we have?”, “What was the total revenue last month?”, “Which products had the highest sales?”
The name of the table to query. This helps the AI understand the context and structure of your data.Example: “users”, “orders”, “products”
Response Fields Explained
true
if the query was executed successfully, false
otherwise.An array of objects containing the query results. Each object represents a row in the result set.
The SQL query that was generated from your natural language question. This is useful for understanding how the AI interpreted your question.
The time taken to execute the query in milliseconds.
A message indicating the status of the query execution.
Example Response
Common Errors and How to Fix Them
Error | Cause | Solution |
---|---|---|
”Could not understand question” | Question is too vague or uses unknown terms | Rephrase with more specific language and common terms |
”Table not found” | Incorrect table name provided | Verify the table name exists in your database |
”Column not found” | Question references fields that don’t exist | Use field names that match your database schema |
”Query timed out” | Question generates an overly complex query | Simplify your question or break it into smaller parts |
”Unauthorized” | Invalid or missing API key | Check that you’re using a valid API key |
Tips for Better Results
- Be specific: Include relevant details like time periods, categories, or conditions
- Keep it simple: Start with straightforward questions and gradually increase complexity
- Use common terms: Use terms that match your database schema when possible
- Specify the table: Always provide the correct table name to query
- Review the generated SQL: Check the returned SQL to understand how your question was interpreted
Example Questions
Here are some examples of natural language questions you can ask:- “How many users signed up last week?”
- “What’s the average order value for premium customers?”
- “Show me the top 5 products by sales”
- “Count active users by country”
- “What was the total revenue in March 2025?”