The ChartQuery Chart API renders a Chart.js configuration as an image, or generates a chart from a plain-English prompt with AI.
- Chart Render API — Render a Chart.js image via GET.
- AI Chart API — Describe a chart in plain English via GET and get a rendered image back.
Use it for charts in emails, PDF reports, Slack bots, dashboards and AI assistants.
| Endpoint | Request | Credits |
|---|---|---|
| Chart Render API | GET /v1/chart |
5 |
| AI Chart API | GET /v1/chart/ai |
10 |
- How it works
- Chart Render API
- AI Chart API
- Code examples in other languages
- Use cases
- Why ChartQuery?
- FAQ
- Related repositories
- Support
- Create a ChartQuery account and copy your API key from the dashboard.
- Call
https://api.chartquery.comwith the headerx-api-key: YOUR_API_KEY. - Use the result in your app — no infrastructure to run.
export CHARTQUERY_API_KEY="your-api-key"
pip install requests # Python
# TypeScript: Node.js 18+ (native fetch), run with `npx tsx file.ts`Render a Chart.js image via GET. Pass the full chart object as URL-encoded JSON in query. Prefer format png for ChatGPT. POST sends the same object as a JSON body, not query.
GET https://api.chartquery.com/v1/chart · 5 credits per request · API reference
| Parameter | In | Type | Required | Description |
|---|---|---|---|---|
query |
query | string | ✅ | Full chart config as URL-encoded JSON. Pass ?version= or ?v= separately to pin the chart version. |
version |
query | string | — | Chart.js version to use. Alias: ?v=. Only v4.x is supported. Defaults to the installed version (4.5.1). Example: "4", "4.5", "4.5.1". The installed version is always returned in the X-ChartJS-Version response header. |
share |
query | boolean | — | If true, persist the result and return share URLs instead of an image. Leave false to get the image. |
import os
import requests
API_KEY = os.environ["CHARTQUERY_API_KEY"]
HEADERS = {"x-api-key": API_KEY}
response = requests.get(
"https://api.chartquery.com/v1/chart",
headers=HEADERS,
params={
"query": "{\"type\":\"bar\",\"title\":\"Monthly Sales\",\"legend\":\"bottom\",\"width\":1200,\"height\":600,\"device_pixel_ratio\":1,\"data\":{\"labels\":[\"Jan\",\"Feb\",\"Mar\",\"Apr\",\"May\",\"Jun\"],\"datasets\":[{\"label\":\"2025\",\"data\":[42,58,37,65,49,72],\"backgroundColor\":\"rgba(99,102,241,0.85)\"},{\"label\":\"2026\",\"data\":[51,67,44,71,58,85],\"backgroundColor\":\"rgba(249,115,22,0.85)\"}]},\"scales\":{\"y\":{\"beginAtZero\":true}}}",
},
timeout=120,
)
response.raise_for_status()
with open("chart.png", "wb") as f:
f.write(response.content)
print("Saved chart.png", len(response.content), "bytes")import { writeFile } from "node:fs/promises";
const headers = { "x-api-key": process.env.CHARTQUERY_API_KEY!, "Content-Type": "application/json" };
const params = new URLSearchParams({
"query": "{\"type\":\"bar\",\"title\":\"Monthly Sales\",\"legend\":\"bottom\",\"width\":1200,\"height\":600,\"device_pixel_ratio\":1,\"data\":{\"labels\":[\"Jan\",\"Feb\",\"Mar\",\"Apr\",\"May\",\"Jun\"],\"datasets\":[{\"label\":\"2025\",\"data\":[42,58,37,65,49,72],\"backgroundColor\":\"rgba(99,102,241,0.85)\"},{\"label\":\"2026\",\"data\":[51,67,44,71,58,85],\"backgroundColor\":\"rgba(249,115,22,0.85)\"}]},\"scales\":{\"y\":{\"beginAtZero\":true}}}",
});
const response = await fetch(`https://api.chartquery.com/v1/chart?${params}`, { headers });
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
await writeFile("chart.png", Buffer.from(await response.arrayBuffer()));
console.log("Saved chart.png");The response body is the generated file (saved as chart.png in every example). Error responses are JSON with an explanatory message.
Describe a chart in plain English via GET and get a rendered image back. Powered by AI.
GET https://api.chartquery.com/v1/chart/ai · 10 credits per request · API reference
| Parameter | In | Type | Required | Description |
|---|---|---|---|---|
prompt |
query | string | ✅ | Describe your chart in plain English (max 1000 chars). Be specific: mention chart type, data topic, colors, style. |
raw_data |
query | string | — | Raw data for the chart. URL-encoded string, CSV, or JSON. AI will parse and structure it. |
title |
query | string | — | Override the chart title generated by AI. |
subtitle |
query | string | — | Override the chart subtitle. |
legend |
query | string (top, bottom, left, right, chartArea, false) |
— | Legend position or visibility. Use "false" to hide. |
format |
query | string (png, svg) |
— | Output format. Default: "png". |
width |
query | number | — | Image width in pixels (50–4000). Default: 1200. |
height |
query | number | — | Image height in pixels (50–4000). Default: 600. |
background |
query | string | — | Background color as a hex value. Default: #ffffff. |
device_pixel_ratio |
query | number | — | Device pixel ratio for the rendered image. Default: 1. |
share |
query | boolean (false, true) |
— | Set share=true to persist the config and receive JSON instead of an image: { id, render_url, view_url, embed_url, expires_in }. Free plan: 3-day expiry with watermark. Paid plan: 6-month expiry, no branding. |
import os
import requests
API_KEY = os.environ["CHARTQUERY_API_KEY"]
HEADERS = {"x-api-key": API_KEY}
response = requests.get(
"https://api.chartquery.com/v1/chart/ai",
headers=HEADERS,
params={
"prompt": "Bar chart of monthly sales from January to June, indigo bars, clean style",
"format": "png",
},
timeout=120,
)
response.raise_for_status()
with open("ai-chart.png", "wb") as f:
f.write(response.content)
print("Saved ai-chart.png", len(response.content), "bytes")import { writeFile } from "node:fs/promises";
const headers = { "x-api-key": process.env.CHARTQUERY_API_KEY!, "Content-Type": "application/json" };
const params = new URLSearchParams({
"prompt": "Bar chart of monthly sales from January to June, indigo bars, clean style",
"format": "png",
});
const response = await fetch(`https://api.chartquery.com/v1/chart/ai?${params}`, { headers });
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
await writeFile("ai-chart.png", Buffer.from(await response.arrayBuffer()));
console.log("Saved ai-chart.png");The response body is the generated file (saved as ai-chart.png in every example). Error responses are JSON with an explanatory message.
Ready-to-run examples live in examples/; each reads your key from CHARTQUERY_API_KEY.
| Language | chart |
chart-ai |
|---|---|---|
| cURL (Bash) | chart.sh | chart_ai.sh |
| PHP | chart.php | chart_ai.php |
| C# | Chart.cs | ChartAi.cs |
| Go | chart.go | chart_ai.go |
| Java | ChartExample.java | ChartAiExample.java |
| Ruby | chart.rb | chart_ai.rb |
| Node.js | chart.mjs | chart_ai.mjs |
- Email & PDF reports — Embed charts where JavaScript can't run.
- Chatbots & AI agents — Return charts as images from Slack, Discord or ChatGPT tools.
- Automated reporting — Generate weekly KPI charts from your data pipeline.
- Images in one request — the response body is the PNG/SVG/PDF, ready for emails, PDFs, dashboards, Slack or
<img>tags. - Charts, diagrams, QR codes, barcodes, labels — Chart.js configs, 28 diagram languages (Mermaid, Graphviz, PlantUML, D2…), 25+ barcode formats.
- AI generation — describe a chart or diagram in plain English and get the rendered image.
- No rendering infrastructure — no headless browser, fonts or libraries to maintain.
- Copy-paste examples — Python and TypeScript in each README, 7 more languages in
examples/.
Create an account on ChartQuery, copy your API key and send it in the x-api-key header of every request to https://api.chartquery.com.
Credits per call: /v1/chart 5, /v1/chart/ai 10. See ChartQuery pricing.
The response body is the file itself (image or document). Save it directly to disk or stream it to your storage — every example in this repository writes the file locally.
Any language that can make an HTTP request. This README shows Python and TypeScript; the examples/ folder contains cURL, PHP, C#, Go, Java, Ruby and Node.js.
- 💬 Join the Discord to ask questions and share what you build.
- 📚 Read the API reference.
- 🔑 Get your API key.
Built by ChartQuery. Examples are released under the MIT license.
