Zum Inhalt springen

SDK

Steuere OpenCode aus deinen eigenen Skripten, CI-Jobs und Tools. Das SDK führt OpenCode in deinem Prozess aus, mit deiner Konfiguration und deinen Modellen, und sein typisierter Client erstellt Sessions, sendet Prompts und streamt jedes Event.

Funktionen

CI per Code reparieren

Ein Skript lässt OpenCode kaputte Tests reparieren und führt sie neu aus.

Jeden Schritt verfolgen

Streame Events und sieh jedes Tool, das der Agent aufruft, in Echtzeit.

Eigene Tools bauen

Binde OpenCode mit wenigen Zeilen in Bots, Dashboards und Workflows ein.

In deinem Prozess

OpenCode läuft in deinem Prozess, mit deiner Config und deinen Modellen.

  • TypeScript-ClientTypisierte Requests und Events, mit denselben Werten wie @opencode/client.
  • Sessions aus CodeErstelle Sessions und sende Prompts aus jedem Skript.
  • Jedes ModellNutzt die Modelle, die dein OpenCode-Setup hat.
  • npm oder bunInstalliere es mit npm i @opencode/sdk oder bun add @opencode/sdk.
  • In-Process-HostFührt OpenCode im Speicher aus, ohne Umweg übers Netzwerk.
  • Deine PluginsÜbergib eigene Plugins, wenn du den In-Process-Host erstellst.
  • Promise oder EffectEine Promise-API und eine Effect-API mit denselben Werten.
  • Cloudflare WorkersFühre OpenCode in einem Cloudflare Durable Object auf Workers aus.

  • npmnpm i @opencode/sdk
  • bunbun add @opencode/sdk
SDK-Doku lesen

Changelog

  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

    Verbesserungen

    • 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

    Verbesserungen

    • 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

    Fehlerbehebungen

    • 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

    Verbesserungen

    • 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.
Alle Updates ansehen