Files
wehub-resource-sync 0d3cb498a3
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Waiting to run
Test and Publish Multi-arch Docker Image / test (push) Waiting to run
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Blocked by required conditions
CI / Shell Format Check (push) Waiting to run
CI / Check Ruby (3.4) (push) Waiting to run
CI / CI Config (push) Waiting to run
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Blocked by required conditions
CI / Build on Node ${{ matrix.node }} (push) Blocked by required conditions
CI / Style Check (push) Waiting to run
CI / Generate Assets (push) Waiting to run
CI / Check Python (3.14) (push) Waiting to run
CI / Check Python (3.9) (push) Waiting to run
CI / Build Docs (push) Waiting to run
CI / Code Scan Action (push) Waiting to run
CI / Site tests (push) Waiting to run
CI / webui tests (push) Waiting to run
CI / Run Integration Tests (push) Waiting to run
CI / Run Smoke Tests (push) Waiting to run
CI / Go Tests (push) Waiting to run
CI / Share Test (push) Waiting to run
CI / Redteam (Production API) (push) Waiting to run
CI / Redteam (Staging API) (push) Waiting to run
CI / GitHub Actions Lint (push) Waiting to run
CI / Check Ruby (3.0) (push) Waiting to run
release-please / release-please (push) Waiting to run
release-please / build (push) Blocked by required conditions
release-please / publish-npm (push) Blocked by required conditions
release-please / publish-npm-backfill (push) Waiting to run
release-please / docker (push) Blocked by required conditions
release-please / publish-code-scan-action (push) Blocked by required conditions
release-please / attest-code-scan-action (push) Blocked by required conditions
Validate Renovate Config / Validate Renovate Configuration (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 13:24:08 +08:00
..

provider-opencode-sdk (OpenCode SDK Examples)

The OpenCode SDK provider runs agentic evals through OpenCode, an open-source coding agent with support for hosted and local model providers.

npx promptfoo@latest init --example provider-opencode-sdk
cd provider-opencode-sdk

Setup

1. Install OpenCode CLI

curl -fsSL https://opencode.ai/install | bash

2. Install OpenCode SDK

npm install @opencode-ai/sdk

Configure provider credentials in your shell or .env. For example:

export OPENAI_API_KEY=your_api_key_here

If promptfoo starts the OpenCode server for you, you can also set config.apiKey together with config.provider_id. If you use baseUrl, the target OpenCode server must already be authenticated.

If you are validating changes inside this repository, use npm run local -- eval ... from the repo root. If you initialized an example with npx promptfoo@latest init --example provider-opencode-sdk, run npx promptfoo@latest eval -c promptfooconfig.yaml --no-cache from the example directory.

The shipped examples use OpenAI for reproducible QA, but the provider itself is not OpenAI-specific. OpenCode can route to Anthropic, Google, Ollama, LM Studio, and other providers configured in OpenCode.

Examples

Basic Usage

Chat-only usage in a temporary directory with no filesystem tools.

Location: ./basic/

Usage:

cd basic
npx promptfoo@latest eval -c promptfooconfig.yaml --no-cache

Working Directory

Read-only filesystem access with working_dir, using the default read, grep, glob, and list tools.

Location: ./working-dir/

Usage:

cd working-dir
npx promptfoo@latest eval -c promptfooconfig.yaml --no-cache

Structured Output

Provider-enforced JSON Schema output using the OpenCode format request option.

Location: ./structured-output/

Usage:

cd structured-output
npx promptfoo@latest eval -c promptfooconfig.yaml --no-cache

Permissions

Session-level permission rules mixing simple and pattern-based entries. Promptfoo converts the object config into the PermissionRuleset array the OpenCode v2 API expects.

Location: ./permissions/

Usage:

cd permissions
npx promptfoo@latest eval -c promptfooconfig.yaml --no-cache

Provider Configuration

The provider supports these high-value options:

providers:
  - id: opencode:sdk
    config:
      provider_id: openai
      model: gpt-4o-mini

      # Optional: pass credentials directly when promptfoo starts the server
      apiKey: '{{env.OPENAI_API_KEY}}'

      # Read-only local repo access
      working_dir: ./basic
      workspace: feature-branch

      # Structured output
      format:
        type: json_schema
        schema:
          type: object
          properties:
            answer:
              type: string
          required: [answer]

      # Reuse the same OpenCode session for repeated calls
      persist_sessions: true

Supported Providers

OpenCode can route requests to the provider ecosystem it already supports, including:

  • Anthropic
  • OpenAI
  • Google
  • Ollama
  • LM Studio
  • Other providers configured in OpenCode

Learn More