### Postgres Connection Example Source: https://wrenai.readme.io/reference/post_projects Example JSON configuration for connecting to PostgreSQL. ```json { "type": "POSTGRES", "connectionInfo": { "host": "db.internal", "port": 5432, "user": "app", "password": "s3cret", "database": "warehouse", "ssl": true } } ``` -------------------------------- ### MySQL Connection Example Source: https://wrenai.readme.io/reference/post_projects Example JSON configuration for connecting to MySQL. ```json { "type": "MYSQL", "connectionInfo": { "host": "db.internal", "port": 3306, "user": "app", "password": "s3cret", "database": "warehouse", "ssl": true } } ``` -------------------------------- ### Oracle Connection Example Source: https://wrenai.readme.io/reference/post_projects Example JSON configuration for connecting to Oracle. ```json { "type": "ORACLE", "connectionInfo": { "user": "app", "password": "s3cret", "host": "oracle.internal", "port": 1521, "database": "ORCLCDB", "dsn": "oracle.internal:1521/ORCLCDB" } } ``` -------------------------------- ### Trino Connection Example Source: https://wrenai.readme.io/reference/post_projects Example JSON configuration for connecting to Trino. ```json { "type": "TRINO", "connectionInfo": { "host": "trino.internal", "port": 443, "schemas": "hive.default,iceberg.analytics", "username": "app", "password": "s3cret", "ssl": true } } ``` -------------------------------- ### MSSQL Connection Example Source: https://wrenai.readme.io/reference/post_projects Example JSON configuration for connecting to MSSQL. ```json { "type": "MSSQL", "connectionInfo": { "host": "mssql.internal", "port": 1433, "user": "app", "password": "s3cret", "database": "warehouse", "trustServerCertificate": true } } ``` -------------------------------- ### BigQuery Connection Example Source: https://wrenai.readme.io/reference/post_projects Example JSON configuration for connecting to BigQuery. ```json { "type": "BIG_QUERY", "connectionInfo": { "projectId": "gcp-project", "datasetId": "analytics", "credentials": "{ \"type\": \"service_account\", \"client_email\": \"svc@...\", \"private_key\": \"-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n\" }", "sourceProjectId": "gcp-project-src", "sourceDatasetId": "raw" } } ``` -------------------------------- ### Athena Connection Example Source: https://wrenai.readme.io/reference/post_projects Example JSON configuration for connecting to Athena. ```json { "type": "ATHENA", "connectionInfo": { "database": "analytics", "schema": "public", "s3StagingDir": "s3://bucket/athena-results/", "awsRegion": "us-east-1", "awsAccessKey": "AKIA...", "awsSecretKey": "s3cret" } } ``` -------------------------------- ### Message Start Event Example Source: https://wrenai.readme.io/reference/post_stream-generate-sql-1 An example payload for the 'message_start' event, indicating the beginning of a streaming response. ```json { "type": "message_start", "timestamp": 1751014954139 } ``` -------------------------------- ### Content Block Start Event Source: https://wrenai.readme.io/reference/post_stream-ask This JSON example shows the structure of a `content_block_start` event, signaling the beginning of a content block like summary generation. ```json { "type": "content_block_start", "content_block": { "type": "text", "name": "summary_generation" } } ``` -------------------------------- ### SQL Generation State Transitions Source: https://wrenai.readme.io/reference/post_stream-generate-sql-1 This example demonstrates the sequence of state transitions during the SQL generation process, from start to success, including intermediate steps like understanding, searching, planning, and generating. ```javascript data: { "type": "state", "data": { "state": "sql_generation_start", "question": "list 5 customers", "threadId": "0625991d-1bba-407d-8ad4-dd0210172484", "language": "English" }, "timestamp": 1751014954142 } data: { "type": "state", "data": { "state": "sql_generation_understanding", "pollCount": 1, "rephrasedQuestion": null, "intentReasoning": null, "sqlGenerationReasoning": null, "retrievedTables": null, "invalidSql": null, "traceId": "f218b1f7-4623-4a56-8b66-18d544797b20" }, "timestamp": 1751014954165 } data: { "type": "state", "data": { "state": "sql_generation_searching", "pollCount": 4, "rephrasedQuestion": "List 5 customers from the olist_customers_dataset table.", "intentReasoning": "User wants to retrieve specific customer data, likely using SQL query.", "sqlGenerationReasoning": null, "retrievedTables": null, "invalidSql": null, "traceId": "f218b1f7-4623-4a56-8b66-18d544797b20" }, "timestamp": 1751014957183 } data: { "type": "state", "data": { "state": "sql_generation_planning", "pollCount": 6, "rephrasedQuestion": "List 5 customers from the olist_customers_dataset table.", "intentReasoning": "User wants to retrieve specific customer data, likely using SQL query.", "sqlGenerationReasoning": null, "retrievedTables": ["olist_customers_dataset"], "invalidSql": null, "traceId": "f218b1f7-4623-4a56-8b66-18d544797b20" }, "timestamp": 1751014959232 } data: { "type": "state", "data": { "state": "sql_generation_generating", "pollCount": 9, "rephrasedQuestion": "List 5 customers from the olist_customers_dataset table.", "intentReasoning": "User wants to retrieve specific customer data, likely using SQL query.", "sqlGenerationReasoning": "1. **Identify the table involved**: The question asks for customer data, so the relevant table is `olist_customers_dataset`.\n\n2. **Determine the number of records needed**: The user requests 5 customers, so we need to select 5 entries from the table.", "retrievedTables": ["olist_customers_dataset"], "invalidSql": null, "traceId": "f218b1f7-4623-4a56-8b66-18d544797b20" }, "timestamp": 1751014962254 } data: { "type": "state", "data": { "state": "sql_generation_success", "sql": "SELECT \"o\".\"customer_id\", \"o\".\"customer_zip_code_prefix\", \"o\".\"customer_city\", \"o\".\"customer_state\" FROM \"olist_customers_dataset\" AS \"o\" LIMIT 5" }, "timestamp": 1751014963263 } data: { "type": "state", "data": { "state": "sql_execution_start", "sql": "SELECT \"o\".\"customer_id\", \"o\".\"customer_zip_code_prefix\", \"o\".\"customer_city\", \"o\".\"customer_state\" FROM \"olist_customers_dataset\" AS \"o\" LIMIT 5" }, "timestamp": 1751014963263 } data: { "type": "state", "data": { "state": "sql_execution_end" }, "timestamp": 1751014963339 } ``` -------------------------------- ### Basic parameters response example Source: https://wrenai.readme.io/reference/post_projects Example of a successful response after creating a project with basic parameters. ```json { "project": { "id": 123, "type": "POSTGRES", "displayName": "Sales Analytics", "createdAt": "2025-09-11T12:34:56Z", "updatedAt": "2025-09-11T12:34:56Z", "connectionInfo": null, "language": "EN", "timezone": "Europe/London" }, "status": "succeeded" } ``` -------------------------------- ### ClickHouse Connection Example Source: https://wrenai.readme.io/reference/post_projects Example JSON configuration for connecting to ClickHouse. ```json { "type": "CLICK_HOUSE", "connectionInfo": { "host": "clickhouse.internal", "port": 8443, "user": "app", "password": "s3cret", "database": "analytics", "ssl": true } } ``` -------------------------------- ### Basic parameters request example Source: https://wrenai.readme.io/reference/post_projects Example of a request to create a project with basic parameters. ```json { "orgId": 1, "displayName": "Sales Analytics", "language": "EN", "timezone": "Europe/London" } ``` -------------------------------- ### Initial Question Request Source: https://wrenai.readme.io/reference/post_stream-interactive-ask Example JSON request for an initial question to start a new conversation thread. ```json { "projectId": 123, "question": "What are the top 5 states with the most customers?" } ``` -------------------------------- ### OpenAPI definition Source: https://wrenai.readme.io/reference/get_knowledge-instructions OpenAPI definition for the Get all instructions endpoint. ```json { "openapi": "3.0.0", "info": { "title": "WrenAI API", "description": "Restful API for interacting with Wren AI", "version": "1.0.0" }, "servers": [ { "url": "/api/v1", "description": "WrenAI API v1" } ], "paths": { "/knowledge/instructions": { "get": { "summary": "Get all instructions", "description": "Retrieves all instructions for the current project", "responses": { "200": { "description": "Successfully retrieved instructions", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Instruction" } }, "example": [ { "id": 1, "instruction": "Always include customer_id in the SELECT clause when querying customer data", "isGlobal": true, "createdAt": "2024-01-15T10:30:00Z", "updatedAt": "2024-01-15T10:30:00Z" }, { "id": 2, "instruction": "When analyzing sales data, consider seasonal trends and regional differences", "isGlobal": false, "questions": [ "What are our sales trends?", "How do sales vary by region?" ], "createdAt": "2024-01-16T14:20:00Z", "updatedAt": "2024-01-16T14:20:00Z" } ] } } } } } } }, "components": { "schemas": { "Instruction": { "type": "object", "properties": { "id": { "type": "integer", "description": "Unique identifier for the instruction" }, "instruction": { "type": "string", "description": "The instruction text" }, "isGlobal": { "type": "boolean", "description": "Whether this instruction is global or question-matching" }, "createdAt": { "type": "string", "format": "date-time", "description": "Creation timestamp" }, "updatedAt": { "type": "string", "format": "date-time", "description": "Last update timestamp" } } } } } } ``` -------------------------------- ### Redshift Connection Example (Password Auth) Source: https://wrenai.readme.io/reference/post_projects Example JSON configuration for connecting to Redshift using password authentication. ```json { "type": "REDSHIFT", "connectionInfo": { "host": "redshift-cluster.internal", "port": 5439, "user": "app", "password": "s3cret", "database": "dev", "redshiftType": "PASSWORD" } } ``` -------------------------------- ### Snowflake Connection Example (Password Auth) Source: https://wrenai.readme.io/reference/post_projects Example JSON configuration for connecting to Snowflake using password authentication. ```json { "type": "SNOWFLAKE", "connectionInfo": { "user": "APP", "account": "ACCT", "database": "ANALYTICS", "schema": "PUBLIC", "password": "s3cret", "warehouse": "COMPUTE_WH" } } ``` -------------------------------- ### Create SQL Pair Example Source: https://wrenai.readme.io/reference/post_projects-projectid-knowledge-sql-pairs Example of creating a new SQL pair with question and SQL query. ```json { "openapi": "3.0.0", "info": { "title": "WrenAI SaaS API", "description": "Restful API for interacting with Wren AI SaaS Platform", "version": "1.0.0" }, "servers": [ { "url": "https://cloud.getwren.ai/api/v1", "description": "WrenAI SaaS API v1" } ], "components": { "securitySchemes": { "BearerAuth": { "type": "http", "scheme": "bearer", "bearerFormat": "JWT" } }, "schemas": { "ErrorResponse": { "type": "object", "properties": { "id": { "type": "string", "description": "Unique identifier for the error response" }, "error": { "type": "string", "description": "Error message" }, "code": { "type": "string", "description": "Error code" } } }, "SqlPair": { "type": "object", "properties": { "id": { "type": "integer", "description": "Unique identifier for the SQL pair" }, "question": { "type": "string", "description": "The question text" }, "sql": { "type": "string", "description": "The SQL query" }, "createdAt": { "type": "string", "format": "date-time", "description": "Creation timestamp" }, "updatedAt": { "type": "string", "format": "date-time", "description": "Last update timestamp" } } }, "SqlPairCreateInput": { "type": "object", "required": [ "question", "sql" ], "properties": { "question": { "type": "string", "description": "The question text" }, "sql": { "type": "string", "description": "The SQL query" } } } } }, "security": [ { "BearerAuth": [] } ], "paths": { "/projects/{projectId}/knowledge/sql_pairs": { "post": { "summary": "Create a new SQL pair", "description": "Creates a new SQL pair for the specified project", "parameters": [ { "name": "projectId", "in": "path", "description": "The project ID to scope the operation to", "required": true, "schema": { "type": "string" } } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SqlPairCreateInput" } } } }, "responses": { "201": { "description": "Successfully created SQL pair", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SqlPair" }, "example": { "id": 3, "question": "What are the top 10 products by sales volume?", "sql": "SELECT p.product_name, COUNT(*) as sales_count FROM order_items oi JOIN products p ON oi.product_id = p.product_id GROUP BY p.product_name ORDER BY sales_count DESC LIMIT 10", "createdAt": "2024-01-17T16:45:00Z", "updatedAt": "2024-01-17T16:45:00Z" } } } }, "400": { "description": "Bad request", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }, "401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }, "403": { "description": "Forbidden - Project access denied", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }, "404": { "description": "Project not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } } } } } } } ``` -------------------------------- ### Create with Metadata (MDL) request example (minimal) Source: https://wrenai.readme.io/reference/post_projects Example of a request to create a project with minimal MDL (schema) import. ```json { "orgId": 1, "displayName": "Retail BI", "language": "EN", "timezone": "Europe/London", "mdl": { "models": [ { "name": "customers", "columns": [ { "name": "customer_id", "type": "VARCHAR", "notNull": true }, { "name": "customer_city", "type": "VARCHAR" } ], "primaryKey": "customer_id", "tableReference": { "catalog": "memory", "schema": "main", "table": "customers" }, "properties": { "displayName": "Customers" } } ], "relationships": [], "views": [] } } ``` -------------------------------- ### Redshift Connection Example (IAM Auth) Source: https://wrenai.readme.io/reference/post_projects Example JSON configuration for connecting to Redshift using IAM authentication. ```json { "type": "REDSHIFT", "connectionInfo": { "clusterIdentifier": "rs-cluster", "user": "app", "database": "dev", "awsRegion": "us-east-1", "awsAccessKey": "AKIA...", "awsSecretKey": "s3cret", "redshiftType": "IAM" } } ``` -------------------------------- ### cURL Request Examples Source: https://wrenai.readme.io/reference/put_projects-projectid-knowledge-instructions-id Examples of how to make a PUT request to update an instruction using cURL. ```shell curl --request PUT \ --url https://cloud.getwren.ai/api/v1/projects/projectId/knowledge/instructions/id \ --header 'accept: application/json' \ --header 'content-type: application/json' ``` -------------------------------- ### OpenAPI definition for Get all instructions Source: https://wrenai.readme.io/reference/get_projects-projectid-knowledge-instructions This is the OpenAPI definition for the endpoint that retrieves all instructions for a specified project. ```json { "openapi": "3.0.0", "info": { "title": "WrenAI SaaS API", "description": "Restful API for interacting with Wren AI SaaS Platform", "version": "1.0.0" }, "servers": [ { "url": "https://cloud.getwren.ai/api/v1", "description": "WrenAI SaaS API v1" } ], "components": { "securitySchemes": { "BearerAuth": { "type": "http", "scheme": "bearer", "bearerFormat": "JWT" } }, "schemas": { "ErrorResponse": { "type": "object", "properties": { "id": { "type": "string", "description": "Unique identifier for the error response" }, "error": { "type": "string", "description": "Error message" }, "code": { "type": "string", "description": "Error code" } } }, "Instruction": { "type": "object", "properties": { "id": { "type": "integer", "description": "Unique identifier for the instruction" }, "instruction": { "type": "string", "description": "The instruction text" }, "isGlobal": { "type": "boolean", "description": "Whether this instruction is global or question-matching" }, "questions": { "type": "array", "description": "List of questions that this instruction matches if it is question-matching instruction", "items": { "type": "string" } }, "createdAt": { "type": "string", "format": "date-time", "description": "Creation timestamp" }, "updatedAt": { "type": "string", "format": "date-time", "description": "Last update timestamp" } } } } }, "security": [ { "BearerAuth": [] } ], "paths": { "/projects/{projectId}/knowledge/instructions": { "get": { "summary": "Get all instructions", "description": "Retrieves all instructions for the specified project", "parameters": [ { "name": "projectId", "in": "path", "description": "The project ID to scope the operation to", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Successfully retrieved instructions", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Instruction" } }, "example": [ { "id": 1, "instruction": "Always include customer_id in the SELECT clause when querying customer data", "isGlobal": true, "createdAt": "2024-01-15T10:30:00Z", "updatedAt": "2024-01-15T10:30:00Z" }, { "id": 2, "instruction": "When analyzing sales data, consider seasonal trends and regional differences", "isGlobal": false, "questions": [ "What are our sales trends?", "How do sales vary by region?" ], "createdAt": "2024-01-16T14:20:00Z", "updatedAt": "2024-01-16T14:20:00Z" } ] } } }, "401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }, "403": { "description": "Forbidden - Project access denied", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }, "404": { "description": "Project not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } } } } } } } ``` -------------------------------- ### API Key Authentication Source: https://wrenai.readme.io/reference/cloud-getting-started Example of how to use the API key in the Authorization header as a Bearer token. ```bash Authorization: Bearer YOUR_API_KEY ``` -------------------------------- ### Create with MDL, Instructions, and SQL Pairs response example Source: https://wrenai.readme.io/reference/post_projects Example of a successful response after creating a project with MDL, instructions, and SQL pairs. ```json { "project": { "...": "..." }, "status": "succeeded" } ``` -------------------------------- ### Create with MDL, Instructions, and SQL Pairs request example Source: https://wrenai.readme.io/reference/post_projects Example of a request to create a project with MDL, seed instructions, and SQL pairs. ```json { "orgId": 1, "displayName": "Growth Insights", "language": "EN", "timezone": "Europe/London", "mdl": { "models": [ { "name": "orders", "columns": [{ "name": "order_id", "type": "VARCHAR", "notNull": true }], "primaryKey": "order_id" } ], "relationships": [], "views": [] }, "instructions": [ { "instruction": "Always include order_id in order analysis", "isGlobal": true }, { "instruction": "Aggregate by month when asked 'by month'", "questions": ["by month", "monthly"] } ], "sqlPairs": [ { "question": "Top 10 customers by orders", "sql": "SELECT customer_id, COUNT(*) c FROM orders GROUP BY customer_id ORDER BY c DESC LIMIT 10" } ] } ``` -------------------------------- ### OpenAPI definition for Get all SQL pairs Source: https://wrenai.readme.io/reference/get_projects-projectid-knowledge-sql-pairs This OpenAPI definition describes the GET endpoint for retrieving all SQL pairs for a specified project. It includes request parameters, response schemas, and example responses. ```json { "openapi": "3.0.0", "info": { "title": "WrenAI SaaS API", "description": "Restful API for interacting with Wren AI SaaS Platform", "version": "1.0.0" }, "servers": [ { "url": "https://cloud.getwren.ai/api/v1", "description": "WrenAI SaaS API v1" } ], "components": { "securitySchemes": { "BearerAuth": { "type": "http", "scheme": "bearer", "bearerFormat": "JWT" } }, "schemas": { "ErrorResponse": { "type": "object", "properties": { "id": { "type": "string", "description": "Unique identifier for the error response" }, "error": { "type": "string", "description": "Error message" }, "code": { "type": "string", "description": "Error code" } } }, "SqlPair": { "type": "object", "properties": { "id": { "type": "integer", "description": "Unique identifier for the SQL pair" }, "question": { "type": "string", "description": "The question text" }, "sql": { "type": "string", "description": "The SQL query" }, "createdAt": { "type": "string", "format": "date-time", "description": "Creation timestamp" }, "updatedAt": { "type": "string", "format": "date-time", "description": "Last update timestamp" } } } } }, "security": [ { "BearerAuth": [] } ], "paths": { "/projects/{projectId}/knowledge/sql_pairs": { "get": { "summary": "Get all SQL pairs", "description": "Retrieves all SQL pairs for the specified project", "parameters": [ { "name": "projectId", "in": "path", "description": "The project ID to scope the operation to", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Successfully retrieved SQL pairs", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/SqlPair" } }, "example": [ { "id": 1, "question": "How many customers do we have in each state?", "sql": "SELECT customer_state, COUNT(*) as customer_count FROM customers GROUP BY customer_state ORDER BY customer_count DESC", "createdAt": "2024-01-15T11:00:00Z", "updatedAt": "2024-01-15T11:00:00Z" }, { "id": 2, "question": "What is the total revenue by month?", "sql": "SELECT DATE_TRUNC('month', order_date) as month, SUM(payment_value) as total_revenue FROM orders o JOIN payments p ON o.order_id = p.order_id GROUP BY month ORDER BY month", "createdAt": "2024-01-16T15:30:00Z", "updatedAt": "2024-01-16T15:30:00Z" } ] } } }, "401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }, "403": { "description": "Forbidden - Project access denied", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }, "404": { "description": "Project not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } } } } } } } ``` -------------------------------- ### message_start Event Example Source: https://wrenai.readme.io/reference/post_stream-interactive-ask Indicates the start of a new conversation response. ```json { "type": "message_start", "message": { "query_id": "6771808b-790a-48f3-b60c-5c7e62a694f4", "trace_id": "a87102f7-6e27-4aed-a32d-52b444ceadac" } } ``` -------------------------------- ### Example response from the post stream generate SQL endpoint Source: https://wrenai.readme.io/reference/post_stream-generate-sql-1 This example shows the stream of events that are returned from the post stream generate SQL endpoint. It includes the message start, state updates, and the final SQL query. ```json data: {"type":"message_start","timestamp":1751015017304} data: {"type":"state","data":{"state":"sql_generation_start","question":"list 5 customers","threadId":"a0820d1b-5926-4ef0-bcc4-b4237c0cff50","language":"English"},"timestamp":1751015017306} data: {"type":"state","data":{"state":"sql_generation_understanding","pollCount":1,"rephrasedQuestion":null,"intentReasoning":null,"sqlGenerationReasoning":null,"retrievedTables":null,"invalidSql":null,"traceId":"5bcb1451-0b2e-46ce-9ff4-3bcd6f3007e1"},"timestamp":1751015017315} data: {"type":"state","data":{"state":"sql_generation_searching","pollCount":4,"rephrasedQuestion":"List 5 customers from the olist_customers_dataset table.","intentReasoning":"User wants a specific SQL query to retrieve customer data.","sqlGenerationReasoning":null,"retrievedTables":null,"invalidSql":null,"traceId":"5bcb1451-0b2e-46ce-9ff4-3bcd6f3007e1"},"timestamp":1751015020340} data: {"type":"state","data":{"state":"sql_generation_planning","pollCount":6,"rephrasedQuestion":"List 5 customers from the olist_customers_dataset table.","intentReasoning":"User wants a specific SQL query to retrieve customer data.","sqlGenerationReasoning":null,"retrievedTables":["olist_customers_dataset"],"invalidSql":null,"traceId":"5bcb1451-0b2e-46ce-9ff4-3bcd6f3007e1"},"timestamp":1751015022366} data: {"type":"state","data":{"state":"sql_generation_generating","pollCount":7,"rephrasedQuestion":"List 5 customers from the olist_customers_dataset table.","intentReasoning":"User wants a specific SQL query to retrieve customer data.","sqlGenerationReasoning":"1. **Identify the table to query**: The table to retrieve customer data from is `olist_customers_dataset`. 2. **Determine the number of records needed**: The user requests 5 customers, so we need to limit the result to 5 entries.","retrievedTables":["olist_customers_dataset"],"invalidSql":null,"traceId":"5bcb1451-0b2e-46ce-9ff4-3bcd6f3007e1"},"timestamp":1751015025913} data: {"type":"state","data":{"state":"sql_generation_success","sql":"SELECT \"customer_id\", \"customer_unique_id\", \"customer_zip_code_prefix\", \"customer_city\", \"customer_state\" FROM \"olist_customers_dataset\" LIMIT 5"},"timestamp":1751015027926} data: {"type":"message_stop","data":{"threadId":"a0820d1b-5926-4ef0-bcc4-b4237c0cff50","duration":10624},"timestamp":1751015027928} ``` -------------------------------- ### Example Request Source: https://wrenai.readme.io/reference/cloud_post_generate-vega-chart An example of a request payload to the /generate_vega_chart endpoint. ```json { "projectId": 1, "question": "Show me total payments by customer state", "sql": "SELECT customer_state, SUM(payment_value) AS total_payment_value FROM orders GROUP BY customer_state ORDER BY total_payment_value DESC", "customInstruction": "Display as a pie chart", "threadId": "75ab23c8-9124-4560-a125-fbe7e321dcba" } ``` -------------------------------- ### Snowflake Connection Example (Private Key Auth) Source: https://wrenai.readme.io/reference/post_projects Example JSON configuration for connecting to Snowflake using private key authentication. ```json { "type": "SNOWFLAKE", "connectionInfo": { "user": "APP", "account": "ACCT", "database": "ANALYTICS", "schema": "PUBLIC", "privateKey": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n", "warehouse": "COMPUTE_WH" } } ``` -------------------------------- ### Create with Connection Test request example (Postgres) Source: https://wrenai.readme.io/reference/post_projects Example of a request to create a project with connection testing enabled for a Postgres database. ```json { "orgId": 1, "displayName": "Ops DWH", "language": "EN", "timezone": "America/Los_Angeles", "type": "POSTGRES", "connectionInfo": { "host": "db.internal", "port": 5432, "user": "app", "password": "s3cret", "database": "warehouse", "ssl": true }, "testConnection": true } ``` -------------------------------- ### Error Response Example Source: https://wrenai.readme.io/reference/cloud_post_generate-vega-chart An example of an error response when chart generation fails. ```javascript { "id": "c4f82c31-a40d-4b8e-9e5f-c1d8a742db55", "code": "INVALID_SQL", "error": "Unable to generate chart: SQL query does not return valid data for visualization" } ``` -------------------------------- ### Create with Metadata (MDL) response example (partial success) Source: https://wrenai.readme.io/reference/post_projects Example of a response indicating partial success when creating a project with MDL, showing error details for failed steps. ```json { "project": { "...": "..." }, "status": "partial", "errors": [ { "resource": "views", "message": "View \"sales_by_city\" failed: question is required" } ] } ``` -------------------------------- ### Create with Connection Test response example (redacted connectionInfo) Source: https://wrenai.readme.io/reference/post_projects Example of a response after creating a project with connection testing, showing redacted sensitive connection information. ```json { "project": { "id": 124, "type": "POSTGRES", "displayName": "Ops DWH", "createdAt": "2025-09-11T12:40:00Z", "updatedAt": "2025-09-11T12:40:00Z", "connectionInfo": { "host": "db.internal", "port": 5432, "user": "app", "password": "******", "database": "warehouse", "ssl": true }, "language": "EN", "timezone": "America/Los_Angeles" }, "status": "succeeded" } ``` -------------------------------- ### Non-SQL Query Handling Examples Source: https://wrenai.readme.io/reference/cloud_post_generate-sql Examples of error responses when a question cannot be converted to SQL. ```javascript // Example 1: Asking question "hello" { "id": "e593369b-e222-4435-b874-dc10edb12a96", "code": "NON_SQL_QUERY", "error": "Vague greeting unrelated to schema, SQL, or user guide; no specific intent identified.", "explanationQueryId": "475afc1f-7950-4bc7-a248-a7da394d137a" } // Example 2: Asking question "what could you do" { "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" } ``` -------------------------------- ### SSE Stream Example Source: https://wrenai.readme.io/reference/post_stream-interactive-ask Example of the Server-Sent Events (SSE) stream response for an initial question. ```javascript // Stream begins - events forwarded from AI Service event: message_start data: {"type":"message_start","message":{"query_id":"6771808b-790a-48f3-b60c-5c7e62a694f4","trace_id":"a87102f7-6e27-4aed-a32d-52b444ceadac"}} event: content_block_start data: {"type":"content_block_start","index":0,"message":{"type":"text","content_block_label":"GREETINGS","trace_id":"a87102f7-6e27-4aed-a32d-52b444ceadac","metadata":{"visible_in_ui":true,"ui_components":["MARKDOWN","ASSISTANT"],"show_elapsed_time":false,"elapsed_time":0.0}}} event: content_block_delta data: {"type":"content_block_delta","index":0,"message":{"type":"text_delta","content_block_label":"GREETINGS","content":"You're all set. Let me process that for you.","trace_id":"a87102f7-6e27-4aed-a32d-52b444ceadac","metadata":{"visible_in_ui":true,"ui_components":["MARKDOWN","ASSISTANT"],"show_elapsed_time":false,"elapsed_time":0.01}}} event: content_block_stop data: {"type":"content_block_stop","index":0,"message":{"type":"text","trace_id":"a87102f7-6e27-4aed-a32d-52b444ceadac","content_block_label":"GREETINGS","metadata":{"show_elapsed_time":false,"elapsed_time":0.01}}} ... // Stream ends data: {"done": true} ```