日本語
ドキュメント
サーバー

Server

HTTP 経由で opencode サーバーとやり取りします。

opencode serve コマンドは、opencode クライアントが使用できる OpenAPI エンドポイントを公開する、ヘッドレス HTTP サーバーを実行します。


Usage

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

Options

FlagDescriptionDefault
--port待ち受けるポート4096
--hostname待ち受けるホスト名127.0.0.1
--mdnsmDNS 検出を有効にしますfalse
--mdns-domainmDNS サービスのカスタムドメイン名opencode.local
--cors許可する追加のブラウザオリジン[]

--cors は複数回渡せます:

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

Authentication

OPENCODE_SERVER_PASSWORD を設定して、HTTP basic 認証でサーバーを保護します。ユーザー名はデフォルトで opencode ですが、OPENCODE_SERVER_USERNAME を設定して上書きできます。これは opencode serveopencode web の両方に適用されます。

OPENCODE_SERVER_PASSWORD=your-password opencode serve

How it works

opencode を実行すると、TUI とサーバーが起動します。ここで TUI は、サーバーと通信するクライアントです。サーバーは OpenAPI 3.1 仕様のエンドポイントを公開します。このエンドポイントは、SDK の生成にも使われます。

ヒント: opencode サーバーを使って、opencode をプログラム的に操作してください。

このアーキテクチャにより、opencode は複数のクライアントをサポートでき、opencode をプログラム的に操作できます。

opencode serve を実行して、スタンドアロンのサーバーを起動できます。opencode の TUI が実行中の場合、opencode serve は新しいサーバーを起動します。


Connect to an existing server

TUI を起動すると、ポートとホスト名がランダムに割り当てられます。代わりに --hostname--port フラグを渡すこともできます。そして、これを使ってそのサーバーに接続します。

/tui エンドポイントを使って、サーバーを通じて TUI を操作できます。例えば、プロンプトを事前入力したり実行したりできます。このセットアップは、OpenCode の IDE プラグインで使用されています。


Spec

サーバーは、次の場所で閲覧できる OpenAPI 3.1 仕様を公開します:

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

例えば、http://localhost:4096/doc です。この仕様を使って、クライアントを生成したり、リクエストとレスポンスの型を調べたりします。あるいは Swagger エクスプローラーで表示します。


APIs

opencode サーバーは、次の API を公開します。


Global

MethodPathDescriptionResponse
GET/global/healthサーバーのヘルスとバージョンを取得{ healthy: true, version: string }
GET/global/eventグローバルイベントを取得(SSE ストリーム)Event stream

Project

MethodPathDescriptionResponse
GET/projectすべてのプロジェクトを一覧表示Project[] (opens in a new tab)
GET/project/current現在のプロジェクトを取得Project (opens in a new tab)

Path & VCS

MethodPathDescriptionResponse
GET/path現在のパスを取得Path (opens in a new tab)
GET/vcs現在のプロジェクトの VCS 情報を取得VcsInfo (opens in a new tab)

Instance

MethodPathDescriptionResponse
POST/instance/dispose現在のインスタンスを破棄boolean

Config

MethodPathDescriptionResponse
GET/config設定情報を取得Config (opens in a new tab)
PATCH/config設定を更新Config (opens in a new tab)
GET/config/providersプロバイダーとデフォルトモデルを一覧表示{ providers: Provider[] (opens in a new tab), default: { [key: string]: string } }

Provider

MethodPathDescriptionResponse
GET/providerすべてのプロバイダーを一覧表示{ all: Provider[] (opens in a new tab), default: {...}, connected: string[] }
GET/provider/authプロバイダーの認証方法を取得{ [providerID: string]: ProviderAuthMethod[] (opens in a new tab) }
POST/provider/{id}/oauth/authorizeOAuth を使ってプロバイダーを認可ProviderAuthAuthorization (opens in a new tab)
POST/provider/{id}/oauth/callbackプロバイダーの OAuth コールバックを処理boolean

Sessions

MethodPathDescriptionNotes
GET/sessionすべてのセッションを一覧表示Session[] (opens in a new tab) を返します
POST/session新しいセッションを作成body: { parentID?, title? }Session (opens in a new tab) を返します
GET/session/statusすべてのセッションのステータスを取得{ [sessionID: string]: SessionStatus (opens in a new tab) } を返します
GET/session/:idセッションの詳細を取得Session (opens in a new tab) を返します
DELETE/session/:idセッションとそのすべてのデータを削除boolean を返します
PATCH/session/:idセッションのプロパティを更新body: { title? }Session (opens in a new tab) を返します
GET/session/:id/childrenセッションの子セッションを取得Session[] (opens in a new tab) を返します
GET/session/:id/todoセッションの todo リストを取得Todo[] (opens in a new tab) を返します
POST/session/:id/initアプリを分析して AGENTS.md を作成body: { messageID, providerID, modelID }boolean を返します
POST/session/:id/fork既存のセッションをメッセージ位置でフォークbody: { messageID? }Session (opens in a new tab) を返します
POST/session/:id/abort実行中のセッションを中止boolean を返します
POST/session/:id/shareセッションを共有Session (opens in a new tab) を返します
DELETE/session/:id/shareセッションの共有を解除Session (opens in a new tab) を返します
GET/session/:id/diffこのセッションの diff を取得query: messageID?FileDiff[] (opens in a new tab) を返します
POST/session/:id/summarizeセッションを要約body: { providerID, modelID }boolean を返します
POST/session/:id/revertメッセージを元に戻すbody: { messageID, partID? }boolean を返します
POST/session/:id/unrevert元に戻したすべてのメッセージを復元boolean を返します
POST/session/:id/permissions/:permissionID権限リクエストに応答body: { response, remember? }boolean を返します

