Skip to content

Serve API ​

Every call on this page is built. What version 1 leaves out is in Not in version 1. To follow it from an empty folder to a running container, read Serve your agent.

In serve mode golem runs in a container behind your app. Your app's backend calls this API, on a private network, with a key. It starts workflow runs for your own users, follows them, and answers the review questions they raise. It can also chat with an agent in the OpenAI shape.

The basics ​

Base path/v1. The contract changes only by adding.
AuthAuthorization: Bearer gk_.... A missing or wrong key is 401.
Who a run is foruser: your own id for a person. It is in the body of a start, and in the user query parameter of every other runs call. A run of another user is 404, never 403.
RetriesIdempotency-Key on a request that starts a run.
Errorsapplication/problem+json with code and request_id. Branch on code.
Limits429 with Retry-After and the name of the limit. See Limits.
TracingX-Request-Id on every response. A valid traceparent you send is echoed, stored with the run (or the chat session) and shown in its trace, and its trace id is on every gateway log line of the request. An invalid one is ignored.

What the app folder holds, and how to start the container, is on What goes in /app.

The examples use $GOLEM for the address (such as http://golem.internal:7480) and $KEY for a key.

Run states ​

statusMeans
submittedAccepted, not started.
workingRunning.
input-requiredWaits on a review. The run's interrupts list the open questions.
completedDone. output has the result.
failedStopped with an error. error says why.
canceledCancelled.

The last three are final. ADR-064 maps golem's own states to these.

1. Start a run ​

sh
curl -i "$GOLEM/v1/workflows/draft_reply/runs" \
  -H "Authorization: Bearer $KEY" \
  -H "Idempotency-Key: ticket-1042-first-try" \
  -H "Content-Type: application/json" \
  -d '{"input": {"ticket": "T-1042"}, "user": "u_8f2c"}'

The answer is 202, with the place of the run and the run itself:

http
HTTP/1.1 202 Accepted
Location: /v1/runs/run_7Hq2Kd9x
X-Request-Id: req_a81

{"id": "run_7Hq2Kd9x", "workflow": "draft_reply", "user": "u_8f2c", "status": "submitted",
 "created_at": "2026-12-01T09:00:00Z", "updated_at": "2026-12-01T09:00:00Z",
 "interrupts": [], "usage": {"cost_usd": 0}, "metadata": {}}

The input is checked before anything is written. An input the workflow does not take, one of the wrong type, or a required one that is missing or null is 422 with code input_invalid, and the problem has field: the name of the input. A workflow says which inputs are required with @workflow(required=[...]) (the workflow guide); the others may be left out.

Send the same request again with the same Idempotency-Key and you get the same run, with 200. The same key with another body is 409. usage has the cost golem recorded. It has no token counts, because golem does not keep them for workflow steps.

2. Follow it ​

Poll the run:

sh
curl "$GOLEM/v1/runs/run_7Hq2Kd9x?user=u_8f2c" -H "Authorization: Bearer $KEY"

Or follow its events. -N keeps curl from buffering. You do not need a GET first: a new connection starts with the run's state.

sh
curl -N "$GOLEM/v1/runs/run_7Hq2Kd9x/events?user=u_8f2c" -H "Authorization: Bearer $KEY"
text
event: run.status
data: {"status": "working"}

id: 1
event: run.status
data: {"status": "working"}

id: 2
event: step.started
data: {"key": "fetch-ticket", "kind": "step", "title": "Fetch the ticket", "attempts": 1}

id: 3
event: step.finished
data: {"key": "fetch-ticket", "kind": "step", "title": "Fetch the ticket", "status": "done"}

id: 4
event: run.interrupt
data: {"id": "review:reply", "kind": "review", "title": "Send this reply?", "ask": "Look at the reply before it goes out.", "draft": "Hello Ana, your refund is on its way."}

id: 5
event: run.status
data: {"status": "input-required"}

The first run.status has no id: and is not stored: it is the state of the run when you connected (submitted, working, input-required or a final one), sent only on a connection that gives no position. The events with an id: follow, from the first, so the state may appear twice. Because the state event has no id:, it never moves Last-Event-ID: a client that drops before it has seen a stored event connects again with no position and gets the state again, and a client that has seen one resumes after that event's own id. step.started means the step is running. step.finished has the step's final state in status: done, failed, skipped or in_doubt. A step has no other event, so a step that has started and not finished is running.

A review is announced by run.interrupt, which carries the whole interrupt, so you can show it without a second GET. The run.status that moves the run to input-required comes after the run.interrupt of every open review. When a run fails, run.error comes first and the final run.status with failed after it. The stream stays open while the run waits, and ends after the final event. If the connection drops, ask again from where you were:

sh
curl -N "$GOLEM/v1/runs/run_7Hq2Kd9x/events?user=u_8f2c" \
  -H "Authorization: Bearer $KEY" -H "Last-Event-ID: 5"

?starting_after=5 does the same. Any position, 0 included, is a resume: send none to start fresh. The events are run.status, step.started, step.finished, run.interrupt, run.output and run.error. Model text is not in this stream in version 1.

Events that expire ​

golem keeps the stored events of a run that has ended for [serve] keep_events_days (30 unless the app sets another; 0 keeps them for ever). After that the daemon trims the run to the events that end it (run.error, if any, and the final run.status), in the background, once an hour. A run that has not ended is never trimmed. The numbers do not change: what is left starts at a number above 1.

A resume that asks for events before the first one that is kept is 410 with code events_expired, and the problem has first_seq. Do this: connect again with no Last-Event-ID and no starting_after. You get the run's state, then what is kept. A resume from the number just before first_seq (or later) is not a gap and works.

3. Answer a review ​

A run waits on a review only when the container sets ask = "app" in the [serve] table of config.toml. With the default, ask = "deny", golem answers every review reject at once, with a reason in the step's result, and the run goes on: it is never input-required. A tool call that would ask is denied under both settings, so a tool is never an interrupt in version 1.

A run in input-required has one interrupt for each open review, with no time limit, and it stays so if golem restarts. Answer all of them in one call. The verdicts are golem's own: approve, edit and reject. edit needs text, your version of the draft. approve and reject may carry text too.

sh
curl -i "$GOLEM/v1/runs/run_7Hq2Kd9x/resume?user=u_8f2c" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{"answers": [{"id": "review:reply", "verdict": "edit", "text": "Hello Ana, your refund is on its way."}]}'

The answer is 202 and the run, which goes on as working. The answers are checked together and saved together, so a refused call changes nothing:

ProblemStatuscode
An open question has no answer. The problem has missing: the ids left out422answers_incomplete
An unknown id, an id twice, an unknown verdict, or an edit without text422answer_invalid
The run is not input-required (also a second identical call, which finds the run already going on)409run_not_waiting
The run is another user's404not_found

resume takes no Idempotency-Key.

When the run is completed, GET /v1/runs/{id} has its output.

Cancel a run ​

sh
curl -X POST "$GOLEM/v1/runs/run_7Hq2Kd9x/cancel?user=u_8f2c" -H "Authorization: Bearer $KEY"

It is safe to call twice, and always answers 200 with the run and one more field, canceled_by_this_call: true when this call stopped a run that was going, false when the run had already ended (or another call stopped it first). So a caller can tell "I stopped it" from "it had ended" without a second GET. golem does not answer 409 for a run that has ended. The answer waits a few seconds for a stopped run to reach canceled.

json
{"id": "run_7Hq2Kd9x", "status": "canceled", "canceled_by_this_call": true, "...": "the rest of the run"}

Chat ​

An agent of your app is a model. Point an OpenAI client at $GOLEM/v1:

sh
curl "$GOLEM/v1/chat/completions" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "support", "messages": [{"role": "user", "content": "Where is my order?"}], "safety_identifier": "u_8f2c"}'

