0d3cb498a3
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
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) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
139 lines
3.4 KiB
Markdown
139 lines
3.4 KiB
Markdown
# 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.
|
|
|
|
```bash
|
|
npx promptfoo@latest init --example provider-opencode-sdk
|
|
cd provider-opencode-sdk
|
|
```
|
|
|
|
## Setup
|
|
|
|
### 1. Install OpenCode CLI
|
|
|
|
```bash
|
|
curl -fsSL https://opencode.ai/install | bash
|
|
```
|
|
|
|
### 2. Install OpenCode SDK
|
|
|
|
```bash
|
|
npm install @opencode-ai/sdk
|
|
```
|
|
|
|
Configure provider credentials in your shell or `.env`. For example:
|
|
|
|
```bash
|
|
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**:
|
|
|
|
```bash
|
|
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**:
|
|
|
|
```bash
|
|
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**:
|
|
|
|
```bash
|
|
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**:
|
|
|
|
```bash
|
|
cd permissions
|
|
npx promptfoo@latest eval -c promptfooconfig.yaml --no-cache
|
|
```
|
|
|
|
## Provider Configuration
|
|
|
|
The provider supports these high-value options:
|
|
|
|
```yaml
|
|
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
|
|
|
|
- [OpenCode SDK Provider Documentation](/docs/providers/opencode-sdk/)
|
|
- [OpenCode Documentation](https://opencode.ai/docs/)
|
|
- [OpenCode SDK Reference](https://opencode.ai/docs/sdk/)
|
|
- [Claude Agent SDK Provider](/docs/providers/claude-agent-sdk/) - Alternative agentic provider
|