ForgeCode with AI Gateway
ForgeCode is a terminal coding agent. It supports custom OpenAI-compatible providers, which you can point at AI Gateway for unified model access and spend monitoring.
Run the Vercel CLI setup command for ForgeCode:
npx vercel ai-gateway setup --agent forgeThe command writes a gateway [[providers]] entry and [session] defaults into ~/.forge/.forge.toml. It stores the key in the sibling .credentials.json with 0600 permissions, which is the only key source Forge 2.13 and later read. Re-run it to refresh the defaults.
If you can't use the Vercel CLI, configure ForgeCode manually:
Go to the AI Gateway section in the Vercel dashboard sidebar and click API keys to create a new API key.
Add a
[[providers]]entry to~/.forge/.forge.toml:~/.forge/.forge.toml[[providers]] id = "vercel-ai-gateway" url = "https://ai-gateway.vercel.sh/coding-agent/v1/chat/completions" models = "https://ai-gateway.vercel.sh/coding-agent/v1/models" api_key_vars = "AI_GATEWAY_API_KEY" response_type = "OpenAI" auth_methods = ["api_key"] [session] provider_id = "vercel-ai-gateway" model_id = "openai/gpt-6-astra"Forge 2.13 and later resolve keys only from
~/.forge/.credentials.json, not the environment. Add the key to the JSON array with mode0600:~/.forge/.credentials.json[ { "provider_id": "vercel-ai-gateway", "auth_details": { "api_key": "your-ai-gateway-api-key" } } ]Terminalchmod 0600 ~/.forge/.credentials.jsonOlder Forge releases read the key from
AI_GATEWAY_API_KEYin the environment instead, which is why the provider also declaresapi_key_vars.- Terminal
forgeSwitch models in-session with
:config-model. The picker fills from the gateway's/modelsendpoint, so the full catalog is available.
View your usage, spend, and request activity in the AI Gateway section in the Vercel dashboard sidebar. See the observability documentation for more details.
| Variable | Description |
|---|---|
AI_GATEWAY_API_KEY | Your AI Gateway API key. Used by Forge releases older than 2.13; newer releases read .credentials.json |
- Browse the models catalog for available models
- Configure spend limits on your API key
Was this helpful?