Use the API
Scripts and AI agents can work with temperwork through its API: upload datasets, make steps and pipelines, start runs, judges and trainings, wait for them, and download what they made. Each request sends an API key you make on the Account page.
Make a key
On the Account page, under API keys, name the key, choose what it may do and when it expires, and select Create key. Copy the key (tw_...) right away: it is shown once.
read only lists and reads, and checks runs without starting them.
read and write also creates, changes, deletes and starts runs.
A key acts as you, in the organization you are acting for when you make it. It reaches pipelines and steps, judges, datasets, executions, trainings and LoRAs. Credits, environments, your account, organizations and other keys are managed on their pages only, never with a key.
A key expires after 90 days unless you choose otherwise (1 to 365 days, or never); you can have 25 active at a time. It stops working as soon as you revoke it, when it expires, if you lose access to temperwork, or if you leave its organization. Runs still use your organization's credits: a run they don't cover is refused before it starts.
Send a request
Put the key in the Authorization header of every request. Bodies are JSON:
export TW_KEY=tw_...
curl -H "Authorization: Bearer $TW_KEY" https://temperwork.com/v1/datasetsIf something between you and temperwork uses the Authorization header itself (some proxies do), send the key as X-Api-Key: tw_... instead.
Every route is in the API reference, which is generated from the API itself, so it stays true to it.
Upload, run and wait
API=https://temperwork.com/v1
H="Authorization: Bearer $TW_KEY"
# a dataset, and a file in it (up to 4 MB this way)
curl -H "$H" -H 'Content-Type: application/json' -d '{"name": "album"}' $API/datasets
curl -H "$H" -H 'Content-Type: application/octet-stream' --data-binary @photo.jpg \
"$API/datasets/album/files?file=photo.jpg"
# a step, then a run of it on the dataset
curl -H "$H" -H 'Content-Type: application/json' \
-d '{"name": "Brighten", "kind": "step", "settings": {"prompt": "brighter"}}' $API/pipelines
curl -H "$H" -H 'Content-Type: application/json' -H 'Idempotency-Key: brighten-album-1' \
-d '{"pipeline_id": "<its id>", "data": {"input": "album"}}' $API/executions
# wait for it (each call waits up to 25 seconds), then download its output
curl -H "$H" "$API/executions/<execution id>?wait=25"
curl -H "$H" -H 'Content-Type: application/json' -d '{}' $API/datasets/<output dataset>/linksLarger files go straight to storage: POST /v1/datasets/<name>/uploads gives a URL to PUT the file to, then .../uploads/complete checks it.
Retries
Send an Idempotency-Key header (any unique string) when you start a run, a judge's run or a training. If the request times out and you send it again with the same key, you get the first answer instead of a second run. A key is remembered for a day.
Errors
An error is {"error": {"code": ..., "message": ...}}. The message says what to change.
| Status | When |
|---|---|
| 400 | Something in the request is wrong. |
| 401 | No key, or one that is unknown, revoked, expired or read only for this request. |
| 402 | Your organization's credits don't cover it. Nothing was started. |
| 404 | No such route, or nothing of yours by that name or id. |
| 409 | It changed meanwhile, it is running, or an Idempotency-Key was reused for another request. |
| 429 | Too many requests with this key: wait the seconds in Retry-After. |