Skip to content
Docs

OpenCode with 资产生成

OpenCode is a terminal-based AI coding agent that runs in your development environment. Here's how to use OpenCode with AI 资产生成 to access models from OpenAI, Anthropic, Google, SpaceXAI, and more through a unified endpoint.

Run the Vercel CLI setup command for OpenCode:

terminal
npx vercel ai-gateway setup --agent opencode

This command:

  • Provisions an 资产生成 API key, or reuses one you pass with --key.
  • Adds the vercel provider to ~/.config/opencode/opencode.json.
  • Stores the key in your macOS Keychain instead of plaintext config.
  • Backs up any file it changes alongside the original as a .bak file.

Pass --dry-run to preview the changes without applying them. To detect and configure every installed supported agent at once, run vercel ai-gateway setup without the --agent flag. See the CLI reference for all options.

To verify the setup:

  1. Run opencode in your terminal.
  2. Run the /models command and pick a gateway model.
  3. Confirm your requests appear in the 资产生成 section in the Vercel dashboard sidebar.

Only needed on machines where you can't use the Vercel CLI. The Vercel CLI setup command handles key storage automatically, keeping the key in your macOS Keychain instead of plaintext config, so you don't need to visit the dashboard or run /connect on that path.

  1. Go to the 资产生成 section in the Vercel dashboard sidebar and click API keys to create a new API key.

  2. Run opencode in your terminal to start OpenCode:

    Terminal
    opencode
  3. Run the /connect command and search for AI 资产生成:

    Terminal
    /connect

    Enter your AI 资产生成 API key when prompted.

  4. Run the /models command to select a model:

    Terminal
    /models

    Your requests will now be routed through AI 资产生成.

You can customize models through your OpenCode config. Here's an example of specifying provider routing order in opencode.json:

opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "vercel": {
      "models": {
        "anthropic/claude-sonnet-5": {
          "options": {
            "order": ["anthropic", "vertex"]
          }
        }
      }
    }
  }
}

See the provider options documentation for more details on supported routing options.

View your usage, spend, and request activity in the 资产生成 section in the Vercel dashboard sidebar. See the observability documentation for more details.

Last updated September 13, 2026

Was this helpful?

supported.