Text2Chart API
Converts natural language queries to SQL, executes the query, and automatically generates interactive charts from the data.
POST/agent/api/v2/generate-chart
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | Yes | Natural language query |
stream | boolean | No | Whether to return streaming response Default: true |
AI Chart Selection
The system automatically analyzes your data and query to select the most suitable chart type:
- Line Chart - Time series and trend data
- Bar Chart - Categorical comparisons
- Pie Chart - Proportional data
- Scatter Plot - Correlation analysis
- Area Chart - Cumulative data
Response Format
Standard Response (stream: false)
{
"sql": "SELECT date, price FROM token_prices WHERE date >= CURRENT_DATE - INTERVAL '30 days'",
"data": [
{"date": "2024-01-01", "price": 100.5},
{"date": "2024-01-02", "price": 102.3}
],
"chart": {
"chartType": "line",
"htmlCode": "<div>...</div>",
"previewUrl": "https://...",
"dataInsights": ["Price shows upward trend", "Peak reached on January 15th"],
"generationTime": 1500
},
"timestamp": "2024-01-20T10:30:00Z"
}
Streaming Response Event Types
| Event Type | Description |
|---|---|
chart_start | Chart generation started |
node_execution | Workflow node executing |
chart_sql_complete | SQL query execution completed |
chart_generation_complete | Chart generation completed |
chart_complete | Entire process completed |
chart_error | Chart generation error |
llm_start / token / llm_end | LLM generation process |
Responses
- 200
- 400
- 401
- 429
- 500
Chart generation successful
{
"sql": "SELECT date, price FROM token_prices WHERE date >= CURRENT_DATE - INTERVAL '30 days'",
"data": [
{
"date": "2024-01-01",
"price": 100.5
},
{
"date": "2024-01-02",
"price": 102.3
},
{
"date": "2024-01-03",
"price": 98.7
}
],
"chart": {
"chartType": "line",
"htmlCode": "<div class=\"chart-container\"><canvas id=\"chart\"></canvas></div>",
"previewUrl": "https://charts.hubble-rpc.xyz/preview/abc123",
"dataInsights": [
"Price shows upward trend",
"Peak reached on January 15th",
"Average daily volume: $2.5M"
],
"generationTime": 1500
},
"timestamp": "2024-01-20T10:30:00Z"
}Bad Request - Invalid parameters
{
"error": "Query parameter cannot be empty",
"timestamp": "2024-01-20T10:30:00Z"
}Unauthorized - Invalid API key
{
"error": "Invalid or missing API key",
"timestamp": "2024-01-20T10:30:00Z"
}Too Many Requests - Rate limit exceeded
{
"error": "Rate limit exceeded. Please try again in 60 seconds",
"retryAfter": 60,
"timestamp": "2024-01-20T10:30:00Z"
}Internal Server Error
{
"error": "Chart generation failed, please try again later",
"timestamp": "2024-01-20T10:30:00Z"
}