man oscar The manual Integrations

API server and editors

The OpenAI-compatible API server, editors over ACP (Zed), their security.

MANUAL / INTEGRATIONS 24 / 29

Two ways for other programs to use Oscar, with its tools, sessions and approvals:

  • oscar api serve: an OpenAI-compatible HTTP API. Chat front ends, scripts and libraries that speak the OpenAI API talk to Oscar instead of a bare model.
  • oscar acp: the Agent Client Protocol over stdio, for editors such as Zed. The editor starts Oscar and shows its replies, tool calls and approval questions.

Both run the same agent as oscar chat: the same workspace rules, sandbox mode, approval policy, redaction and audit logs.

Security first

Whoever can use the API, or the editor connection, can make Oscar run tools on this machine as you: shell commands, file edits, web requests, within your sandbox mode and approval mode. Treat the API key like an SSH key.

  • The API listens on 127.0.0.1:8642 by default: only programs on this machine can reach it.
  • It has a key from its first start. With no OSCAR_API_SERVER_KEY set, oscar api serve makes one, saves it to $OSCAR_HOME/credentials.env (mode 600) and shows it once — on a terminal; when its output goes to a log it says where the key is instead of printing it. Or set your own (credentials.env or the environment):
    text
    OSCAR_API_SERVER_KEY=<a long random string>
    Clients send it as Authorization: Bearer <key>. It is compared in constant time and never logged.
  • --no-key serves on loopback without one (refused while a key is set). Risky: any program on this machine can then make Oscar run tools, and runs follow the unattended policy (see below).
  • Web pages are refused. A page in your browser can send requests to a local server, and one whose name was made to point at 127.0.0.1 (DNS rebinding) could read the replies. So on a loopback address the Host header must be 127.0.0.1, localhost or [::1] (with the port) — a reverse proxy on this machine must pass one of those — any request with an Origin (or Referer) from another site is refused (403), and a request body must be sent as Content-Type: application/json (415 otherwise; a request without a body may leave the type out). Ordinary API clients do all of this already.
  • Listening on any other address (--listen 0.0.0.0:8642) is refused unless the key is set (at least 16 characters) and you pass --public; no key is made for it. Put a TLS proxy in front: the server speaks plain HTTP.
  • Replies are redacted like everything else Oscar shows (known keys and key shapes), whole and streamed: a key the model's stream splits across pieces is held back until it can be masked whole.
  • Nobody is there to approve a chat-completions or responses request, so the unattended policy (unattended_approve) decides alone (see below). With auto, everything that is not dangerous runs, with a line in $OSCAR_HOME/audit/approvals.jsonl.
  • Runs (/v1/runs) can ask their caller instead, and only on a server with a key: the key proves the caller is you, so an approval sent over the API counts as your answer, dangerous commands included. Without a key any local program could answer, so runs then follow the unattended policy like every other request, and nothing waits for an answer. Keep the key secret: whoever holds it can approve.
  • Prefer the workspace sandbox (sandbox = "workspace") for a server others use: commands then see only the workspace and have no network.
  • The chat gateways' user allow-lists do not apply to the API: the key is the only gate in front of it. Your before_tool hooks do apply and can refuse calls (hooks).

The API server

shell
oscar api serve                          # http://127.0.0.1:8642/v1 (makes a key the first time)
oscar api serve --no-key                 # loopback without a key: any local program can use it
oscar api serve --listen 127.0.0.1:9000 --max-concurrent 2
oscar api serve --answer-timeout 300     # how long a run waits for your answer
oscar api serve --listen 0.0.0.0:8642 --public   # needs OSCAR_API_SERVER_KEY
Endpoint What it does
GET /health {"status":"ok"}, no key needed
GET /v1/models the configured model, then your model aliases
POST /v1/chat/completions a turn; "stream": true for server-sent events
POST /v1/responses the same in the Responses API shape; streams too
POST /v1/runs a turn in the background; answers 202 with its run_id
GET /v1/runs, GET /v1/runs/{id} recent runs; one run's state, output, usage and what it waits for
GET /v1/runs/{id}/events the run's events as server-sent events
POST /v1/runs/{id}/approve, /deny answer the approval the run waits for (keyed server only)
POST /v1/runs/{id}/clarify answer the question the run asked
POST /v1/runs/{id}/stop stop the run
GET /v1/sessions, GET /v1/sessions/{id} stored sessions, newest first; one session
GET /v1/sessions/{id}/messages a session's messages, redacted
DELETE /v1/sessions/{id} delete a session the API started (api-…)

