@diagrams-so/sdk is a fully typed client that covers every /api/v2 operation with one method per endpoint. It has zero dependencies (it uses the platform fetch), works in Node 18+, browsers, and edge runtimes, and includes built-in retries, idempotency keys, streaming, and a re-layout helper.

Install

Connect

Run this once per machine. You enter your email, we send a one-time code, and a browser opens where you sign in and enter it; press Approve and the credential is stored for you at ~/.diagrams-so/credentials.json, shared with the MCP server and the Python SDK:

CI and servers

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

Quickstart

Use the SDK server-side. Never ship an API key in browser or client-side code.

Authentication and plans

Pass your key from Settings → API Keys. Every method works on both plans, with no usage limit beyond the rate limit.
dgz_test_ keys run in test mode, with a lower rate limit. They are not a sandbox: they run real generations on your account.

Create and change diagrams

Streaming generation

generateStream is an async generator that yields { event, data }. The diagram arrives only in the terminal complete event. On Free its xml is null (see the Free plan).

Warnings, re-layout, versions, export

Usage and account

Errors

Every non-2xx response throws DiagramsAPIError with .code, .status, and .requestId.

Idempotency

Pass idempotencyKey on create calls (generate, generateStream, edit, fix) so a retry replays the stored result for 24 hours instead of running twice.

Pagination

list, searchGallery, and versions return Page<T> = { items, next_cursor, has_more }.

Configuration

Full method list

generate, generateStream, list, get, update, delete, edit, fix, warnings, startRelayout, relayoutStatus, relayoutAndWait, export, versions, getVersion, revert, import, searchGallery, fork, enhancePrompt, clarifyPrompt, usage, usageHistory, me, meta. Each maps one-to-one to an endpoint in the API reference.

The Free plan

Nothing runs out on either plan. On Free, the API keeps the draw.io XML on the server: diagram replies have xml: null, xml_withheld: true, and an export_url for a watermarked SVG. Asking for a "drawio" export throws DiagramsAPIError with code UPGRADE_REQUIRED (status 403). Older published types declare xml as a string, so widen the type when you check:
See Plans & pricing.