OpenHands with AI Gateway
OpenHands is an open-source AI coding agent with an interactive app and headless mode. You can configure it to use AI Gateway for unified model access and spend monitoring.
Run the Vercel CLI setup command for OpenHands:
npx vercel ai-gateway setup --agent openhandsThe command writes a minimal llm block into ~/.openhands/agent_settings.json pointing at the gateway with an openai/-prefixed model ID, repoints an existing condenser LLM the same way, and fills the pinned model's per-token cost fields from the gateway catalog.
If you can't use the Vercel CLI, configure OpenHands manually:
Go to the AI Gateway section in the Vercel dashboard sidebar and click API keys to create a new API key.
OpenHands keeps agent settings in
~/.openhands/agent_settings.json. Add anllmblock pointing at the gateway:~/.openhands/agent_settings.json{ "llm": { "usage_id": "agent", "model": "openai/openai/gpt-6-astra", "api_key": "your-ai-gateway-api-key", "base_url": "https://ai-gateway.vercel.sh/coding-agent/v1" } }The
openai/prefix tells OpenHands to speak the OpenAI protocol; the rest is the gateway'screator/model-nameslug, soopenai/openai/gpt-6-astrameans the gateway modelopenai/gpt-6-astra. The key is stored in this file, so create it with mode0600:Terminalchmod 0600 ~/.openhands/agent_settings.jsonIf you use a condenser for context compression, give it the same provider so its summarization calls also route through the gateway:
~/.openhands/agent_settings.json{ "condenser": { "llm": { "model": "openai/openai/gpt-6-astra", "api_key": "your-ai-gateway-api-key", "base_url": "https://ai-gateway.vercel.sh/coding-agent/v1" } } }Headless runs pick this up automatically, with no
--override-with-envsneeded:TerminalopenhandsSwitch models in
/settingswithopenai/<gateway-model-id>.
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 | Not read by OpenHands itself. The key lives in agent_settings.json |
- Browse the models catalog for available models
- Configure spend limits on your API key
- Read the OpenHands documentation for headless runs and configuration
Was this helpful?