Point a client at http://127.0.0.1:8642/v1 with the key as its API key.

Models. The model field may be empty, oscar or the configured model's id (the served model), or any other model /model accepts: a model of the configured provider, provider:model, a custom provider's <name>:<model>, or an alias from [model_aliases]. The keys come from your configuration, never from the request; a model that cannot be built (no key, unknown provider) is refused with the reason. Replies show the model that answered.

What a reply contains. Oscar runs its own tools during the turn; the client gets the reply text, never Oscar's tool calls. In a stream, tool activity shows as SSE comment lines (: tool bash running, : tool bash done), which clients ignore; only the tool's name is shown, never its arguments. Text from before and after a tool call is separated by a blank line. The client's own tools, tool messages and function calls are ignored. Non-streamed replies also carry an oscar object with the session id and the files tools produced (e.g. generated images: paths on this machine).

Sessions.

  • Every reply has an X-Oscar-Session header (and oscar.session).
  • Send X-Oscar-Session: <id> to continue that session: Oscar uses its stored history and only the last user message of the request. Any Oscar session works, including ones from oscar chat (oscar sessions lists them). An unknown id gets 404.
  • Without the header, a new session starts from the request's messages (system and developer messages become instructions for this turn; earlier user and assistant messages become the history and are stored).
  • /v1/responses (and /v1/runs) also accept previous_response_id: the response ids (and run ids) are kept in the session store with their session, so they work after a restart; deleting the session forgets them. The newest 5000 are kept.

Images in user messages are taken as data: URLs (image/png, image/jpeg, image/webp, image/gif; at most 8 per request). Remote image URLs are refused: the server does not fetch what a client names.

Approvals with nobody to ask (chat completions, responses, and runs on a server without a key). unattended_approve decides (unset: never, or auto when approve = "auto"; see approvals and sandbox):

unattended_approve ask-tier calls (writes, most commands) dangerous (confirm-tier) refused tier
auto run, with an audit line refused refused
smart run when the reviewer model approves them, else refused refused refused
never (default) refused ("no one to ask") refused refused

Allow and deny rules apply first, as everywhere. The model is told why a call was refused and can say so. Outside runs, clarify answers that nobody can be asked; browser_vault cannot save new logins anywhere in the API.

Limits. Request bodies up to 8 MiB (413 beyond), 64 open connections, 30 seconds to send the request headers, --max-concurrent turns at once (default 4; more get 429), one turn per session at a time (409). A client that closes a stream stops its turn (a keep-alive comment every 15 seconds notices quiet disconnects).

Runs

A run is a turn the server works on in the background. The client starts it, then reads its events, polls its state, answers what it waits for, or stops it:

shell
curl -s http://127.0.0.1:8642/v1/runs -H "Authorization: Bearer $KEY" \
  -d '{"input": "tidy the README", "session_id": "api-1234"}'
# {"run_id": "run_…", "status": "started", "session_id": "api-…", "approvals": "api", …}
curl -sN http://127.0.0.1:8642/v1/runs/run_…/events -H "Authorization: Bearer $KEY"

Starting a run. POST /v1/runs takes input (a string, or Responses API items), and optionally instructions, conversation_history (earlier messages, for a new session), session_id (or the X-Oscar-Session header) to continue a session, previous_response_id (a response or run id), model, and approvals: "api" (the default on a keyed server: the run asks you) or "unattended" (the unattended policy decides, as for chat completions). The limits are the server's: --max-concurrent runs and turns at once (429 beyond), one turn per session at a time (409).

Events (GET /v1/runs/{id}/events) come as server-sent events, each with an id: (its number, from 0), an event: name and JSON data. The stream starts from the first event (or after the one named in Last-Event-ID or ?after=N, to resume), follows the run, and ends after its last event:

Event Data
run.started session_id, model, approvals
message.delta text: the reply as it is written
tool.started tool, preview: the call's arguments, cut to 300 characters
tool.completed tool, ok
tool.output tool, ok, preview: what it returned, cut to 500 characters
tool.refused tool, code: refused by policy or an approval
approval.request request_id, tool, reason, detail, dangerous, offer_session
approval.resolved request_id, decision (allow, allow_session, deny), by (api, timeout, run)
clarify.request request_id, questions (question, choices, multi_select)
clarify.resolved request_id, by
file, notice, context.compressed, turn.budget a file a tool made, a provider notice, compression, the turn budget
run.completed output, usage, attachments, session_id
run.failed error
run.cancelled the run was stopped

Every text in an event, and in the run's state, is redacted (known secrets and token shapes); tool payloads are previews only, and the model's private reasoning is never sent. A comment line (: keepalive) goes out every 15 seconds of quiet.

The run's state (GET /v1/runs/{id}): status is running, waiting_for_approval, waiting_for_input, stopping, then completed, failed or cancelled; pending lists what it waits for (as in the request events); a finished run has output, usage (input_tokens, output_tokens, cache_read_tokens, cache_write_tokens) or error. Runs live in the server's memory: a finished run is kept for an hour (at most 256 runs), and a restart forgets runs (the sessions stay, and run ids still continue them).

