本文へスキップ

SDK

自分のスクリプト、CIジョブ、ツールからOpenCodeを操作できます。SDKはあなたの設定とモデルでOpenCodeをプロセス内で実行し、型付きクライアントでセッションの作成、プロンプトの送信、すべてのイベントのストリーミングを行えます。

機能

コードでCIを修正

短いスクリプトで、失敗したテストをOpenCodeに直させて再実行します。

すべてのステップを追う

イベントをストリーミングして、エージェントが呼ぶツールを即座に確認。

独自のツールを作る

数行のコードで、ボット、ダッシュボード、ワークフローにOpenCodeを組み込めます。

プロセス内で実行

あなたの設定とモデルで、OpenCodeをプロセス内で実行します。

  • TypeScriptクライアント型付きのリクエストとイベント。@opencode/client と同じ値を使います。
  • コードでセッションどのスクリプトからでもセッションを作成し、プロンプトを送れます。
  • 任意のモデルOpenCodeの設定にあるモデルをそのまま使います。
  • npmまたはbunnpm i @opencode/sdk または bun add @opencode/sdk でインストールできます。
  • インプロセスホストネットワークを介さず、メモリ内でOpenCodeを実行します。
  • 自分のプラグインインプロセスホストの作成時に、独自のプラグインを渡せます。
  • PromiseかEffect同じ値を返すPromise APIとEffect API。
  • Cloudflare WorkersWorkers上のCloudflare Durable Object内でOpenCodeを実行できます。

  • npmnpm i @opencode/sdk
  • bunbun add @opencode/sdk
SDKのドキュメントを読む

変更履歴

  1. v2.2.7

    session.generate returns tokens and cost along with text

    v2.2.7 のハイライトをすべて見る

    破壊的変更

    SDK: fewer endpoints wait for plugins to load

    On a Location that is still loading plugins, agent.list returns the agents loaded so far, and integration.list, usage.limits, vcs.init, rpc.call and artifact.* no longer wait up to 5 seconds. Entries and actions that a plugin provides appear when it finishes loading, so refresh on the matching *.updated event. Model, provider, generate.*, voice.* and websearch.query endpoints still wait.

    #62796#63040

    改善

    • SDKcredential.updated includes the integrationID and credentialID of the login that changed.#62762
    • SDKPredicate questions in client.experimental.generate.decisions accept optional criteria: { true?, false? }.#62819
  2. v2.2.6

    Improvements

    v2.2.6 のハイライトをすべて見る

    改善

    • SDKAdded client.experimental.job.list() and its Effect equivalent for listing background shell, subagent, and image jobs, with session, descendant, kind, and status filters.#60698
    • SDKServer embedders can provide a custom fetch implementation for OpenCode HTTP, model, web, and remote MCP traffic.#61582
  3. v2.2.4

    Publish Interactive Artifacts

    Enable "experimental": { "artifacts": true } in opencode.json to let agents publish, update, and serve HTML or static artifacts through the built-in local provider or plugin-provided storage.#60351

    v2.2.4 のハイライトをすべて見る

    改善

    • SDKExtended client.experimental.persistentPty.update to rename terminals or clear a user title, and exposed userTitle plus persistent-pty.updated events.#60329
すべての更新を見る