A traceparent header on the request is stored with the session and shown by its trace. The call is stateless: each request starts a short session of that user, seeded with messages, and runs the last one, which must be a user message. The agent keeps its own instructions, and a system message of yours is added to them. Add "stream": true for server-sent chunks that end with data: [DONE]; they carry the assistant's text only, and a client that hangs up cancels the turn.

Supported: model, messages (text only), stream, stream_options.include_usage, metadata, safety_identifier and user. temperature, top_p, max_tokens (or max_completion_tokens) and stop (up to 4 strings) are applied to the model call. The agent's own max-tokens is a ceiling: the smaller one wins, and finish_reason is length when the limit cut the answer. A setting the model of the agent cannot take (for example top_p together with temperature on a Claude model, or temperature on an OpenAI reasoning model) is refused with 400 and unsupported_parameter, naming the field. The two checks golem makes itself are these: a Claude model takes temperature or top_p, not both, and an OpenAI reasoning model takes none of temperature, top_p and stop. A provider may refuse more. When it answers 400 and names one of the four settings, that is unsupported_parameter too, with the field. tools, functions, image and audio parts, n above 1 and a response_format other than text are refused with 400 and the field's name: the client does not run tools in version 1. Fields golem does not know are ignored.

Errors ​

A problem looks like this:

