Token Desk / API
Get a token

Driving Token Desk from code

Everything the web app does is available over HTTP. The base URL is https://api.skillsafe.ai/v1/app-api, every request carries Authorization: Bearer <token>, and every response is the same envelope.

The task field comes first

This app has five lanes behind one endpoint. Every run body must carry a task field naming the lane - it is what the system prompt routes on. Send the wrong one and you get a valid package of the wrong kind; omit it and the model picks the closest lane and tells you which it chose.

One more shape trap: the run body is the input object. Do not wrap it in an {"input": ...} envelope - that returns 200 while hiding task from the model, which is the most confusing way this API can fail.

taskLaneFieldsSections returned
planDesign a prompt the window and the budget can pay forbrief, knownSummary, The Prompt, The Numbers, Reasoning, Next Step
readWhat this prompt actually costs, per call and per conversationsheet, worrySummary, Verdict, Findings, Corrected Prompt, Next Step
turnsThe conversation: what it bills as it grows, and where it stops fittingsheetSummary, Every Turn’s Bill, Where The Window Runs Out, What Trimming Would Change, Next Step
cacheThe cache: where the prefix really ends, and whether it payssheetSummary, The Prefix, When Caching Pays, What One Volatile Line Costs, Next Step
decideDecide what changes: a part, the order, or the modelsheet, fixedSummary, Moving A Part Fixes, Only A Different Model Fixes, Nothing Fixes, Next Step

Only task and the lane's own required fields are mandatory: sheet on read, turns, cache and decide; brief on plan. Every field is a string - there are no number fields on this app. sheet is the prompt budget sheet itself: a header of KEY: value lines and a PROMPT: block with one part per line, in the order the prompt is assembled.

WINDOW: and MAX-OUTPUT: take 8192, 128k or 1M; assumed 200k and 64k. They are two numbers because the window holds input AND output, so the input ceiling is the difference - which is the figure the turn count is actually bounded by. PRICE: takes in= and out= in dollars per million tokens; assumed 3 and 15. The RATIO between them is what decides which half of the bill is worth optimising. TURNS: is a count; assumed 20. RATE: takes 10/min, 600/h or 10000/day; assumed 1/min. The unit matters more here than anywhere else on the sheet, because the cache answer is decided by whether the next call lands inside the TTL - reading /day as /min would move it by a factor of 1,440. CACHE: takes ttl=, min=, write= and read=.

A part needs tokens= and nothing else. It takes 1800, 1.8k or 2M; a bare number is tokens, and a negative one is rejected rather than summed. count= multiplies it, which is what makes a few-shot block a per-call cost rather than a one-off. per=turn says the part is re-sent as the conversation grows. kind=output says it is generated rather than sent, and is priced at the output price. volatile=yes says it changes every call. cached=yes is what you INTENDED - whether it can be is what this API works out, and a marking that can never take effect is reported by name.

Order is the prompt. A cache breakpoint covers a PREFIX, so the first part that changes between calls ends it and every later part is uncacheable however it is marked. Moving one line therefore changes the whole cache answer while changing nothing the model reads - which is why the response reports the prefix you have, the best one this prompt allows, and the difference.

Anything the reader cannot place is listed as a problem rather than skipped, and so is a part named twice or one whose count= is unreadable. A part with no tokens= is an error: it has no size, so every total would be smaller than the truth - the direction that matters.

A token count is reported with thousands separators, a window as 200k, money to as many places as it takes not to read as zero, a share as a percentage and a ratio as 17.8×. This API does not tokenise - it has no model's vocabulary - so every figure is arithmetic on the counts you send, and a count 10% out makes every figure 10% out in the same direction.

Add $model to any body to choose the model for that run: gpt-5.6-luna, gpt-5.6-terra (the default) or gpt-5.6-sol. Luna caps output at 4,096 tokens and will fail the read, turns and cache lanes rather than shorten them - a findings table, a corrected prompt, or a table with a row per turn, is several thousand characters before the reasoning starts.

The response envelope

Success and failure have the same outer shape, so one check covers both.

{
  "ok": true,
  "data": {
    "...": "the result"
  }
}
{
  "ok": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "seconds should be number, got string",
    "details": {}
  }
}
HTTPerror.codeWhat it means
400VALIDATION_ERRORThe body was not a JSON object, or a declared field had the wrong type. A number field sent as a string is the usual cause.
401UNAUTHORIZEDNo token, or a token that has expired or been revoked. Mint a new one.
402INSUFFICIENT_CREDITSThe balance is below the run's minimum. Call /estimate first and compare hold_credits against /me.
404NOT_FOUNDWrong path, or a job id that does not belong to this token.
409CONFLICTAn Idempotency-Key replay whose body differs from the original request.
429RATE_LIMITEDToo many requests. Back off; do not tight-loop.
503UPSTREAM_UNAVAILABLEThe model provider is unavailable. Retry with backoff.

