@opencode-ai/client is the generated TypeScript client for the OpenCode HTTP
API. Use it when your application connects to an OpenCode server over the
network. Its types and methods are generated from the same contract as the
API reference.
The V2 API and client are beta. Method names, inputs, and outputs may change
before the stable release.
Install
Create a client
Create a client with the server URL, then call methods grouped by API resource:
Headers and requests
Pass default authentication or application headers to OpenCode.make with
headers. You can also supply a custom fetch implementation. Each operation
accepts request options as its final argument for an AbortSignal or
per-request headers.
Stream events
Streaming endpoints return async iterables:
Local background service
The main client entrypoints are browser-compatible and do not include local
process management. In a Node application, import the native Promise service
API from @opencode-ai/client/service.
Service.discover() returns a healthy registered endpoint without starting
a process.
Service.ensure() returns a compatible service, starting one when needed.
Service.stop() stops the exact registered service instance.
Service.headers(endpoint) creates the authentication headers for a client.
Service.ensure() accepts an optional registration file, required version,
service command, and onStart callback:
Omit these options to use the standard registration path and
opencode serve --service command.
Effect
OpenCode provides a first-class Effect client through the
@opencode-ai/client/effect entrypoint. It returns typed Effects and Streams
and decodes responses into OpenCode schema values.
Create a client
Streaming operations, including client.event.subscribe() and
client.session.log(...), return Effect Stream values.
Local background service
The Node-only @opencode-ai/client/effect/service entrypoint exposes the same
operations as Effect values. Add @effect/platform-node and provide its
filesystem layer when running them.