json
{
  "type": "https://golem.dev/problems/answers-incomplete",
  "title": "Every open question needs an answer",
  "status": 422,
  "detail": "The run waits on review:reply. Answer it.",
  "code": "answers_incomplete",
  "request_id": "req_a8f"
}

The code values are fixed. New ones are only added.

codeStatusMeaning
invalid_request400, 422The body or a parameter is wrong.
invalid_key401The key is missing, wrong or revoked.
not_found404No such run, or it is not yours.
workflow_not_found404The app has no such workflow.
model_not_found404The app has no such agent.
input_invalid422input does not fit the workflow's inputs: an unknown one, the wrong type, or a required one missing. field names it.
idempotency_conflict409The key was used with another body.
idempotency_in_progress409The first request with this key is still being handled.
run_not_waiting409The run is not input-required, or an answer to it was already taken.
answers_incomplete422An open interrupt has no answer.
answer_invalid422An unknown id, an unknown verdict, or an edit without text.
user_required400A runs call with no user, or a chat request with no safety_identifier or user.
tools_not_supported400The request has tools or the like.
unsupported_parameter400A chat field that version 1 does not do.
payload_too_large413The body is too big.
unsupported_media_type415The body is not JSON.
events_expired410The events asked for are no longer kept. first_seq is the first one that is. Connect again with no position.
rate_limited429A limit is reached. See Retry-After.
budget_exceeded429The key's or user's budget is spent.
upstream_error502A model endpoint failed.
draining503golem is stopping. Try again.
not_ready503golem has not loaded the app yet.
internal_error500A bug. Quote request_id.

Limits ​

One user, or one leaked key, cannot run up the bill or starve the others. You set the limits in the app's config.toml under [serve.limits] (the table of settings). A caller that passes one gets 429 and a problem whose limit says which:

json
{
  "type": "urn:golem:problem:rate_limited",
  "title": "Too many requests",
  "status": 429,
  "detail": "The limit runs_at_once is reached. Try again in 3 seconds.",
  "code": "rate_limited",
  "limit": "runs_at_once",
  "request_id": "req_a8f"
}
limitcodePerKept by
requests_per_minuterate_limitedkeythe gateway
streams_at_oncerate_limitedkeythe gateway
runs_at_oncerate_limiteduserthe daemon
runs_at_once_totalrate_limitedthe deploymentthe daemon
user_usd_per_daybudget_exceededuser, per UTC daythe daemon
key_usd_per_daybudget_exceededkey, per UTC daythe daemon
  • Retry-After is a whole number of seconds, at least 1. For budget_exceeded it is the time to the next midnight UTC. Wait that long, or show the person "come back tomorrow".
  • The gateway counts requests and open streams in memory, for one replica. GET /healthz and GET /readyz are never limited.
  • Runs at once count the runs and chat turns that are executing. A run that waits for a review (input-required) does not count, and answering it makes it count again. A start that repeats an earlier one (the same Idempotency-Key) is never refused.
  • Money comes from the cost golem records for each model call. It is checked before a run or a chat turn starts (429 budget_exceeded) and again before every model call inside it. A run that reaches the limit in the middle ends failed, its error.code is budget_exceeded, and the steps before it keep their results. A call that costs nothing (a local model) is never stopped. A call can pass the limit by its own cost: the cost is known only when it ends.
  • "Per key" is everything started through that key. A user's spend counts across all keys.

GET /v1/usage?user=u_8f2c answers how much that user has used today (UTC) and what is left. Without user it answers for the key:

json
{
  "user": "u_8f2c",
  "day": "2026-12-01",
  "cost_usd": 1.6,
  "limits": { "runs_at_once": 4, "runs_at_once_total": 32, "user_usd_per_day": 2 },
  "remaining_usd": 0.4
}

limits names the settings that apply; a money limit you did not set is left out, and so is remaining_usd. Show "you have used 80%" from cost_usd and user_usd_per_day.

Webhooks ​

Instead of polling, let golem call your app when a run ends or needs an answer. Set it in the app's config.toml (the table):

toml
[serve.webhooks]
url = "https://app.example/hooks/golem"
secret = "secret:webhook/app"      # the value is whsec_ and base64
events = ["run.completed", "run.failed", "run.canceled", "run.input_required"]

golem follows the Standard Webhooks 1.0 spec. It sends a POST with a JSON body for each run an app key started, once for each event:

typeWhen
run.completedThe run is completed.
run.failedThe run is failed.
run.canceledThe run is canceled.
run.input_requiredThe run waits on a review (input-required). A run that is answered and waits again sends it again.
http
POST /hooks/golem HTTP/1.1
Content-Type: application/json
webhook-id: msg_2f1c0b9a7e4d4c0f8a1b3d5e6f708192
webhook-timestamp: 1796115600
webhook-signature: v1,K5oZfzN95Z9UkDG9n6bC6Wt2Ow3xC5kq1pU0m0hQ0aY=

{"type":"run.input_required","timestamp":"2026-12-01T09:00:00+00:00","data":{"run":{"id":"run_7Hq2Kd9x","workflow":"draft_reply","status":"input-required","user":"u_8f2c"}}}

The body is thin on purpose. It has no input, no output and no review draft, so nothing private leaves golem in it. Read the run with GET /v1/runs/{id}?user=... for the rest.

Check the signature ​

The signed text is webhook-id, ., webhook-timestamp, . and the raw body, as they came. The key is the base64 part of the secret (after whsec_). The signature is v1, and the base64 HMAC-SHA256 of that text. Check it on the raw bytes, before you parse the JSON, with a constant-time compare, and refuse a webhook-timestamp more than five minutes from your clock.

python
import base64, hashlib, hmac, time

def verify(secret: str, headers: dict[str, str], body: bytes) -> bool:
    key = base64.b64decode(secret.removeprefix("whsec_"))
    if abs(time.time() - int(headers["webhook-timestamp"])) > 300:
        return False
    signed = f"{headers['webhook-id']}.{headers['webhook-timestamp']}.".encode() + body
    expected = base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()
    return any(
        hmac.compare_digest(expected, part.removeprefix("v1,"))
        for part in headers["webhook-signature"].split()
        if part.startswith("v1,")
    )
ts
import { createHmac, timingSafeEqual } from "node:crypto";

export function verify(secret: string, headers: Headers, body: string): boolean {
  const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
  const id = headers.get("webhook-id") ?? "";
  const timestamp = headers.get("webhook-timestamp") ?? "";
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
  const expected = createHmac("sha256", key).update(`${id}.${timestamp}.${body}`).digest();
  return (headers.get("webhook-signature") ?? "").split(" ").some((part) => {
    if (!part.startsWith("v1,")) return false;
    const given = Buffer.from(part.slice(3), "base64");
    return given.length === expected.length && timingSafeEqual(given, expected);
  });
}

Delivery and retries ​

  • Answer 2xx to end it. Any other answer, a refused connection and a wait of more than 10 seconds count as a failure. golem does not follow redirects.
  • It tries again after about 5 seconds, 30 seconds, 2 minutes, 10 minutes and 1 hour, then every 6 hours, and gives up after 3 days. webhook-id is the same on every try of one delivery, so use it to ignore a repeat. webhook-timestamp and the signature are new on each try.
  • 410 Gone means "stop": golem sends nothing more to that URL until it restarts, and logs it.
  • A delivery is written in the same step that changes the run's state, and sent after. A restart loses none, and a crash cannot send one for a state that was not saved. Deliveries are not promised in order, so read the run for its state now.
  • golem sends only where its outgoing rules allow: the URL must be https, or plain http to localhost or a private name. It never logs the secret or a signature.

GET /v1/webhooks/deliveries?status=failed&limit=50 shows an operator what is stuck. status is pending (not tried yet), delivered or failed (a try failed: it will be tried again, or gave_up is true). It lists the latest deliveries of the runs this key started, newest first:

json
{
  "data": [
    {
      "id": "msg_2f1c0b9a7e4d4c0f8a1b3d5e6f708192",
      "type": "run.completed",
      "run_id": "run_7Hq2Kd9x",
      "status": "failed",
      "attempts": 2,
      "last_status": 500,
      "last_error": "the receiver answered 500",
      "created_at": "2026-12-01T09:00:00.000+00:00",
      "next_try": "2026-12-01T09:02:30.000+00:00"
    }
  ]
}

Users: delete, export and keep_days ​

Your users can ask you to erase what you hold about them, or to hand it over. Two calls do it, for one user of your app:

sh
curl -X DELETE "$GOLEM/v1/users/u_8f2c" -H "Authorization: Bearer $KEY"      # 202
curl "$GOLEM/v1/users/u_8f2c/export" -H "Authorization: Bearer $KEY" -o u_8f2c.json
  • Delete cancels the user's runs that have not ended (a run that waits for a review too), then removes everything in the table below. It is done when it answers 202. Do not wait for anything else. It is idempotent: a second call answers the same, {"user": "u_8f2c", "deleted": true}, whether or not anything was left.
  • Export is one JSON document, streamed, with the same set: user, exported_at, runs (each with its steps, outputs, reviews, events and webhook deliveries), chats (each with its messages) and usage (totals, by day). It changes nothing.
  • A user is a user id of the app, across all its keys. Keys are interchangeable credentials that get rotated, so any key may delete or export a user, including data made under a key that has been revoked. What you started yourself, with no key, is never touched.
  • Each call writes one audit line to golem's log, as JSON: event (user.delete or user.export), key (the key id), user and counts. It never holds content.
  • A user with nothing held is not an error: delete answers 202, export has empty lists.

What golem stores about a user ​

Where in /dataWhat it holdsDelete
golem.db workflow_runsEach run: its input, result, error, metadata, workflow, model and timesRemoved
workflow_steps, workflow_outputsWhat each step returned and what the run marked as an outputRemoved
workflow_reviewsThe draft of each review and the answerRemoved
workflow_eventsThe run's events (keep_events_days trims them)Removed
idempotency_keysThe Idempotency-Key of each start and a digest of its bodyRemoved
webhook_deliveriesThe body sent to your app (the user id, run id and state) and how it wentRemoved
sessions, events, runsEach chat of the user, the headless session of each of their runs, and the helpers of both: every message, tool call and resultRemoved
artifacts, file_changes, blobsTables and file changes a session kept, and the prompt texts only that user's sessions usedRemoved. A prompt that other sessions share stays
routine_runsA row that points at one of the user's runsRemoved
model_calls, model_outcomesOne row for each model call: model, tokens, cost, dayKept as numbers. The session and run ids are cut, and the key id that made the call is written in, so each key's spend of the day does not drop
checkpoints.dbThe model's memory of each sessionRemoved
memory.dbMemories written in the user's sessionsRemoved
Output filesA file a run marked with run.output, when it is under /data, is not golem's own file (a definition, a database, a log), and no run of anyone else marks it too. A file outside /data is the workflow's own and is never touchedDeleted
Copies and query results of helpersA folder or a Parquet file that a session madeRemoved with the session
The logThe audit line of a delete or export, and request_ids. golem logs no contentKept
Your appWebhook bodies already sent, and every answer you storedgolem cannot reach them

A copy of golem.db that golem made before an upgrade (golem.db.bak-N) is a copy of the past and is not edited. Remove it once you are sure of the upgrade, and exclude it from backups that must not keep a deleted user.

Old data leaves by itself ​

[serve] keep_days (off by default) sets how many days a run that has ended is kept, counted from when it ended. A sweep, once a day and once when the daemon starts, removes what is older, the same way a delete does: the run, its events, reviews, webhook deliveries, idempotency records, output files and sessions. It also removes app chats whose last use is that old. A run that has not ended is never swept, and neither is anything you started yourself. The usage totals stay.

keep_events_days keeps its meaning and may not be longer than keep_days: golem serve check says so (0, which keeps events for ever, counts as longer). Leave keep_days out to keep runs for ever.

Other calls ​

CallMeaning
GET /v1/runs?user=&status=&after=&limit=List one user's runs, newest first. user is required. Pass next as after for the next page.
GET /v1/modelsThe agents of the app.
GET /v1/usage?user=What one user, or the key without user, has spent today (UTC) and the limits. See Limits.
GET /v1/webhooks/deliveries?status=&limit=The latest webhook deliveries of this key's runs, to see what is stuck. See Webhooks.
DELETE /v1/users/{user}Delete everything held about one user of the app. 202. See Users.
GET /v1/users/{user}/exportEverything held about one user as one JSON document. See Users.
GET /healthz, GET /readyzNo key needed.
GET /metricsPrometheus text. Off unless [serve] metrics = true; needs a key. See Watching a served golem.

Not in version 1 ​

What golem does not do yet, in one place. The contract changes only by adding, so each of these may come later without breaking a caller.

WhatToday
Who answers a reviewask = "deny" and ask = "app" only. ask = "owner" (a queue for your own team) is refused by golem serve check
Model text in the run streamNot sent. A step's result is the unit. Use chat when you want the text as it comes
Tools the client runs in chattools and functions are refused with 400 (tools_not_supported). A tool is never a review in a run either
Chat inputsText only. Image and audio parts, n above 1, and a response_format other than text are refused with 400
Chat historyEach call is stateless. Send the messages you want the agent to see
Other OpenAI callsOnly GET /v1/models and POST /v1/chat/completions. There is no /v1/responses
CallersYour app's backend, on a private network, with a key. No CORS, so a browser cannot call it
More than one replicaOne golem uses one /data. The request and stream limits are counted in memory, for one replica
TracesThe gateway's log lines carry the trace id. The daemon's do not yet
A local modelServe mode starts no model server. A model is an endpoint by URL