Approvals over the API. On a keyed server, what the approve mode leaves to a person is asked of the run's caller, like an editor asks its user: in ask mode every call that needs approval, in auto mode only dangerous commands, in smart mode what the reviewer model leaves to a person, in never mode nothing (it is refused). Allow and deny rules apply first, as everywhere, and your answer goes through the same gate: it is written to audit/approvals.jsonl, and the hooks see it.

  • POST /v1/runs/{id}/approve with {"request_id": "apr-1"} (or {} when only one approval waits); "scope": "session" allows the same again for the rest of the session when the request says offer_session (never for dangerous commands).
  • POST /v1/runs/{id}/deny, optionally with "reason": the model is told.
  • An answer resolves only an item this run is waiting for; anything else (another run's id, an item already answered, a question) is refused (409).
  • Nobody answers within --answer-timeout (default 600 seconds): the call is refused.

Without a key, runs never wait for an approval: the unattended policy decides, and approve/deny say so (409).

Questions. clarify questions wait for POST /v1/runs/{id}/clarify with {"answers": ["2", "a free answer"]} (one per question; a number picks a choice) or {"answer": "…"} for one question. Unanswered within the timeout, the model decides itself and says what it assumed. Questions can be answered on a server without a key too: an answer is text for the model, like the input.

Stopping. POST /v1/runs/{id}/stop stops the turn (like a client leaving a stream): the status turns stopping, then cancelled, and what waited is refused.

Sessions over REST

  • GET /v1/sessions: newest first, active ones; limit (default 50, at most 500), search (words in the title, the id or the messages), origin (api, terminal, telegram, imported, …), archived=true to include archived ones. Each has its id, title, times, model, message count, origin and the start of its first message (redacted).
  • GET /v1/sessions/{id}/messages: limit (default 200, at most 1000) and offset; each message has its role and text (redacted), tool calls with their arguments cut to 2000 characters, and the number of images.
  • DELETE /v1/sessions/{id}: only sessions the API started (api-…), not while a turn runs in them (409), and not when something refers to them (a pin, a scheduled job, a kanban card: 409). Sessions of the terminal, a chat or an editor are deleted with oscar sessions delete.

Hooks ([[hooks]]) run for API turns like for any other: session_start when a new session begins, turn_start/turn_end, and the tool hooks. API sessions are never closed, so session_end does not run for them.

Editors (ACP)

oscar acp speaks the Agent Client Protocol on stdin/stdout: the editor starts it and talks to it. Standard output carries only protocol messages; logs go to standard error (the editor's log).

Zed

In Zed's settings.json:

json
{
  "agent_servers": {
    "Oscar": {
      "type": "custom",
      "command": "oscar",
      "args": ["acp"],
      "env": {}
    }
  }
}

Older Zed versions take the same entry without "type". Use the full path (e.g. /home/you/.local/bin/oscar) if Zed does not find it. Then open the agent panel and start an Oscar thread. Oscar uses the provider, model, approve mode and sandbox from your config.toml; to change them for the editor only, put flags in args (["--approve", "auto", "acp"]) or variables in env (OSCAR_SANDBOX, OSCAR_MODEL, OSCAR_HOME). Keys stay in credentials.env; do not put them in the editor's settings.

Other ACP clients

Any client that starts an agent command over stdio works the same way: command oscar, argument acp.

What the editor sees

  • The workspace is the project folder the editor names for the session, checked exactly like --workspace: in the workspace sandbox a folder that is or contains your home directory is refused (unless --allow-home-workspace names it), and a folder inside $OSCAR_HOME is always refused. The folder the editor started oscar acp in does not matter.
  • Replies stream in as message chunks. Each tool call is an item with a kind (read, edit, execute, search, fetch, ...) and a status: pending while it waits for approval, in progress, then completed or failed. Calls refused by policy appear as failed items.
  • Approvals follow the approve mode, and what the mode leaves to a human is asked in the editor: Allow once, Allow for this session (not offered for dangerous commands) or Deny. In auto mode only dangerous commands are asked; in smart mode the reviewer model decides routine ones first; in never mode nothing is asked and everything that needs approval is refused. Allow and deny rules apply before any of that. An editor that cannot answer (an error, no answer in 10 minutes) gets the call refused.
  • Cancel stops the turn at once; open tool items are marked failed and a permission question still open is dropped. The next prompt continues from the stored transcript.
  • The mode picker is the session's approval mode: Ask (the default, or your configured approve), Smart, Auto (dangerous commands still ask) and Read only (never: everything that needs approval is refused). A change holds from the next approval on, also during a running prompt. It lasts for the session only.
  • The model picker lists the current model, your aliases, the provider's models from the cached model list (oscar model list fills it; the editor never makes Oscar fetch it), custom providers' models and the fallback chain. Any model /model accepts can be chosen; it holds from the next prompt on, for this session.
  • The editor's MCP servers (mcpServers in session/new and session/load: local commands, or remote servers over HTTP; SSE servers are not supported) join the session as editor-<name>, untrusted: their tools that do not say they only read always ask in the editor, whatever the mode, and their calls go through the approval gate like any MCP tool. Values the editor passes (environment, headers) are treated as secrets and redacted from what Oscar shows. A server whose settings refer to ${…} variables is left out (it would read Oscar's own keys), and acp_mcp = "off" leaves all of them out. Local servers run in the session's folder, outside the sandbox, like the servers of mcp.json.
  • Prompts may include text, images, files the editor attaches (their text is given to the model) and file links (named, not read: the model reads them with its tools if it needs to).
  • Sessions are stored like any other (acp-... ids). The editor can load an earlier session (Oscar replays it), including sessions from oscar chat.
  • Closing the editor (or the session) runs the session_end hooks and stops background processes the session started.

Gaps

  • The editor's own file system and terminal are not used: Oscar reads and writes files on disk with its own tools, so unsaved editor buffers are not seen, and commands run in Oscar's shell (subject to its sandbox), not in an editor terminal.
  • No slash commands from the editor, and tool items show status, not their output.
  • clarify questions cannot be asked over ACP: the model is told to decide and say what it assumed.