Skip to content

Server

Komunicirajte s opencode serverom preko HTTP-a.

Komanda opencode serve pokrece headless HTTP server koji izlaže OpenAPI endpoint koji opencode klijent moze koristiti.


Usage

Terminal window
opencode serve [--port <number>] [--hostname <string>] [--cors <origin>]

Options

ZastavaOpisDefault
--portPort na kojem slusa4096
--hostnameHostname na kojem slusa127.0.0.1
--mdnsUkljuci mDNS otkrivanjefalse
--mdns-domainPrilagodeni domen za mDNS servisopencode.local
--corsDodatni browser origin-i koje dozv.[]

--cors mozete navesti vise puta:

Terminal window
opencode serve --cors http://localhost:5173 --cors https://app.example.com

Authentication

Postavite OPENCODE_SERVER_PASSWORD da zastitite server HTTP basic auth mehanizmom. Korisnicko ime je po defaultu opencode, ili postavite OPENCODE_SERVER_USERNAME za nadjacavanje. Ovo vazi i za opencode serve i za opencode web.

Terminal window
OPENCODE_SERVER_PASSWORD=your-password opencode serve

How it works

Kada pokrenete opencode, pokrecu se TUI i server. TUI je klijent koji komunicira sa serverom. Server izlaže OpenAPI 3.1 spec endpoint koji se koristi i za generisanje SDK-a.

Ova arhitektura omogucava opencode podrsku za vise klijenata i programsku interakciju.

Mozete pokrenuti opencode serve da startate standalone server. Ako je opencode TUI vec pokrenut, opencode serve ce pokrenuti novi server.


Connect to an existing server

Kada pokrenete TUI, port i hostname se nasumicno dodijele. Umjesto toga, mozete zadati --hostname i --port zastave, pa se povezati na taj server.

Endpoint /tui mozete koristiti za upravljanje TUI-jem kroz server. Na primjer, mozete unaprijed popuniti ili pokrenuti prompt. Ovaj setup koriste OpenCode IDE pluginovi.


Spec

Server objavljuje OpenAPI 3.1 specifikaciju koju mozete vidjeti na:

http://<hostname>:<port>/doc

Na primjer, http://localhost:4096/doc. Koristite specifikaciju da generisete klijente ili pregledate tipove zahtjeva i odgovora. Mozete je otvoriti i u Swagger exploreru.


APIs

opencode server izlaže sljedece API-je.


Global

MetodaPutanjaOpisOdgovor
GET/global/healthGet server health and version{ healthy: true, version: string }
GET/global/eventGet global events (SSE stream)Event stream

Project

MetodaPutanjaOpisOdgovor
GET/projectList all projectsProject[]
GET/project/currentGet the current projectProject

Path & VCS

MetodaPutanjaOpisOdgovor
GET/pathGet the current pathPath
GET/vcsGet VCS info for the current projectVcsInfo

Instance

MetodaPutanjaOpisOdgovor
POST/instance/disposeDispose the current instanceboolean

Config

MetodaPutanjaOpisOdgovor
GET/configGet config infoConfig
PATCH/configUpdate configConfig
GET/config/providersList providers and default models{ providers: Provider[], default: { [key: string]: string } }

Provider

MetodaPutanjaOpisOdgovor
GET/providerList all providers{ all: Provider[], default: {...}, connected: string[] }
GET/provider/authGet provider authentication methods{ [providerID: string]: ProviderAuthMethod[] }
POST/provider/{id}/oauth/authorizeAuthorize a provider using OAuthProviderAuthAuthorization
POST/provider/{id}/oauth/callbackHandle OAuth callback for a providerboolean

Sessions

