import { createAgentSession } from "agent-harness-experimental";import { openCode } from "@agent-harness-experimental/adapter-opencode";const agent = createAgentSession({ adapter: openCode(),});const result = await agent.generate("Add error handling to the API routes");console.log(result.text);await agent.close("stop");
Configuration
openCode({ // Model ID (e.g. 'anthropic/claude-sonnet-4') model: "anthropic/claude-sonnet-4", // Model provider provider: "anthropic", // 'anthropic' | 'openai' | etc.});
Option
Type
Default
Description
model
string
—
Model ID
provider
string
—
Model provider
auth
object
—
Optional per-adapter auth override matching the selected provider
Sandbox runtime options such as template, timeoutMs, and httpHandler
belong on createAgentSession({ sandbox }).
auth is optional. If you omit it, OpenCode uses the shared ambient
gateway/OIDC fallback first: AI_GATEWAY_API_KEY, then VERCEL_OIDC_TOKEN.
For multi-provider runs, OpenCode uses the auth bag
matching provider or the model prefix.