new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

AI SDK · Providers · all subjects

opencode/setup

15 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

OpenCode harness setup packages

To set up the OpenCode harness adapter, install three packages: @ai-sdk/harness, @ai-sdk/harness-opencode, and @ai-sdk/sandbox-vercel.

OpenCode harness imports

Import openCode and createOpenCode from '@ai-sdk/harness-opencode'. The openCode export is equivalent to createOpenCode() with default configuration.

OpenCode harness basic usage example

import { HarnessAgent } from '@ai-sdk/harness/agent'; import { openCode } from '@ai-sdk/harness-opencode'; import { createVercelSandbox } from '@ai-sdk/sandbox-vercel'; const agent = new HarnessAgent({ harness: openCode, sandbox: createVercelSandbox({ runtime: 'node24', ports: [4000], }), }); const session = await agent.createSession(); let exitCode = 0; try { const result = await agent.stream({ session, prompt: 'Check the test failures and fix the production code.', }); for await (const part of result.stream) { if (part.type === 'text-delta') { process.stdout.write(part.text); } } } catch (err) { exitCode = 1; console.error(err); } finally { await session.destroy(); process.exit(exitCode); }

OpenCode harness environment variables

To use the OpenCode harness agent, ensure environment variables include VERCEL_OIDC_TOKEN for Vercel Sandbox and one of the variables listed for authentication (AI_GATEWAY_API_KEY, AI_GATEWAY_BASE_URL, VERCEL_OIDC_TOKEN, ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_BASE_URL, OPENAI_API_KEY, OPENAI_BASE_URL, OPENAI_ORGANIZATION, or OPENAI_PROJECT).

OpenCode authentication configuration example

const harness = createOpenCode({ auth: { gateway: { apiKey: process.env.AI_GATEWAY_API_KEY, }, }, });

OpenCode OpenAI-compatible authentication

For OpenAI-compatible endpoints, use auth.openaiCompatible and set the name property to the OpenCode provider id.

OpenCode sandbox requirements

OpenCode requires a network sandbox with at least one exposed port. The @ai-sdk/sandbox-vercel provider can be used with configuration like createVercelSandbox({ runtime: 'node24', ports: [4000] }).

OpenCode harness experimental status

Harness packages are experimental. Breaking changes are expected between releases as the early API gets further refined.

OpenCode provider enables multiple AI providers through unified interface

The ai-sdk-provider-opencode-sdk community provider enables using multiple AI providers (Anthropic, OpenAI, Google) through the OpenCode SDK. OpenCode is a terminal-based AI coding assistant that provides a unified interface to various AI models.

OpenCode version compatibility with AI SDK

Version 1.x of OpenCode provider supports AI SDK v6 with npm tag 'latest' (Stable status). Version 0.x supports AI SDK v5 with npm tag 'ai-sdk-v5' (Maintenance status).

OpenCode installation commands for different AI SDK versions

For AI SDK v6: npm install ai-sdk-provider-opencode-sdk ai For AI SDK v5: npm install ai-sdk-provider-opencode-sdk@ai-sdk-v5 ai@^5.0.0

OpenCode default provider instance import

The default provider instance 'opencode' can be imported from 'ai-sdk-provider-opencode-sdk': import { opencode } from 'ai-sdk-provider-opencode-sdk';

OpenCode createOpencode function for customized setup

For customized setup, import createOpencode and create a provider instance: import { createOpencode } from 'ai-sdk-provider-opencode-sdk'; const opencode = createOpencode({ autoStartServer: true, serverTimeout: 10000, defaultSettings: { agent: 'build' } });

OpenCode provider disposal

OpenCode runs as a managed server and should be disposed when done using: await opencode.dispose(); or await opencode.getClientManager().dispose(); The client manager automatically cleans up on process exit (SIGINT, SIGTERM).

OpenCode system requirements

OpenCode requires Node.js 22 or higher, OpenCode CLI installed (npm install -g opencode), and provider credentials configured in OpenCode (Anthropic, OpenAI, or Google API keys).

Give your agent this brain