MetodaPutanjaOpisNapomene
GET/sessionList all sessionsReturns Session[]
POST/sessionCreate a new sessionbody: { parentID?, title? }, returns Session
GET/session/statusGet session status for all sessionsReturns { [sessionID: string]: SessionStatus }
GET/session/:idGet session detailsReturns Session
DELETE/session/:idDelete a session and all its dataReturns boolean
PATCH/session/:idUpdate session propertiesbody: { title? }, returns Session
GET/session/:id/childrenGet a session’s child sessionsReturns Session[]
GET/session/:id/todoGet the todo list for a sessionReturns Todo[]
POST/session/:id/initAnalyze app and create AGENTS.mdbody: { messageID, providerID, modelID }, returns boolean
POST/session/:id/forkFork an existing session at a messagebody: { messageID? }, returns Session
POST/session/:id/abortAbort a running sessionReturns boolean
POST/session/:id/shareShare a sessionReturns Session
DELETE/session/:id/shareUnshare a sessionReturns Session
GET/session/:id/diffGet the diff for this sessionquery: messageID?, returns FileDiff[]
POST/session/:id/summarizeSummarize the sessionbody: { providerID, modelID }, returns boolean
POST/session/:id/revertRevert a messagebody: { messageID, partID? }, returns boolean
POST/session/:id/unrevertRestore all reverted messagesReturns boolean
POST/session/:id/permissions/:permissionIDRespond to a permission requestbody: { response, remember? }, returns boolean

Messages

MetodaPutanjaOpisNapomene
GET/session/:id/messageList messages in a sessionquery: limit?, returns { info: Message, parts: Part[]}[]
POST/session/:id/messageSend a message and wait for responsebody: { messageID?, model?, agent?, noReply?, system?, tools?, parts }, returns { info: Message, parts: Part[]}
GET/session/:id/message/:messageIDGet message detailsReturns { info: Message, parts: Part[]}
POST/session/:id/prompt_asyncSend a message asynchronously (no wait)body: same as /session/:id/message, returns 204 No Content
POST/session/:id/commandExecute a slash commandbody: { messageID?, agent?, model?, command, arguments }, returns { info: Message, parts: Part[]}
POST/session/:id/shellRun a shell commandbody: { agent, model?, command }, returns { info: Message, parts: Part[]}

Commands

MetodaPutanjaOpisOdgovor
GET/commandList all commandsCommand[]

Files

MetodaPutanjaOpisOdgovor
GET/find?pattern=<pat>Search for text in filesArray of match objects with path, lines, line_number, absolute_offset, submatches
GET/find/file?query=<q>Find files and directories by namestring[] (paths)
GET/find/symbol?query=<q>Find workspace symbolsSymbol[]
GET/file?path=<path>List files and directoriesFileNode[]
GET/file/content?path=<p>Read a fileFileContent
GET/file/statusGet status for tracked filesFile[]

/find/file query parameters

  • query (required) — search string (fuzzy match)
  • type (optional) — limit results to "file" or "directory"
  • directory (optional) — override the project root for the search
  • limit (optional) — max results (1–200)
  • dirs (optional) — legacy flag ("false" returns only files)

Tools (Experimental)

MetodaPutanjaOpisOdgovor
GET/experimental/tool/idsList all tool IDsToolIDs
GET/experimental/tool?provider=<p>&model=<m>List tools with JSON schemas for a modelToolList

LSP, Formatters & MCP

MetodaPutanjaOpisOdgovor
GET/lspGet LSP server statusLSPStatus[]
GET/formatterGet formatter statusFormatterStatus[]
GET/mcpGet MCP server status{ [name: string]: MCPStatus }
POST/mcpAdd MCP server dynamicallybody: { name, config }, returns MCP status object

Agents

MetodaPutanjaOpisOdgovor
GET/agentList all available agentsAgent[]

Logging

MetodaPutanjaOpisOdgovor
POST/logWrite log entry. Body: { service, level, message, extra? }boolean

TUI

MetodaPutanjaOpisOdgovor
POST/tui/append-promptAppend text to the promptboolean
POST/tui/open-helpOpen the help dialogboolean
POST/tui/open-sessionsOpen the session selectorboolean
POST/tui/open-themesOpen the theme selectorboolean
POST/tui/open-modelsOpen the model selectorboolean
POST/tui/submit-promptSubmit the current promptboolean
POST/tui/clear-promptClear the promptboolean
POST/tui/execute-commandExecute a command ({ command })boolean
POST/tui/show-toastShow toast ({ title?, message, variant })boolean
GET/tui/control/nextWait for the next control requestControl request object
POST/tui/control/responseRespond to a control request ({ body })boolean

Auth

MetodaPutanjaOpisOdgovor
PUT/auth/:idSet authentication credentials. Body must match provider schemaboolean

Events

MetodaPutanjaOpisOdgovor
GET/eventServer-sent events stream. First event is server.connected, then bus eventsServer-sent events stream

Docs

MetodaPutanjaOpisOdgovor
GET/docOpenAPI 3.1 specificationHTML page with OpenAPI spec