HTTP server
atomic-agent serve turns your machine into an agent API. It starts a Node HTTP server that speaks the OpenAI Chat Completions protocol, so any OpenAI SDK can point at it. It also speaks the Anthropic Messages API (for Claude Code) and the OpenAI Responses API (for Codex and the Agents SDK), plus a set of Atomic Agent management routes for sessions, approvals, tasks, skills, and config.
It boots one shared runtime and serves every request from it. The same per-session FIFO turn controller applies: requests on different sessions run in parallel, requests on the same session serialise.
atomic-agent serve [--host H] [--port P] [--cwd DIR] [--api-key K] [--no-approval] [--parent-pid PID] [--no-parent-exit] [--reap] [--tunnel | --tunnel-name N --tunnel-hostname H]The server listens until SIGINT or SIGTERM (Ctrl-C). By default it also stops when the process that started it exits; --no-parent-exit keeps it running.
serve boots the same runtime as the TUI, so enabled Telegram and Discord channels (and swarm bots that have a token) run in this process too. A channel runs in one process at a time; if another process already runs it, serve reports it as already running.
Authentication: set a key
This is the one thing to get right before anything else.
If you pass no --api-key and set no ATOMIC_AGENT_API_KEY, the server starts without authentication, and only on a loopback host. The startup line says auth=none, followed by a warning that any program on this machine can run the agent and its tools:
[atomic-agent] serve listening on http://127.0.0.1:8787 (auth=none, cwd=/Users/you/project)With a key it reads auth=bearer instead. That token is your only check on who gets to drive an agent that can write files and run shell commands on your machine.
Without a key the server protects itself in three ways:
serverefuses to start on a host other than loopback (0.0.0.0,::, a LAN address or a hostname). It prints how to set a key.- Every request must name a loopback host in
Host, otherwise it gets403 host_not_allowed. This blocks DNS rebinding. - A request with an
Originheader must come from a loopback origin or one listed inATOMIC_AGENT_ALLOWED_ORIGINS(comma-separated), otherwise it gets403 origin_not_allowed. APOST,PUT,PATCHorDELETEwith a body must sendContent-Type: application/json, otherwise it gets415. curl and CLI clients send noOriginand are not affected.
# Authenticated, reachable from the local networkATOMIC_AGENT_API_KEY="$(openssl rand -hex 32)" \ atomic-agent serve --host 0.0.0.0 --port 8787Authenticated routes expect a standard bearer header:
Authorization: Bearer <token>Flags
| Flag | Default | Description |
|---|---|---|
--host H | 127.0.0.1 | Address to bind. A host other than loopback needs an API key, or serve refuses to start. |
--port P | 8787 | Port to listen on. Must be an integer in 0..65535. |
--cwd DIR / --working-dir DIR | current directory | Working directory the OS tools and sessions resolve against. |
--api-key K | ATOMIC_AGENT_API_KEY env var | Bearer token required on every route except the public ones. An empty or whitespace-only key is refused. If both flag and env var are omitted, the server runs without auth on loopback only. |
--no-approval | off | Force approval level 5 (approve everything) for all requests handled by this process. The saved level is not changed. |
--parent-pid PID | the real parent | Watch this process instead of the actual parent, for spawners that double-fork. Must be greater than 1. |
--no-parent-exit | off | Keep running after the parent exits. Use it to run serve as a daemon from a shell, under nohup, or with & disown. ATOMIC_AGENT_SERVE_NO_PARENT_EXIT=1 does the same. |
--reap | off | Stop servers stranded by earlier runs, print what was found, and exit. |
--tunnel | off | Reach the webhooks from the internet through a Cloudflare quick tunnel (a random https://….trycloudflare.com address, no account). Needs cloudflared on PATH and at least one webhook with a secret. See Webhooks. |
--tunnel-name N, --tunnel-hostname H | Use your own named Cloudflare tunnel and the public hostname routed to it instead. Both are needed. |
An unknown flag, a missing value, or an out-of-range port exits 1 and prints the help text.
Routes
GET /health and GET /v1/models are public by design so OpenAI SDKs can probe the server before they have a key. GET /panel (a small phone page that asks for the key itself) is public too. Everything else requires the bearer token when one is configured.
| Method & path | Auth | Purpose |
|---|---|---|
POST /v1/chat/completions | required | Chat completions, streaming or sync. |
POST /v1/chat/completions/{completion_id}/cancel | required | Abort a streaming completion by id. |
GET /v1/models | public | Model catalog: a single atomic-agent entry. |
POST /v1/messages | required | Anthropic Messages API (for Claude Code), streaming or sync. |
POST /v1/messages/count_tokens | required | Rough input token estimate for Anthropic clients. |
POST /v1/responses | required | OpenAI Responses API (for Codex and the Agents SDK), streaming or sync. |
| Method & path | Auth | Purpose |
|---|---|---|
GET /health | public | Liveness plus reachability of the local model server (localModels.url). Returns 200 with status: "degraded" when it is down; add ?strict=1 to get 503 instead, or ?llama=0 to skip the model-server probe. |
GET /api/capabilities | required | Runtime wiring summary. |
GET /api/config | required | Read the user config, with the file path and the sha256 of the file. |
PATCH /api/config | required | Merge the fields you send into the user config file, see below. |
PUT /api/config | required | Replace the whole file: { config, expectSha256? }. With expectSha256, it writes only while the file still has that hash, otherwise 409. |
GET /api/skills | required | List installed skills. |
GET /api/skills/{name} | required | Inspect one skill. |
POST /api/skills/install | required | Install a skill. |
POST /api/skills/uninstall | required | Uninstall a skill. |
GET /api/sessions | required | List sessions. |
GET /api/sessions/{id} | required | Fetch one session. |
DELETE /api/sessions/{id} | required | Delete a session. |
PATCH /api/sessions/{id} | required | Rename a session: { title }. |
POST /api/sessions/{id}/archived | required | Archive or unarchive a chat: { archived: true|false }. |
GET /api/sessions/{id}/export | required | One chat as Markdown, HTML or Word (?format=markdown|html|docx). |
POST /api/sessions/{id}/steer | required | Fold a message into the turn running on that session. See Steering a running turn. |
GET /api/sessions/{id}/steer | required | List steer messages the session’s turns accepted but never consumed. |
DELETE /api/sessions/{id}/steer | required | Acknowledge them (?through={seq} and/or ?discarded={n}). |
| Method & path | Auth | Purpose |
|---|---|---|
GET /api/events | required | SSE stream of pending approval requests. |
POST /api/approval/resolve | required | Resolve one pending approval. |
POST /api/question/answer | required | Answer a question the agent asked with ask_user. |
GET /api/approval-rules, DELETE /api/approval-rules/{id} | required | List or delete saved Allow always rules. |
POST /api/tasks | required | Create a task. |
GET /api/tasks | required | List tasks (?session=, ?status=, ?limit=). |
GET /api/tasks/{id} | required | Fetch one task. |
DELETE /api/tasks/{id} | required | Cancel a task. |
POST /api/tasks/{id}/run | required | Run one task now. |
POST /api/tasks/{id}/pause, /resume | required | Pause or resume a waiting task. |
GET /api/tasks/{id}/runs | required | The task’s past runs. |
POST /api/tasks/drain | required | Drain due tasks. |
GET /api/webhooks | required | Webhook bindings, and their public addresses while a tunnel is up. Never the secrets. |
POST /api/webhooks, DELETE /api/webhooks/{name} | required | Add or remove a binding without a restart. |
POST /api/webhooks/{name} | required | Webhook ingress, materialised as a task. |
The server has more routes for the desktop app and other clients: session search, rewind and fork, goals, compaction, Fusion workers, MCP servers and their sign-in, memory notes and profile facts, ideas, Telegram pairing, offline mode, the AG-UI protocol (POST /api/ag-ui) and a Prometheus scrape target (GET /metrics, which needs --api-key even on loopback). Run atomic-agent serve --help for the main list.
A first request
Start the server, then talk to it like any OpenAI endpoint:
atomic-agent serve --api-key "$MY_KEY"curl http://127.0.0.1:8787/v1/chat/completions \ -H "Authorization: Bearer $MY_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "atomic-agent", "messages": [ { "role": "user", "content": "List the TypeScript files in this directory." } ] }'Check liveness without a key at all:
curl http://127.0.0.1:8787/healthCustom headers
| Header | Direction | Purpose |
|---|---|---|
X-Atomic-Session-Id | request and response | Pin the request to a session; returned so you can continue the conversation. |
X-Atomic-Completion-Id | response | Returned on streaming and non-streaming completions; pass it to the cancel route. |
X-Atomic-Extensions | request | Opt into named SSE events (for example tool_progress) instead of the strict OpenAI subset. |
X-Webhook-Secret | request | Authenticates posts to /api/webhooks/{name}. |
Streaming: the two shapes of the SSE stream
POST /v1/chat/completions with "stream": true emits one of two different streams, depending on whether you opt in with X-Atomic-Extensions.
Accepted truthy values are 1, true, on, and yes (case-insensitive, whitespace trimmed). Anything else (the header being absent, or a value like 0 or false) leaves extensions off.
Off (the default): a strict OpenAI subset
Every frame is an unnamed data: line carrying a standard chat.completion.chunk, terminated by data: [DONE]. With stream_options: { include_usage: true } the stream ends with a usage chunk, as OpenAI’s does. This is deliberate: off-the-shelf clients like the Vercel AI SDK and the OpenAI Node SDK validate each frame against a strict schema, and a named event would break them.
Mid-stream failures also take the OpenAI shape here: an unnamed frame carrying { error: { message, type, param, code } }, with our failure category folded into type as agent.<category> so you can still branch on it.
On: extra events
With the header set you get the same content chunks plus these named events:
| Event | When | Payload |
|---|---|---|
session_id | Once, at stream start | { id, object, created, model, session_id }: the session this request landed on. |
tool_progress | Each parsed tool call | { …, session_id, tool, label }. label is the call’s arguments as JSON, cut to 120 characters. |
reasoning_progress | Each <think> chunk | { …, session_id, step_index, text }: incremental reasoning text. |
progress_note | A reply the model sent while still working | { …, session_id, step_index, text }. The turn continues after it. |
steer_undelivered | Once, at the end, if any steer message was never consumed | { …, session_id, undelivered: [...] }: every steer the turn accepted but did not read. See Steering a running turn. |
usage | Once, before the final chunk | { …, usage: { prompt_tokens, completion_tokens, total_tokens }, generation? }. generation carries completion_tokens and duration_ms of the streamed replies, for a reply speed. |
error | On a mid-stream failure | { error: "<message>", category?: "<failure category>" }. |
It also sends an unnamed data: frame { "object": "atomic.steer_applied", text, step_index } each time a steer message is folded into the turn.
The table lists the core events. The stream carries more named events for richer clients, such as tool_result, tool_update, plan_updated, turn_phase, provider_waiting, provider_switched and compaction progress. Ignore any event name you do not know.
curl -N http://127.0.0.1:8787/v1/chat/completions \ -H "Authorization: Bearer $MY_KEY" \ -H "X-Atomic-Extensions: 1" \ -H "Content-Type: application/json" \ -d '{ "model": "atomic-agent", "stream": true, "messages": [{ "role": "user", "content": "List the TypeScript files here." }] }'Capabilities
GET /api/capabilities is the one call an admin UI or status dashboard should make on connect. It returns the resolved runtime wiring (paths, backend URLs, the live approval level, the accepted approval decisions, and the full tool and skill catalogs), so a client can decide what to render without probing the agent loop.
curl http://127.0.0.1:8787/api/capabilities -H "Authorization: Bearer $MY_KEY"{ "runtime": "atomic-agent", "capabilities": { "…": "runtime feature flags" }, "paths": { "stateDir": "/Users/you/.atomic-agent", "globalSkillsDir": "/Users/you/.atomic-agent/skills", "projectSkillsDirName": ".atomic-agent/skills", "sessionsDbFile": "/Users/you/.atomic-agent/sessions.sqlite", "grammarsDir": "/Users/you/.atomic-agent/grammars", "userConfigFile": "/Users/you/.atomic-agent/config.json" }, "llama": { "url": "http://127.0.0.1:9931", "healthPath": "/health", "completionPath": "/completion" }, "browser": { "channel": "chrome", "headless": false, "cdpUrl": null }, "agent": { "tokenBudget": 3000, "maxSteps": 25, "approvalLevel": 3, "approvalRequired": true, "approvalDecisions": ["allow-once", "allow-in-chat", "allow-always", "deny"], "questions": true }, "tools": [ { "name": "fs.read", "description": "Read a file", "readonly": true } ], "skills": [ { "name": "pdf", "description": "Work with PDF files", "source": "global" } ], "skillsOmitted": 0}The browser block reports the browser settings the runtime resolved from the browser block of config.json and the ATOMIC_AGENT_BROWSER_* environment variables (an env variable, when set, wins). agent.maxSteps is the leg length. agent.approvalDecisions lists the decisions POST /api/approval/resolve accepts, so a client offers a button only where it works. The response also carries a reasoning block for the active model. skillsOmitted counts installed skills that skills.catalogTokenBudget left out of the skills array; it is always present, 0 when nothing was dropped.
agent.approvalLevel is the live gate state, not the boot-time config snapshot. It reflects --no-approval boots and any later level change, so it is always the truth.
Integrator caveats
Four things that are not defects but will surprise you if you meet them at integration time rather than reading them here.
No CORS, no OPTIONS
The server sets no permissive Access-Control-* headers and registers no OPTIONS route. A browser app served from any other origin will fail its preflight and never reach the API. This is not something a header on your side can fix. Without an API key, a request from a foreign origin is refused with 403 before routing, unless you list that origin in ATOMIC_AGENT_ALLOWED_ORIGINS.
Front the server with a reverse proxy that adds CORS, or call it from your own backend. The design assumption is a local or server-side client.
/api/events sends a keepalive every 15 seconds
The approval SSE stream writes a : keepalive comment line every 15 seconds while it is open, so most proxies keep the connection. A proxy with an idle timeout shorter than that still closes it, and gated tool calls then have nobody to ask. Clients should reconnect on drop; pending requests are replayed to a new subscriber, so a reconnect does not lose a waiting turn.
Derived session ids are content-addressed
If a request carries no explicit session_id (in the body) or X-Atomic-Session-Id (as a header), the server derives one by hashing the system prompt plus the first user message: api-<sha256[:16]>.
That is deliberate: the same client resending the same opening prompt re-hits the same session and reuses its KV-cache slot. But it also means two unrelated clients that send an identical system prompt and identical first user message land in the same session, sharing transcript and memory. With a fixed system prompt and a common opener (“hi”), collisions are not hypothetical.
If your clients are independent, pass an explicit session id. Do not rely on derivation for isolation.
PATCH /api/config merges into the file
PATCH /api/config merges the JSON body into the config file on disk. Objects merge key by key. Arrays and plain values (strings, numbers, booleans, null) replace what the file had. Every key you leave out keeps its value, so your LLM providers, MCP servers, skills settings and an analytics opt-out stay as they are. To change one setting, send only that key:
curl -X PATCH http://127.0.0.1:8787/api/config \ -H "Authorization: Bearer $MY_KEY" \ -H "Content-Type: application/json" \ -d '{ "log": { "level": "debug" } }'The merged file is validated before anything is written. An invalid value returns 400 and the file stays unchanged. A version key in the body is ignored, because the version belongs to the file. The response carries the file path and the full config that was written.
Because arrays replace, sending mcp.servers or llm.providers replaces the whole list: send the complete list you want to keep. Agent turns that are already running keep the config they started with, and MCP servers reconnect only after a restart.
Approvals over HTTP
The server has no terminal to prompt on, so approvals travel over the wire instead. serve wires the runtime’s onApprovalRequest callback into an approval bus:
- A gated tool call publishes an approval request to the bus.
- Connected clients receive it on the
GET /api/eventsSSE stream. Pending requests are replayed when a client connects, so a late subscriber does not miss a turn that is already waiting. - The client answers with
POST /api/approval/resolve.
On the SSE stream each request arrives as an approval_request event. The resolve body carries its id and a decision:
curl -X POST http://127.0.0.1:8787/api/approval/resolve \ -H "Authorization: Bearer $MY_KEY" \ -H "Content-Type: application/json" \ -d '{ "approvalId": "…", "decision": "allow-once", "reason": "looks fine" }'reason is optional. decision is one of:
| Decision | Effect |
|---|---|
allow-once (or approve) | Allow this one call. |
allow-in-chat | Allow it, and let later shell calls of the same program run unasked in this chat only. A request without a command shape gets 400 and stays pending. |
allow-always | Allow it and save an Allow always rule for this project. Only works when the request’s canAlways is true; the event then also carries alwaysLabel, for example Always allow "git status" in this project. |
deny (or reject) | Refuse. |
A success returns { "resolved": true, approvalId, approved }, plus grant: "chat" or grant: "always" and the saved rule. An unknown or already-answered approvalId returns 404, and a missing id or bad decision returns 400.
A question the agent asks with ask_user arrives on the same stream as an approval_request with category: "user_question". Answer it with POST /api/question/answer, not with the resolve route.
If nothing is listening on /api/events, gated calls have nobody to ask. Either keep a client subscribed or run the server at an approval level where the work you are sending does not stop.
Steering a running turn
A steer message is text you add to a turn that is already running, without starting a new request. The agent reads it at the next step boundary.
curl -X POST http://127.0.0.1:8787/api/sessions/s-1234/steer \ -H "Authorization: Bearer $MY_KEY" \ -H "Content-Type: application/json" \ -d '{ "text": "Skip the tests folder." }'| Status | Meaning |
|---|---|
200 { steered: true, sessionId } | Accepted. Not yet delivered: the turn reads it at its next step. |
400 | Missing session id, or text is not a non-empty string. |
409 | No turn on that session is accepting steers. Send the message as a normal POST /v1/chat/completions instead. |
429 | The session’s steering inbox is full; the running turn has not read the pending messages yet. |
A turn can end before it reads a steer (for example, when the message arrives during the final step). Such messages are parked, not dropped:
- A non-streaming completion lists them in an
undelivered_steersarray in its response body. A streaming one with extensions on sends thesteer_undeliveredevent. GET /api/sessions/{id}/steerreturns{ sessionId, undelivered: [{ seq, text, parkedAt }], discarded }. Reading does not consume them.DELETE /api/sessions/{id}/steer?through={seq}acknowledges everything up to and includingseq.discardedcounts messages lost because the per-session parking cap overflowed; acknowledge that separately with?discarded={n}.
Creating tasks
POST /api/tasks takes a JSON body:
{ "sessionId": "s-1234", "userMessage": "Summarise today's changed files", "maxAttempts": 3, "maxSteps": 10, "maxCostUsd": 5, "maxDurationMs": 28800000, "notify": "telegram"}userMessage is a required string. Pass either sessionId or workingDir (an absolute path to an existing folder, which opens a new session there), not both; without either the route returns 400. maxAttempts falls back to ATOMIC_AGENT_TASKS_MAX_ATTEMPTS (default 3); maxSteps is optional. maxCostUsd and maxDurationMs are the task’s own budget; omitted or null leaves the agent.task.* ceiling in charge. notify is telegram or push. Fields the route does not know are ignored. A successful create returns 201 with the persisted row.
If the task subsystem is off (ATOMIC_AGENT_TASKS_ENABLED=0), every /api/tasks route returns 404 with tasks subsystem disabled.
Webhooks
A webhook lets an external system (a GitHub hook, a CI job, a cron-like SaaS) trigger an agent turn over HTTP without writing any code. You declare bindings in the webhooks block of config.json, and each one is mounted at POST /api/webhooks/<name>.
{ "webhooks": { "github-issues": { "userMessageTemplate": "Triage this issue: {{body.issue.title}}\n\n{{body.issue.body}}", "secret": "a-long-random-string", "sessionMode": "ephemeral" } }}The name is the URL path segment and must match [a-zA-Z0-9_-]+. Anything else fails config validation at startup. The default is webhooks: {}: no bindings, so no ingress. You can also add and remove bindings over HTTP with POST /api/webhooks and DELETE /api/webhooks/{name}; the running agent picks them up without a restart, and the create response is the only time the secret is returned.
Binding fields
| Field | Type | Default | What it does |
|---|---|---|---|
userMessageTemplate | string | required | The user message the task is created with. Supports {{body.<json.path>}} placeholders. |
secret | string | none | Checked as verify says. With the default verify, the request must carry a matching X-Webhook-Secret header. |
verify | secret | github | standard-webhooks | stripe | secret | How secret is checked. github checks X-Hub-Signature-256, standard-webhooks (Composio, Svix) checks webhook-signature with a whsec_ secret, stripe checks Stripe-Signature. The signed schemes need secret. |
events | string array | none | Signed schemes only: which events start a task, for example ["pull_request.opened", "issues"]. Other events answer 200 and start nothing. |
sessionMode | ephemeral | persistent | named | ephemeral | How sessions carry across repeated hits. |
sessionId | string | none | The session to use. Required when sessionMode is named. |
schedule | object | none | Optional schedule applied to the created task: { "kind": "at", "at": <epoch ms> }, { "kind": "interval", "everyMs": <ms> }, or { "kind": "cron", "expression": "<cron>", "tz": "<IANA>" } (tz optional). |
Templating the message
userMessageTemplate is rendered against the parsed JSON request body. Placeholders take the form {{body.<path>}} and walk the body by dot-separated keys:
{{body.issue.title}} → body.issue.title{{body.repository.name}} → body.repository.nameOnly paths rooted at body resolve, plus {{event}}, {{action}} and {{delivery}}, which the signed schemes fill from the request. Anything else, and any path that does not exist in the payload, substitutes to an empty string rather than failing the request. Strings, numbers, and booleans interpolate directly; objects and arrays are JSON-stringified. To emit a literal {{, escape it with a backslash: \{{not a placeholder}}.
The templater is deliberately narrow. There is no expression language, no conditionals, and no function calls.
Session modes
| Mode | Behaviour |
|---|---|
ephemeral | No session id is passed. The task runner creates one per hit. Matches CLI one-shot behaviour. |
persistent | The first hit creates a session and records it in <stateDir>/webhook-sessions.json, keyed by webhook name. Every later hit, including after a process restart, reuses it. |
named | Uses the sessionId you configured, verbatim. Nothing is created and nothing is persisted. |
Use persistent when the caller is a recurring feed that should accumulate context, and ephemeral when each hit is independent.
Authentication
The webhook route is an authenticated route like any other, so the bearer token still applies when the server has one. secret is an additional check, not a replacement:
curl -X POST http://127.0.0.1:8787/api/webhooks/github-issues \ -H "Authorization: Bearer $MY_KEY" \ -H "X-Webhook-Secret: a-long-random-string" \ -H "Content-Type: application/json" \ -d '{ "issue": { "title": "Crash on startup", "body": "Steps to reproduce…" } }'If the binding declares no secret, the header is not checked at all.
From the internet: --tunnel
atomic-agent serve --tunnel runs cloudflared from your PATH (it is never downloaded) and gives the webhooks a public https://….trycloudflare.com address. --tunnel-name and --tunnel-hostname use your own named tunnel instead. The tunnel reaches a second listener that holds only POST /api/webhooks/{name}, with no bearer key: every other path answers 404 there, and a binding without a secret answers 403. Signed bindings get replay protection on that listener: a delivery id already turned into a task answers 200 { "taskId": null, "duplicate": true }. serve refuses --tunnel when cloudflared is missing, tasks are off, or no binding has a secret. GET /api/webhooks shows the public address of each binding while the tunnel is up.
Responses
| Status | When |
|---|---|
202 | Accepted. Body is { "taskId": "...", "sessionId": "..." }. |
400 | Missing webhook name, unparseable JSON body, or a schedule the task runner rejects. |
200 | A genuine hit that starts no task: a repeated delivery, GitHub’s ping, or an event the binding’s events leaves out. Body is { "taskId": null, ... }. |
401 | The binding declares a secret and the header or signature is missing or wrong. |
404 | Unknown webhook name, or the task subsystem is disabled. |
Related
Get updates by email
One email when a new version comes out.