本文へスキップ

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.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

    改善

    • SDKExtended client.experimental.persistentPty.update to rename terminals or clear a user title, and exposed userTitle plus persistent-pty.updated events.#60329
  2. v2.2.3

    Added lazy loading for stored image references when experimental.media_blob is enabled

    Added lazy loading for stored image references when experimental.media_blob is enabled. Images are downloaded only for previews, while undo, revert, fork, and prompt recall restore referenced attachments safely.#60116

    改善

    • SDKPreserved partial LLMResponse output on AIError.partial when generation, object generation, or a tool loop fails.#60477
    • SDKUnified Effect and Promise tool declarations around tool(...), with optional output schemas and executable or declaration-only tools.#60407
    • SDKAdded typed OpenRouter debug, models, plugins, provider, and user options to the Responses route.#60044

    修正

    • SDKMatched the Promise AI client more closely to the Effect API and accepted typed tools in loops.#60465#60390
    • SDKKept tools whose execute handler can throw available to the AI client.#60431
    • SDKContinued polling queued media generations when providers return unknown intermediate statuses.#59988
    • SDKStopped sending an incompatible filename alongside file_url on OpenAI Responses requests.#60382
  3. v2.2.2

    Exposed SessionInfo.time.busy for the latest execution’s start time

    改善

    • SDKAdded if and until inputs for client.experimental.schedule.create, plus schedule check results and output fields.#60137
    • SDKAdded optional source metadata to prompt file attachments.
すべての更新を見る