Skip to main content
ClaudeChatGPT

Quick Start

Use this guide to make your first Wren AI API call and confirm that your key, project, and request flow are working correctly.

Prerequisites

  • A Wren AI account
  • An API key (see Manage API Keys)
  • A project ID for the project you want to query

Basic example

Here's a simple example of generating a SQL query using curl:

curl -X POST 'https://cloud.getwren.ai/api/v1/generate_sql' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"projectId": YOUR_PROJECT_ID,
"question": "Show me all customers"
}'

Response:

{
"id": "1fbc0d64-1c58-45b2-a990-9183bbbcf913",
"sql": "SELECT * FROM \"olist_customers_dataset\"",
"threadId": "9c537507-9cec-46ed-b877-07bfa6322bed"
}

Follow-up questions

You can maintain conversation context using the threadId from the previous response:

curl -X POST 'https://cloud.getwren.ai/api/v1/generate_sql' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"projectId": YOUR_PROJECT_ID,
"question": "list top 10 only",
"threadId": "9c537507-9cec-46ed-b877-07bfa6322bed"
}'

Handle questions that cannot be translated to SQL

If a user asks a question that isn't related to your data schema or can't be translated to SQL, you'll receive an error response:

curl -X POST 'https://cloud.getwren.ai/api/v1/generate_sql' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"projectId": YOUR_PROJECT_ID,
"question": "What can you do?"
}'

Response:

{
"id": "75c13d09-6f86-4e79-a00e-a4f85f73f2d7",
"code": "NON_SQL_QUERY",
"error": "User asks about Wren AI's features and capabilities, unrelated to database schema.",
"explanationQueryId": "71b016c5-42bb-4897-82d6-46f9b0bf7d94"
}

You have two options to handle this:

  1. Use the error message to generate your own response to users
  2. Stream Wren AI's explanation to users using the stream_explanation endpoint. Check out the API Reference for more details.

Next steps

For complete API documentation, visit our API Reference.