Beauty Diagram beautifies Mermaid / PlantUML diagrams into
sleek, modern SVG or PNG. It runs as a public API; this skill
delegates to the bd CLI (npm package @beauty-diagram/cli) so you
keep zero state in the agent. (draw.io / SVG import is editor-only —
not exposed through /v1/*.)
diagram source they already have or you can generate.
source string.
("draw me a signup flow", "diagram our deploy pipeline") — use
bd ai generate for this; it returns Mermaid source you then beautify.
SVGs** alongside.
of them rendered (e.g. "render all the .mmd files in docs/diagrams"). Use
bd batch.
diagrams inline** on GitHub / their static site, not just show the source
code block. Use bd extract — three modes available:
/v1/beautify.svg?source=... URLsafter each fence. No API calls during extract, no files written, no quota
consumed. Always watermarked (anonymous endpoint).
--share): mints a /v1/share/.svg URL per unique fence.Watermark-free for Pro/Premium. Requires an API key. Each unique
source consumes 1 share quota the first time; identical fences are
deduplicated; per-owner local cache means re-runs cost zero quota.
--assets-dir ./img): writes local SVG files via /v1/export.Watermark-free for Pro/Premium, consumes export quota.
GitHub strips raw inline , so any of these modes' 
reference is the correct embed strategy.
rewrites layout for presentation; it does not preserve raw Mermaid output).
existing diagram. bd ai generate only does text → diagram; visual
styling is controlled by --theme on bd beautify, not by the AI.
The bd binary from @beauty-diagram/cli:
npx @beauty-diagram/cli help
# or, after install:
bd help
If the user has not installed it, prefer npx over a global install — it
respects their package manager and avoids polluting PATH.
.mmd / .puml file, use it. bd ai generate " — the server returns
Mermaid source, which you can then beautify. Always write the source
to a file so the user can edit it; the first AI draft rarely lands.
prefers not to pay), write Mermaid source yourself (you are good at
this), save it to a file, then beautify.
/v1/*. Ifthe user has those, ask them to convert via the web editor first.
bd beautify --out .svg bd export --out .svg bd share --title "..." --out) rather than lettingthe SVG flood the terminal / chat. AI generation can also pipe directly
into beautify: bd ai generate "..." | bd beautify - --out flow.svg.
failed, surface the error code (e.g. quota_exhausted, not_authenticated,
parse_failed, prompt_injection) — those are actionable for the user.
with the generated SVG — keep them side by side. For AI-generated diagrams,
keep the .mmd file too: it is the editable artifact, the SVG is not.
20 /v1/beautify requests / minute, 1 /v1/export per 24h (trial
budget — enough for an agent to verify the toolchain end-to-end before
registering). /v1/share, /v1/usage, and **bd ai generate always
require auth** — anonymous AI calls are rejected before any model
invocation.
bd auth login once with a key from Required for bd share, bd ai generate, unwatermarked output, and
repeated exports. bd ai generate additionally requires a Pro or
Premium plan and an API key with the ai:write scope.
If the user hits a not_authenticated, plan_not_allowed, or
quota_exhausted error, point them at /account/api-keys (PAT creation)
or pricing — don't silently retry. Anonymous error bodies include a
hints block with absolute signUpUrl / signInUrl / apiDocsUrl,
which is the canonical place to surface to the user.
--theme selects the visual style. Theme tier is enforced on **all bd
commands that hit a /v1/ endpoint with a PAT* — this includes
bd beautify, bd export, bd share, bd embed-url --share,
bd batch, bd extract --share, and sidecar mode of bd extract. If the request includes a
PAT and specifies a theme above that token's plan tier, the server returns
HTTP 403 theme_tier_required.
The only path that bypasses the tier check is the anonymous fallback
(no token, or the GET /v1/beautify.svg inline embed endpoint). Anonymous
callers may request any theme, but always receive watermarked output — there
is no tier-free, watermark-free path.
| Tier | Themes |
|---|---|
| --- | --- |
| Free | classic, modern, slate |
| Pro | + atlas, obsidian, brutalist, atelier |
| Premium | + blueprint, memphis |
When the user's plan is unknown, default to modern (Free, broadly
slide-friendly). Run bd themes to introspect what the current token
can use — locked themes are marked with ✗. Premium signature themes
(blueprint, memphis) are subscriber-only and cannot be unlocked
with credit packs.
Animations are not currently selectable via the CLI — animation choice
is a web-editor concept; CLI export paths ignore animation.
Instead of (or in addition to) CLI flags, you can embed bd: directives at
the very top of the source file. Both the bd CLI and the Obsidian plugin
parse them; the API server ignores them as native comments (graceful
degradation — the source still renders, just without the directive).
Mermaid — use %% comment syntax:
%% bd:theme=classic
%% bd:bg=transparent
flowchart LR
A --> B
PlantUML — use ' comment syntax:
' bd:theme=classic
' bd:bg=transparent
@startuml
A -> B
@enduml
Supported keys:
| Key | Values | Effect |
|---|---|---|
| --- | --- | --- |
theme | classic modern slate atlas obsidian brutalist atelier blueprint memphis | Override render theme. Tier gating still applies. |
bg | transparent | Transparent canvas. Other values are ignored. |
Multiple directives stack, one per line. Blank lines between directives are
tolerated. The first non-directive non-blank line ends the directive block.
Override priority: CLI flag > source directive > server default.
When generating source for the user, prefer directives over CLI flags when:
directive travels with the file.
%% bd:theme=memphis at the top of the .mmd file).
Directives are stripped before the source reaches the renderer — they do not
appear in the SVG output.
# Render a Mermaid file
bd beautify docs/architecture.mmd --theme modern --out docs/architecture.svg
# Same but treat output as a downloadable export (consumes export quota)
bd export docs/architecture.mmd --out docs/architecture.svg
# PNG export. --quality standard works for everyone; high needs pro, max needs premium.
# Higher tiers than the plan cap are silently clamped (X-BD-Scale-Clamped).
bd export docs/architecture.mmd --format png --quality high --out docs/architecture.png
# PlantUML works the same way; .puml / .plantuml / .pu auto-detected,
# otherwise pass --source-format plantuml.
bd export docs/architecture.puml --out docs/architecture.svg
# Create a public share link (returns absolute https://www.beauty-diagram.com/s/... URL)
bd share docs/architecture.mmd --title "Service architecture"
# → prints the URL on stdout
# Get an embeddable <img>-friendly URL for a diagram source.
# Default: anonymous inline URL (always watermarked) + a hint about --share.
bd embed-url docs/architecture.mmd --theme atlas
# One-shot saved share embed (clean output for pro/premium owners).
# Saves the diagram via /v1/share AND prints the embed URL in one step.
bd embed-url docs/architecture.mmd --share
# → prints https://api.beauty-diagram.com/v1/share/<token>.svg
# AI: generate a diagram from a text prompt. Output is Mermaid source —
# always write to a file so the user can iterate. Paid-only.
bd ai generate "user signup with email verification" --out docs/signup.mmd
# Optional shape hint when the prompt is ambiguous about diagram type.
bd ai generate "request lifecycle" --hint sequence --out docs/lifecycle.mmd
# One-shot pipeline: prompt → mermaid → beautify → SVG.
bd ai generate "deploy flow" | bd beautify - --out docs/deploy.svg
# Check remaining AI / export quota before kicking off a batch.
bd usage
# Render every diagram file under a directory in parallel.
# Recurses for .mmd / .puml / .plantuml / .pu; one /v1/export per file.
# Default concurrency=4, default failure mode is continue-on-error.
bd batch ./docs/diagrams --out-dir ./docs/svg --theme modern
# Same idea but for a glob (quote it so the shell doesn't expand first).
bd batch "src/**/*.mmd" --format png --concurrency 8
# Default: inline embed URLs (no files written, anonymous-watermarked, 5 KB/block cap).
# No API calls during extract — source encoded in the URL; browser fetches on demand.
bd extract README.md
# Share mode: mint /v1/share/<token>.svg per fence. Watermark-free for Pro/Premium.
# 1 share quota per unique source (cached locally; re-runs free). No 5 KB cap.
# Requires API key. Default keeps existing share tokens across re-runs;
# use --re-mint to force fresh tokens (e.g. collaborator taking ownership).
bd extract README.md --share
bd extract README.md --share --re-mint
# Sidecar mode: writes local SVG files via /v1/export.
# Pro/Premium plans get watermark-free output; consumes export quota.
bd extract docs/*.md --assets-dir ./img --concurrency 4
# Preview what bd extract would change without writing.
bd extract README.md --dry-run
The API does NOT persist source unless the user calls bd share. Do not warn
about server-side storage when running beautify, export, or
ai generate — that is misleading. AI prompts are logged in hashed form
for abuse / quality monitoring; the raw text is not retained.
as a Markdown code block whena Mermaid source exists. Always run Beauty Diagram and reference the file.
--out and referencethe file path.
client; the engine lives behind the public API.
bd ai generate to "tweak" an existing diagram (changecolors, theme, labels, layout). It is a fresh-generation tool only.
For visual tweaks, change --theme or edit the .mmd source by hand.
bd ai generate speculatively — each call costs the usermonthly AI quota. Confirm the user wants AI generation before running it.
bd ai generate — the command outputs Mermaid source on stdout, not SVG. Pipe into bd beautify - to render.
bd export N times in a shell for loop when the user has many files. Use bd batch — it parallelizes and reports a summary,
with no extra server load (still one request per file).
into a Markdown file to "embed" adiagram. GitHub, GitLab, Obsidian (default), and most static-site
renderers strip inline SVG for safety. Use bd extract , which
writes sidecar SVGs and injects  references that actually
render.
bd extract injects. Inline mode uses / (with
an extra share=true attribute in share mode); sidecar mode uses
/ .
They are how bd extract stays idempotent — without them, the next run
will append duplicate image references instead of replacing the existing one.
| Symptom | Likely cause | Resolution |
|---|---|---|
| --- | --- | --- |
not_authenticated | No key, no session | bd auth login |
scope_missing | Key lacks scope (e.g. ai:write for bd ai generate) | Recreate key with required scope at /account/api-keys |
plan_not_allowed | Plan does not include this capability (AI is Pro / Premium only) | Upgrade or skip the call |
theme_tier_required | Selected --theme requires a higher plan tier than the token has (e.g. free token requesting atelier) | Pick a theme the token can use (run bd themes), or upgrade. See Themes & tiers above for the per-tier breakdown |
parse_failed | Source not valid Mermaid / PlantUML | Check the source — bd beautify will surface a parse error too |
quota_exhausted | Plan limit hit (anon: 1 export/IP/24h; free: 3 exports/mo; pro: 100 exports + 100 AI gens/mo; premium: ∞ exports + 500 AI gens/mo) | Sign in, wait for reset, or upgrade — hints in the response body has the URLs |
rate_limited | Anonymous IP bucket full (20 /v1/beautify requests / minute) or AI per-key bucket (30 /min) | Sign in or wait |
source_too_large | Source > 100 KB | Split the diagram |
output_too_large | PNG raster exceeds 8192 px | Lower --quality or simplify |
prompt_injection | AI prompt looked like an injection attempt | Rephrase as a plain diagram description ("a flowchart of …") |
instruction_rejected | AI judged the prompt was not about a diagram | Rephrase to describe a concrete diagram. Quota was NOT consumed |
parse_failed_after_retry | AI output was unparseable Mermaid even after one retry | Rephrase, or write Mermaid by hand. Quota was NOT consumed |
safety_blocked | Provider safety filter rejected the request | Rephrase the prompt |
upstream_timeout / upstream_error | AI provider was slow or failed | Retry after a moment |
When the user asks for "a GitHub README diagram", "embed in Notion", "embed in my blog post", "an of this diagram", or "a URL that renders my diagram", route to the embed flow rather than emitting raw mermaid:
bd share to save it.https://api.beauty-diagram.com/v1/share/.svg .bd embed-url and recommend the inline URL (note that anonymous embeds carry a "Powered by Beauty Diagram" watermark).Easier one-shot path: bd embed-url saves the diagram AND prints the embed URL in one command — no need to run bd share separately and then construct the URL by hand. Prefer this when the user wants a clean share embed.
Style fidelity: Per-node colors, edge presets, and font overrides set by the user in the web canvas editor ARE faithfully rendered in share-mode embeds (/v1/share/). Encourage a "tweak in editor → save → embed" workflow when the user wants brand colors or custom styling — they do not need to re-run bd embed-url after editing in the web UI, just re-save the diagram there.
Propagation timing: Saved diagram edits show up in direct embeds within ~5 minutes (browser ETag revalidation + 5-min CDN edge TTL). GitHub README embeds may lag a few hours due to GitHub's image proxy cache — that is a GitHub-side cache, not something we can purge.
Animations: Animations do NOT play in -loaded SVGs in any browser. Do not tell the user their animated diagram will appear animated in a README or Notion embed.
Slack / Discord / Twitter / iMessage previews: share links (https://www.beauty-diagram.com/s/) auto-unfurl with a diagram thumbnail card on these platforms — no need to manually attach a screenshot. The OG image is generated server-side from the diagram itself.
Owner-tier fallback on embed URLs: if the share's owner downgraded their plan AFTER saving the diagram (e.g. saved with Atelier on Pro, then downgraded to Free), GET /v1/share/ returns a 200 response with a brand-fallback SVG instead of the real content. Embeds must stay 200 for -mounted unfurls to render at all, so 403 is not used here. The owner can restore the original render by re-upgrading or switching to a free-tier theme and re-saving.
User: "Add a beautified version of this mermaid block to my README."
Agent steps:
bd embed-url ./architecture.mmd --share→ saves the diagram and prints the embed URL, e.g.
https://api.beauty-diagram.com/v1/share/abc12345xyz0.svg
(free owner → watermarked; pro/premium owner → clean).
See examples/ for runnable sources you can adapt:
examples/flowchart.mmdexamples/sequence.mmdAnd scripts/ for shell wrappers you can copy into the user's repo:
scripts/beautify.shscripts/export.shscripts/ai-generate.sh — prompt → .mmd source → .svg render共 3 个版本