The ChartQuery Diagram API renders diagram-as-code (Mermaid, Graphviz, PlantUML, D2 and 24 other languages) to PNG, SVG, JPEG or PDF — or generates a diagram from a plain-English prompt.
- Diagram Render API — Render a diagram via GET.
- AI Diagram API — Describe a diagram in plain English via GET and get a rendered image back.
Use it for docs, READMEs, wikis, architecture diagrams and AI assistants.
| Endpoint | Request | Credits |
|---|---|---|
| Diagram Render API | GET /v1/diagram |
5 |
| AI Diagram API | GET /v1/diagram/ai |
10 |
- How it works
- Diagram Render API
- AI Diagram 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 diagram via GET. Use type (mermaid, d2, …), query (source code), and format=png for ChatGPT. POST uses diagram_type and diagram_source instead.
GET https://api.chartquery.com/v1/diagram · 5 credits per request · API reference
| Parameter | In | Type | Required | Description |
|---|---|---|---|---|
type |
query | string (mermaid, graphviz, plantuml, d2, svgbob, nomnoml) |
✅ | Diagram language. |
query |
query | string | ✅ | Diagram source code (URL-encoded). |
format |
query | string (svg, png, jpeg, pdf) |
— | Use png so ChatGPT can display the image. svg is for download or infinite scale. |
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/diagram",
headers=HEADERS,
params={
"type": "mermaid",
"query": "graph TD\n A[Start] --> B{OK?}\n B -->|yes| C[End]\n B -->|no| D[Error]",
"format": "png",
},
timeout=120,
)
response.raise_for_status()
with open("diagram.png", "wb") as f:
f.write(response.content)
print("Saved diagram.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({
"type": "mermaid",
"query": "graph TD\n A[Start] --> B{OK?}\n B -->|yes| C[End]\n B -->|no| D[Error]",
"format": "png",
});
const response = await fetch(`https://api.chartquery.com/v1/diagram?${params}`, { headers });
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
await writeFile("diagram.png", Buffer.from(await response.arrayBuffer()));
console.log("Saved diagram.png");The response body is the generated file (saved as diagram.png in every example). Error responses are JSON with an explanatory message.
Describe a diagram in plain English via GET and get a rendered image back. Powered by AI.
GET https://api.chartquery.com/v1/diagram/ai · 10 credits per request · API reference
| Parameter | In | Type | Required | Description |
|---|---|---|---|---|
prompt |
query | string | ✅ | Describe your diagram in plain English (max 1000 chars). Be specific: mention the diagram type, key entities, and relationships. |
diagram_type |
query | string (mermaid, d2, plantuml, graphviz) |
— | Preferred diagram language. AI chooses if omitted. Examples: "mermaid", "d2", "plantuml", "graphviz". |
output_format |
query | string (svg, png, jpeg, pdf) |
— | Output format. Default: "svg". |
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. Paid plan: 6-month expiry. |
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/diagram/ai",
headers=HEADERS,
params={
"prompt": "Sequence diagram of a user logging in through an API gateway to an auth service",
"output_format": "png",
},
timeout=120,
)
response.raise_for_status()
with open("ai-diagram.png", "wb") as f:
f.write(response.content)
print("Saved ai-diagram.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": "Sequence diagram of a user logging in through an API gateway to an auth service",
"output_format": "png",
});
const response = await fetch(`https://api.chartquery.com/v1/diagram/ai?${params}`, { headers });
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
await writeFile("ai-diagram.png", Buffer.from(await response.arrayBuffer()));
console.log("Saved ai-diagram.png");The response body is the generated file (saved as ai-diagram.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 | diagram |
diagram-ai |
|---|---|---|
| cURL (Bash) | diagram.sh | diagram_ai.sh |
| PHP | diagram.php | diagram_ai.php |
| C# | Diagram.cs | DiagramAi.cs |
| Go | diagram.go | diagram_ai.go |
| Java | DiagramExample.java | DiagramAiExample.java |
| Ruby | diagram.rb | diagram_ai.rb |
| Node.js | diagram.mjs | diagram_ai.mjs |
- Documentation — Render diagrams for docs and wikis on the fly.
- Architecture — Keep diagrams as code and render them in CI.
- AI assistants — Let agents draw flowcharts and sequence diagrams.
- 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/diagram 5, /v1/diagram/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.
mermaid, graphviz, plantuml, d2, svgbob, nomnoml, blockdiag, seqdiag, actdiag, nwdiag, bpmn, erd, excalidraw, ditaa, vega, vegalite, wavedrom, wireviz, c4plantuml, structurizr, tikz, pikchr, umlet, symbolator, packetdiag, rackdiag, bytefield and dbml.
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.
