diagrams-so is a typed Python client that covers every /api/v2 operation with one method per endpoint. It has no hard dependencies (it uses requests if installed, otherwise the standard library), and includes built-in retries, idempotency keys, streaming, and an async re-layout helper.

Install

Connect

Run this once per machine. A browser opens, you press Approve, and the credential is stored for you at ~/.diagrams-so/credentials.json, shared with the MCP server and the TypeScript SDK:
Installing the package also puts a diagrams-so command on your PATH, so you can connect from a terminal without writing any code and without needing Node:

CI and servers

Where no browser exists, set an environment variable. It always takes priority over a stored login:
Or pass the key explicitly. The order of resolution is an explicit api_key, then DIAGRAMS_API_KEY, then a stored login. Use diagrams_so.logout() to remove the stored credential.

Quickstart

Load the key from an environment variable or secret manager. Never hard-code it or ship it in client-side code.

Authentication and billing

Pass your key from Settings → AI Provider in your account. Reads, enhance_prompt, and clarify_prompt are free. generate, edit, fix, relayout, and fork cost credits.
dgz_test_ keys run in test mode. They bill the same credits as a live key (drawing your real balance) but apply lower rate limits, so use them to exercise your integration, not to avoid spend. Check your balance with client.usage().

Create and change diagrams

Streaming generation

generate_stream yields (event, data) tuples. The diagram XML arrives only in the terminal complete event, after the charge.

Warnings and score

Async re-layout

relayout_and_wait starts the job and polls it to completion.
Prefer to poll yourself? Use client.relayout(d["id"]) then client.relayout_status(d["id"], job_id).

Read, versions, and export

Usage and account

Errors

Every non-2xx response raises DiagramsAPIError with code, status, and request_id.

Idempotency

Pass idempotency_key on billable create calls (generate, generate_stream, edit, fix) so a retry replays the stored result for 24 hours instead of charging twice.

Pagination

list, search_gallery, and versions return {items, next_cursor, has_more}.

Configuration

Full method list

generate, generate_stream, list, get, update, delete, edit, fix, warnings, relayout, relayout_status, relayout_and_wait, export, versions, get_version, revert, import_diagram, search_gallery, fork, enhance_prompt, clarify_prompt, usage, usage_history, me, meta. Each maps one-to-one to an endpoint in the API reference.

Running out of credits

A billable call with no credits left raises DiagramsAPIError with code QUOTA_EXCEEDED. The error carries the top-up link, so you can show it to the user: