Cursor with AI Gateway
Cursor is an AI-first code editor. Point its OpenAI API key settings at AI Gateway to reach every model in the gateway catalog and track spend in one place.
Run the Vercel CLI setup command for Cursor:
npx vercel ai-gateway setup --agent cursorThe command provisions a key, exports it as AI_GATEWAY_API_KEY from your shell startup file, and prints the remaining setup steps with your values filled in. Cursor keeps API-key settings in its account-synced store instead of a file on disk, so you must finish the setup in Cursor.
Complete these steps in Cursor after running the Vercel CLI. If you don't use the CLI, create an API key in the first step.
If you ran the Vercel CLI setup command on macOS, open a new terminal so your shell loads the
AI_GATEWAY_API_KEYexport, then copy the key without displaying it in the terminal:terminalprintf %s "$AI_GATEWAY_API_KEY" | pbcopyIf you didn't use the Vercel CLI, go to the AI Gateway section in the Vercel dashboard sidebar and click API keys to create a key.
In Cursor, open Settings with
Cmd+Shift+J, then go to Models.Under OpenAI API Key, paste your AI Gateway key. Then enable Override OpenAI Base URL and set it to Cursor's dedicated compatibility endpoint:
https://ai-gateway.vercel.sh/cursor/v1Cursor's base URL override sends
/chat/completionsbodies that the standard OpenAI schema rejects. Version 3.14.x sends flat tool definitions whosetypeisn'tfunction, and newer builds send Responses-shaped bodies withinputinstead ofmessages. The/cursor/v1endpoint normalizes both into standard Chat Completions. Every other path falls through to the standard/v1handlers, so routing, billing, and errors are unchanged. Pointing Cursor at the bare/v1or coding agent surface returns a 400 ontools.0.typeinstead.Use Add model to add gateway model IDs to the picker, for example
anthropic/claude-opus-5oropenai/gpt-6-astra. Model IDs use the gateway'screator/model-nameformat, and the models catalog lists what's available.
Cursor's bring-your-own-key support has constraints that come from Cursor itself, not from AI Gateway:
| Limitation | What it means |
|---|---|
| Built-in models stop working | While the base URL override is on, Cursor's own non-OpenAI models are unavailable. Use gateway model IDs for everything, or turn the override off to go back |
| Tab completions are excluded | Tab never uses a custom key, so those requests don't reach the gateway |
| Agent and Auto may bypass the override | Some agent modes route to Cursor's own models regardless of the override |
| Requests pass through Cursor | Bring-your-own-key traffic still goes through Cursor's backend on the way to the gateway |
| No local sessions | Cursor stores chats in its backend, so there are no local sessions to migrate when you switch providers |
- Browse the models catalog for available models
- Configure spend limits on your API key
- Connect your terminal agents with the Vercel CLI
Was this helpful?