← ASCII Diagram
Your token

ASCII Diagram API

The drawing and every export run free in the browser and need no API. The API is for the one metered step: send a description in words, get back PlantUML @startuml text - a sequence diagram or an activity diagram - which this page (or plantuml -txt) draws as text.

Base URL: https://api.skillsafe.ai/v1/app-api. Every response is {"data": ...} or {"error": {"code", "message"}}; read error.code and error.message rather than the HTTP status alone.

The task field

This app has one task. Always send "task": "diagram"; choose the drawing with kind.

taskWhat it doesReply
diagramTurns a description in words into diagram text: a title, then either a sequence diagram (participants the text names, one arrow per step in the order of the text, alt/opt/loop blocks only where the text states them, at most 8 participants and 40 arrows) or an activity diagram (start, one :step; per action, if/elseif/else/endif and while/endwhile only where the text states them, stop; at most 30 steps). Labels are in the text's language.One ```plantuml block

Input fields

FieldTypeMeaning
taskstring"diagram"
textstringThe description. The page sends at most 12,000 characters: longer text keeps its first and last lines and loses the middle, with a marker line.
kindstring"auto" (the model chooses), "sequence" or "flow" (activity diagram).
focusstringOptional, up to 200 characters: what the diagram should show, e.g. include the error cases.
factsstringJSON text of what the page read from the text: read_as (sequence, activity, steps or none), lines, boxes, names. Send "{}" if you have nothing.
clipped_notestringEmpty, or a sentence saying the middle of the text was cut.

The reply

job.output.output is text: one fenced block, @startuml first, @enduml last, then title. A sequence diagram declares participants (actor "User" as user) and has one arrow per line: a -> b : label (request), b --> a : label (reply), a ->> b : label (sent without waiting), with optional alt/else/opt/loop blocks closed by end and up to 3 notes. An activity diagram has start, :step; lines, if (question?) then (answer) ... else (answer) ... endif, while (question?) is (answer) ... endwhile (answer) and stop. No colours or styling. If the balance ran low, truncated is true and the block may stop early; the page closes open blocks and draws what arrived.

Worked example

Input (input.json):

{
  "task": "diagram",
  "text": "When a customer finds that a product is faulty, they open the returns page on the shop website and request a return within 30 days of delivery. The shop website emails the customer a prepaid return label. The customer sends the product back to the warehouse, and the warehouse inspects it when it arrives. The warehouse then reports the result of the inspection to the shop website. If the same item is in stock, the warehouse ships a replacement to the customer. If it is out of stock, the shop website asks the payment provider to refund the original payment, and the payment provider confirms the refund to the shop website. Finally, the shop website emails the customer to say the return is complete.",
  "kind": "auto",
  "focus": "",
  "facts": "{\"read_as\":\"none\",\"lines\":1,\"boxes\":0,\"names\":[]}",
  "clipped_note": ""
}

Reply:

```plantuml
@startuml
title Faulty product return
actor "Customer" as customer
participant "Shop website" as shop
participant "Warehouse" as warehouse
participant "Payment provider" as payment
customer -> shop : Request return within 30 days
shop ->> customer : Email prepaid return label
customer -> warehouse : Send product back
warehouse -> warehouse : Inspect product
warehouse --> shop : Report inspection result
alt Item in stock
  warehouse -> customer : Ship replacement
else Item out of stock
  shop -> payment : Refund original payment
  payment --> shop : Confirm refund
end
shop ->> customer : Email return complete
@enduml
```

Paste the reply into the page to draw it as ASCII or Unicode text, or run plantuml -txt on it.

Errors

HTTPWhat to do
401The token is missing, expired or a guest token on a run. Get a personal token on the token page.
402The balance is below what the run reserves. Top up at skillsafe.ai/account/billing.
400The body is not a JSON object of the fields above.
429Wait and retry with the same Idempotency-Key.

Step 1 — a tiny client helper

One function that sends JSON and unwraps the {data, error} envelope.

BASE="https://api.skillsafe.ai/v1/app-api"
TOKEN="paste-your-token-here"   # from https://ascii-diagram.skillsafe.ai/tokens.html
api() { # api METHOD PATH [JSON-BODY]
  curl -s -X "$1" "$BASE$2" -H "Content-Type: application/json" \
    ${TOKEN:+-H "Authorization: Bearer $TOKEN"} ${3:+--data "$3"}
}

Step 2 — a token

A guest token is enough for /me and /estimate. A run is metered, so it needs your personal token: sign in on the token page and copy it.

# a guest token (enough for /me and /estimate); a run needs your personal token from /tokens.html
TOKEN=$(curl -s -X POST "$BASE/guest" -H "Content-Type: application/json" -d '{"slug":"ascii-diagram"}' | jq -r '.data.token')

Step 3 — who am I, and my balance

subject_type is guest or user; credits is the balance (1 credit = $0.0001).

api GET /me | jq '.data | {subject_type, credits}' 

Step 4 — price a run for free

/estimate charges nothing and starts no job. hold_credits is the amount reserved while a run is in flight, not the price; the run is charged what it uses.

# input.json: the run input object - {"task": "diagram", "text": "...", "kind": "auto", "focus": "", "facts": "{...}", "clipped_note": ""}
api POST /estimate "$(cat input.json)" | jq '.data | {hold_credits, min_credits, model, model_alias, markup_bps, warnings}' 

Step 5 — run it and wait for the job

Send an Idempotency-Key derived from the input: a retry with the same key is never billed twice.

KEY="ascii-diagram:diagram:$(shasum -a 256 input.json | cut -c1-16):a1"
JOB=$(curl -s -X POST "$BASE/run" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: $KEY" --data @input.json | jq -r '.data.job_id')
while :; do
  J=$(api GET "/jobs/$JOB"); S=$(echo "$J" | jq -r '.data.status')
  case "$S" in succeeded|failed|cancelled) break;; esac; sleep 2
done
echo "$J" | jq -r '.data.output.output' > reply.txt   # one ```plantuml block: @startuml ... @enduml
echo "$J" | jq '.data | {charged_credits, truncated}' 

Step 6 — or stream it

/run-stream sends Server-Sent Events while the job runs and the finished job at the end.

# Server-Sent Events: tick/delta events while the job runs, then a final event with the job
curl -N -s -X POST "$BASE/run-stream" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: ascii-diagram:diagram:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.json