컨텐츠로 건너뛰기

서버

opencode serve 명령은 opencode 클라이언트가 사용할 수 있는 OpenAPI 엔드포인트를 노출하는 헤드리스 HTTP 서버를 실행합니다.


사용법

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

옵션

FlagDescriptionDefault
--portPort to listen on4096
--hostnameHostname to listen on127.0.0.1
--mdnsEnable mDNS discoveryfalse
--mdns-domainCustom domain name for mDNS serviceopencode.local
--corsAdditional browser origins to allow[]

--cors는 여러 번 전달할 수 있습니다:

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

인증

OPENCODE_SERVER_PASSWORD를 설정하여 HTTP basic auth로 서버를 보호하세요. 사용자 이름의 기본값은 opencode이며, OPENCODE_SERVER_USERNAME으로 재정의할 수 있습니다. 이는 opencode serveopencode web 모두에 적용됩니다.

OPENCODE_SERVER_PASSWORD=your-password opencode serve

작동 방식

opencode를 실행하면 TUI와 서버가 시작됩니다. TUI는 서버와 통신하는 클라이언트입니다. 서버는 OpenAPI 3.1 사양 엔드포인트를 노출합니다. 이 엔드포인트는 SDK를 생성하는 데에도 사용됩니다.

이 아키텍처를 통해 opencode는 여러 클라이언트를 지원하고 프로그래밍 방식으로 상호작용할 수 있습니다.

opencode serve를 실행하여 독립 서버를 시작할 수 있습니다. opencode TUI가 실행 중인 경우, opencode serve는 새 서버를 시작합니다.


기존 서버에 연결

TUI를 시작하면 포트와 호스트명이 무작위로 할당됩니다. 대신 --hostname--port 플래그를 전달할 수 있습니다. 그런 다음 이를 사용하여 서버에 연결합니다.

/tui 엔드포인트는 서버를 통해 TUI를 구동하는 데 사용할 수 있습니다. 예를 들어 프롬프트를 미리 채우거나 실행할 수 있습니다. 이 설정은 OpenCode IDE 플러그인에서 사용됩니다.


사양

서버는 다음에서 볼 수 있는 OpenAPI 3.1 사양을 게시합니다:

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

예를 들어, http://localhost:4096/doc. 사양을 사용하여 클라이언트를 생성하거나 요청 및 응답 타입을 확인하세요. 또는 Swagger 탐색기에서 확인하세요.


APIs

opencode 서버는 다음 API를 노출합니다.


Global

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

Project

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

Path & VCS

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

Instance

MethodPathDescriptionResponse
POST/instance/disposeDispose the current instanceboolean

Config

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

Provider

MethodPathDescriptionResponse
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

MethodPathDescriptionNotes
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

MethodPathDescriptionNotes
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

MethodPathDescriptionResponse
GET/commandList all commandsCommand[]

Files

MethodPathDescriptionResponse
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 (필수) — 검색 문자열 (퍼지 매치)
  • type (선택) — 결과를 "file" 또는 "directory"로 제한
  • directory (선택) — 검색의 프로젝트 루트 재정의
  • limit (선택) — 최대 결과 수 (1–200)
  • dirs (선택) — 레거시 플래그 ("false"는 파일만 반환)

Tools (Experimental)

MethodPathDescriptionResponse
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

MethodPathDescriptionResponse
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

MethodPathDescriptionResponse
GET/agentList all available agentsAgent[]

Logging

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

TUI

MethodPathDescriptionResponse
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

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

Events

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

Docs

MethodPathDescriptionResponse
GET/docOpenAPI 3.1 specificationHTML page with OpenAPI spec