Coding Agents

OpenCode with AI Gateway
This command:
npx vercelai-gatewaysetup--agentopencode
OpenCode
OpenCode is a terminal-based AI coding agent that runs in your development environment. Here's how to use OpenCode with Vercel AI Gateway to access models from OpenAI, Anthropic, Google, SpaceXAI, and more through a unified endpoint.
- Provisions an AI Gateway 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:
- Run opencode in your terminal.
- Run the /models command and pick a gateway model.
- Confirm your requests appear in the AI Gateway section in the Vercel dashboard sidebar.
Manual setup
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.
- Create an API keyGo to the AI Gateway section in the Vercel dashboard sidebar and click API keys to create a new API key.
-
Start OpenCodeRun
opencode in your terminal to start OpenCode:
opencode
-
Connect to AI GatewayRun the
/connect command and search for Vercel AI Gateway:
/connectEnter your Vercel AI Gateway API key when prompted.
-
Select a modelRun the
/models command to select a model:
/modelsYour requests will now be routed through Vercel AI Gateway.
Configure provider routing
You can customize models through your OpenCode config. Here's an example of specifying provider routing order in opencode.json:
{
"provider": {
}
"vercel": {
"models": {
"anthropic/claude-sonnet-5": {
"options": {
}
}
}
}
"order": ["anthropic","vertex"]
}
Monitor usage and spend
Last updated September 13, 2026
See the provider options documentation for more details on supported routing options.
View your usage, spend, and request activity in the AI Gateway section in the Vercel dashboard sidebar. See the observability documentation for more details.
Cross-link map: OpenCode with AI Gateway (/docs/ai-gateway/coding-agents/opencode)From the Vercel docs graph (built 2026-09-21T05:26:59.511Z), spanning vercel.com docs + KB, nextjs.org, ai-sdk.dev, and other Vercel documentation sites. Full graph as JSON: https://vercel.com/docs/graph.jsonSemantically closest pagesCommand Code with AI Gateway — Connect Command Code to AI Gateway with your own API key and a custom base URL. Configure models, switch between them, aZCode with AI Gateway — Connect ZCode to AI Gateway with the Vercel CLI or an OpenAI-compatible custom provider.OpenClaw with AI Gateway — Connect OpenClaw to AI Gateway with the Vercel CLI or manual provider configuration. Use gateway models across coding agForgeCode with AI Gateway — Connect ForgeCode to AI Gateway with the Vercel CLI or custom provider and credential files.Kilo Code with AI Gateway — Connect Kilo Code to AI Gateway with the Vercel CLI or an OpenAI-compatible provider configuration. Set your API key andThis page links to (3)AI Gateway Provider Routing and Fallbacks — Configure provider routing, ordering, and fallback behavior in Vercel AI Gateway.AI Gateway Observability — Monitor AI Gateway requests in the Vercel dashboard. Inspect token usage, latency, spend, and logs at team, project, andvercel ai-gateway — Manage AI Gateway resources from the Vercel CLI: API keys, budgets, routing rules, virtual models, models, leaderboards,Pages that link here (3)By site: vercel-docs (3)Coding Agents and Chat Platforms with AI Gateway — Connect coding agents and chat platforms to AI Gateway. Configure Claude Code, Codex, Chatbox, Open WebUI, and more.Harbor with AI Gateway — Evaluate coding-agent harnesses with Harbor and AI Gateway. Choose a harness, configure its connection, and pass separatvercel ai-gateway — Manage AI Gateway resources from the Vercel CLI: API keys, budgets, routing rules, virtual models, models, leaderboards,
Previous
We provide 24/7 support through various channels, including live chat, email, and phone, to assist with any queries.
OpenClaw
Was this helpful?