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:
npx vercel ai-gateway setup --agent opencodeThis command:
- Provisions an 资产生成 API key, or reuses one you pass with
--key. - Adds the
vercelprovider 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
.bakfile.
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:
- Run
opencodein your terminal. - Run the
/modelscommand and pick a gateway model. - 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.
Go to the 资产生成 section in the Vercel dashboard sidebar and click API keys to create a new API key.
Run
opencodein your terminal to start OpenCode:TerminalopencodeRun the
/connectcommand and search for AI 资产生成:Terminal/connectEnter your AI 资产生成 API key when prompted.
Run the
/modelscommand to select a model:Terminal/modelsYour 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:
{
"$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.
Was this helpful?