opencode-api
Skill0 starsChanged 6 days agoMITView on GitHub
Use when calling or scripting the opencode server's HTTP API - sessions, prompts, messages, the event stream, PTYs and shells, files, MCP, config, permissions, worktrees, integrations - with curl, opencode api or another HTTP client, when reading the server's OpenAPI spec, or when unsure whether an opencode endpoint is v1 (/session, /event, /global/...) or v2 (/api/...).
2 other projects use a version of this.
Adopted by
Most recently taken up by
- dzianisv/skillstheir own version, first seen Aug 18, 2026
- pepebot-space/skillstheir own version, first seen Feb 16, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- dzianisv/skills★ 4same name
- pepebot-space/skills★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository10 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- capturing-tk-screenshots-headlessSkill
- concept-parableSkill
- opencode-buildSkill
- opencode-cliSkill
- provider-onboardingSkill
- pygameturboSkill
- thonny-pluginSkill
- timestampSkill
The file
Files
opencode server API (v2)
Overview
opencode v2 moved every server route under /api/ (POST /api/session,
GET /api/event, GET /api/info), so the v1 routes you remember (/session,
/event, /global/health, /doc) are probably wrong. Do not write opencode
API calls from memory. Look each one up in the cached OpenAPI spec,
references/openapi.json (~880 KB, 170 operations): search it with the script
instead of reading it.
python scripts/api_lookup.py --tags # areas and operation counts
python scripts/api_lookup.py --list session # operations in a tag (or matching text)
python scripts/api_lookup.py --op session.prompt # params (with style), body, responses, opencode api + curl lines
python scripts/api_lookup.py --op POST /api/session # same, by method and path
python scripts/api_lookup.py --schema Session # one schema
python scripts/api_lookup.py --grep "fork session" # words in ids, paths, summariesPaths are relative to this skill's folder. --depth N limits how far $refs
expand (default 3; use 1 for large bodies). When the spec and ERRATA.md
disagree, ERRATA.md wins.
Calling the server
- Easiest:
opencode api <operationId>(oropencode api GET /api/...) talks to the running server with its connection and password already set:opencode api session.list --param limit=10,opencode api session.create --data '{"title": "x"}'.--opprints this form for each operation, and acurlline to adapt for other clients. - Other clients: HTTP Basic auth, user
opencode, the server password (OPENCODE_PASSWORD, or set it withopencode service set password):curl -u opencode:$OPENCODE_PASSWORD http://127.0.0.1:<port>/api/info.opencode service statusprints the address. Never print or log the password. Details: https://opencode.ai/docs/cli/web (Markdown: same URL +.md). GET /api/info(server.info) returns the version, URLs and paths: a cheap first call to check the connection.- The running server does not serve its own spec (no route for it; v1's
/docis gone, checked 2026-11-08). The published copy is https://opencode.ai/docs/openapi.json, cached here. - Events:
GET /api/event(event.subscribe) is atext/event-stream; filter with thetypesquery parameter. It is volatile: a slow reader is dropped, and events during a disconnect are lost. - Location (72 of 170 operations take it): the query parameter
locationis an object (style: deepObject;--opflags it and prints the URL form):?location[directory]=<url-encoded dir>(curl -g, or encode the brackets as%5B/%5D). On those operations a plain?directory=is ignored (the server's default location answers; a few others, likesession.list, have a realdirectoryfilter of their own), and?location=<dir>→ 400InvalidRequestError"Expected object at ["location"]".opencode apifills it in for the current directory. Checked 2026-11-10 against opencode 2.2.6. - Plugin RPC:
POST /api/rpc/{rpcID}/{method}(rpc.call) wraps the argument: body{"input": <value>}→{"output": <value>}.rpcIDis the id in the plugin'sRpc.define. A bare argument as the body →rpc.invalid_input"Expected object". - Throwaway server (tests, sandboxes):
opencode serve --hostname 127.0.0.1 --port <n> --print-logsprintsserver password <value>at startup; pointXDG_CONFIG_HOME,XDG_DATA_HOME,XDG_CACHE_HOMEandXDG_STATE_HOMEat a temp folder to keep it off your real setup. A location's plugins load in the background after its first request, so plugin-provided agents, skills, references and MCP servers appear a few seconds later.
Keeping it current
references/openapi.jsonis a verbatim copy; never edit it. Refresh withpython scripts/refresh_references.py(--checkreports staleness without writing). The docs page https://opencode.ai/docs/api/ is generated from the same file.- Found a mistake (the spec contradicts the running server)? Add an entry to
ERRATA.mdwith the request, the response and the date.
Common mistakes
| Mistake | Fix |
v1 routes (/session/{id}/message, /event, /global/health) | Look up the v2 operation: --grep, then --op |
Reading openapi.json directly | api_lookup.py; the file is far too large for context |
| curl without auth | -u opencode:<password>, or use opencode api |
| Guessing a request body | --op <id> shows the schema; --schema <Name> for nested types |
?directory=<dir> or ?location=<dir> | ?location[directory]=<dir> (deep-object query) |
| RPC call with the bare argument as body | {"input": <value>} |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

