Back to API Docs

Opencode

Opencode via the @ai-sdk/openai-compatible provider.

Connection

URL cơ sở
https://your-domain.com/v1
Install
npm install -g opencode-ai

Default model

Setup

  1. Install Opencode globally via npm.
  2. Create an opencode.json configuration file at your project root.
  3. Export your gateway API key in the shell.
  4. Run `opencode` in your project directory.

Cấu hình

Configuration file
opencode.json
json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "gateway": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "API Gateway",
      "options": {
        "baseURL": "https://your-domain.com/v1",
        "apiKey": "{env:GATEWAY_API_KEY}"
      },
      "models": {
        "gpt-4o-mini": { "name": "gpt-4o-mini" },
        "claude-3-5-sonnet-latest": { "name": "Claude 3.5 Sonnet" },
        "gpt-4o": { "name": "GPT-4o" }
      }
    }
  },
  "model": "gateway/gpt-4o-mini"
}
Shell environment
~/.zshrc
bash
export GATEWAY_API_KEY="YOUR_API_KEY"