Messages

MethodPathDescriptionNotes
GET/session/:id/messageセッション内のメッセージを一覧表示query: limit?{ info: Message (opens in a new tab), parts: Part[] (opens in a new tab)}[] を返します
POST/session/:id/messageメッセージを送信して応答を待つbody: { messageID?, model?, agent?, noReply?, system?, tools?, parts }{ info: Message (opens in a new tab), parts: Part[] (opens in a new tab)} を返します
GET/session/:id/message/:messageIDメッセージの詳細を取得{ info: Message (opens in a new tab), parts: Part[] (opens in a new tab)} を返します
POST/session/:id/prompt_asyncメッセージを非同期で送信(待機なし)body: /session/:id/message と同じ、204 No Content を返します
POST/session/:id/commandスラッシュコマンドを実行body: { messageID?, agent?, model?, command, arguments }{ info: Message (opens in a new tab), parts: Part[] (opens in a new tab)} を返します
POST/session/:id/shellシェルコマンドを実行body: { agent, model?, command }{ info: Message (opens in a new tab), parts: Part[] (opens in a new tab)} を返します

Commands

MethodPathDescriptionResponse
GET/commandすべてのコマンドを一覧表示Command[] (opens in a new tab)

Files

MethodPathDescriptionResponse
GET/find?pattern=<pat>ファイル内のテキストを検索pathlinesline_numberabsolute_offsetsubmatches を持つ一致オブジェクトの配列
GET/find/file?query=<q>名前でファイルとディレクトリを検索string[](パス)
GET/find/symbol?query=<q>ワークスペースのシンボルを検索Symbol[] (opens in a new tab)
GET/file?path=<path>ファイルとディレクトリを一覧表示FileNode[] (opens in a new tab)
GET/file/content?path=<p>ファイルを読み取りFileContent (opens in a new tab)
GET/file/status追跡対象のファイルのステータスを取得File[] (opens in a new tab)

/find/file query parameters

  • query(必須)— 検索文字列(ファジーマッチ)
  • type(任意)— 結果を "file" または "directory" に制限
  • directory(任意)— 検索のためにプロジェクトルートを上書き
  • limit(任意)— 最大結果数(1-200)
  • dirs(任意)— レガシーフラグ("false" はファイルのみを返します)

Tools (Experimental)

MethodPathDescriptionResponse
GET/experimental/tool/idsすべてのツール ID を一覧表示ToolIDs (opens in a new tab)
GET/experimental/tool?provider=<p>&model=<m>モデルの JSON スキーマ付きでツールを一覧表示ToolList (opens in a new tab)

LSP, Formatters & MCP

MethodPathDescriptionResponse
GET/lspLSP サーバーのステータスを取得LSPStatus[] (opens in a new tab)
GET/formatterフォーマッターのステータスを取得FormatterStatus[] (opens in a new tab)
GET/mcpMCP サーバーのステータスを取得{ [name: string]: MCPStatus (opens in a new tab) }
POST/mcpMCP サーバーを動的に追加body: { name, config }、MCP ステータスオブジェクトを返します

Agents

MethodPathDescriptionResponse
GET/agent利用可能なすべてのエージェントを一覧表示Agent[] (opens in a new tab)

Logging

MethodPathDescriptionResponse
POST/logログエントリを書き込み。Body: { service, level, message, extra? }boolean

TUI

MethodPathDescriptionResponse
POST/tui/append-promptプロンプトにテキストを追加boolean
POST/tui/open-helpヘルプダイアログを開くboolean
POST/tui/open-sessionsセッションセレクターを開くboolean
POST/tui/open-themesテーマセレクターを開くboolean
POST/tui/open-modelsモデルセレクターを開くboolean
POST/tui/submit-prompt現在のプロンプトを送信boolean
POST/tui/clear-promptプロンプトをクリアboolean
POST/tui/execute-commandコマンドを実行({ command }boolean
POST/tui/show-toastトーストを表示({ title?, message, variant }boolean
GET/tui/control/next次の制御リクエストを待つ制御リクエストオブジェクト
POST/tui/control/response制御リクエストに応答({ body }boolean

Auth

MethodPathDescriptionResponse
PUT/auth/:id認証情報を設定。Body はプロバイダーのスキーマに一致する必要がありますboolean

Events

MethodPathDescriptionResponse
GET/eventServer-sent events ストリーム。最初のイベントは server.connected、その後にバスイベントServer-sent events ストリーム

Docs

MethodPathDescriptionResponse
GET/docOpenAPI 3.1 仕様OpenAPI 仕様付きの HTML ページ