1. Get a token

Open /tokens.html in a browser and copy the token this app already holds - no developer console needed. A guest token is minted automatically and is enough for /me and /estimate; writing a package is metered and needs a personal token, which comes from signing in on that page.

Keep it in an environment variable rather than in source:

export SKILLSAFE_TOKEN="YOUR_TOKEN"

2. Check the session and the balance

GET /me is free. It returns only three fields: subject_type, subject_id and credits. Signed-in means subject_type == "user" - there is no username or email to test.

curl -sS -X GET "https://api.skillsafe.ai/v1/app-api/me" \
  -H "Authorization: Bearer $SKILLSAFE_TOKEN"

3. Price the run before making it

POST /estimate costs nothing, creates no job, and returns the worst-case cost. Compare hold_credits against the balance from step 2 before you submit: a 402 after the fact is avoidable. hold_credits is a reservation priced at the full output cap - the actual charge is usually far lower.

It also echoes model, model_alias and markup_bps, which is the authoritative check that a run is bound to the model you think it is. Estimate each lane separately: their prompts and caps differ, so their holds do.

curl -sS -X POST "https://api.skillsafe.ai/v1/app-api/estimate" \
  -H "Authorization: Bearer $SKILLSAFE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "task": "read",
  "sheet": "<WINDOW, PRICE, TURNS, RATE and a PROMPT block, one part per line; the grammar is in /llms.txt>",
  "worry": "the bill is four times what I modelled and the prompt has not changed",
  "rules": "<the working rules for this lane, sent by the app>"
}'

4. Write a package

POST /run submits the job. Always send an Idempotency-Key: a network blip that replays the same request must not bill twice. A replay with the same key returns the stored result and is not charged again; a replay with the same key but a different body is a 409.

The response carries output.output (the Markdown package), charged_credits and truncated. If truncated is true the balance sat between min_credits and hold_credits and the output was cut short - render what arrived and say so rather than presenting it as complete.

curl -sS -X POST "https://api.skillsafe.ai/v1/app-api/run" \
  -H "Authorization: Bearer $SKILLSAFE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "task": "read",
  "sheet": "<WINDOW, PRICE, TURNS, RATE and a PROMPT block, one part per line; the grammar is in /llms.txt>",
  "worry": "the bill is four times what I modelled and the prompt has not changed",
  "rules": "<the working rules for this lane, sent by the app>"
}'

5. Stream a run

POST /run-stream is the same call with a text/event-stream response. Worth knowing before you build on it: from a server or from cURL you get event: delta frames carrying the output token by token; from a browser you get event: tick heartbeats and then one event: done with the whole output. Handle both, and treat ticks as liveness rather than progress.

Frame types are job (the job id), delta ({"text": "..."}), tick ({"t": seconds}), done, and error. An idempotent replay returns plain JSON with no stream at all, so check the content type before you start reading frames.

curl -sS -N -X POST "https://api.skillsafe.ai/v1/app-api/run-stream" \
  -H "Authorization: Bearer $SKILLSAFE_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Accept: text/event-stream" \
  -H "Idempotency-Key: cbd-$(date +%s)" \
  -d '{
  "task": "read",
  "sheet": "<WINDOW, PRICE, TURNS, RATE and a PROMPT block, one part per line; the grammar is in /llms.txt>",
  "worry": "the bill is four times what I modelled and the prompt has not changed",
  "rules": "<the working rules for this lane, sent by the app>"
}'

6. Read the result

output.output is Markdown in the envelope this app's system prompt guarantees: every section is a level-two heading spelled exactly as listed in the lane table above, in that order; tables are GitHub pipe tables with the declared columns; prompts are in fenced blocks opened with three backticks and the word text; checklists are - [x] lines.

So parsing is a split on /^## / - but do it fence-aware, because a prompt block can legitimately contain a line starting with ##. Count the sections you got against the ones the lane declares: a short list means the run was truncated, not that the contract changed.

def sections(md):
    out, name, buf, fence = {}, None, [], False
    for line in md.split("\n"):
        if line.lstrip().startswith("```"):
            fence = not fence
        if not fence and line.startswith("## "):
            if name:
                out[name] = "\n".join(buf).strip()
            name, buf = line[3:].strip(), []
            continue
        if name:
            buf.append(line)
    if name:
        out[name] = "\n".join(buf).strip()
    return out

The artifact most callers want is the fenced text block inside ## The Sheet or ## Corrected Sheet - that is a complete sheet in the grammar above, so it can be fed straight back into another lane with nothing carried alongside it. Every other section is prose and tables meant to be read.

Rate limits and good manners