Skip to main content

Cursor

Cursor is a code editor with a built-in AI chat and agent. It can send its chat and agent requests to your own endpoint instead of to its default models, and it can use MCP servers as tools. Routing both through Spanway means the models your company approved are the ones engineers use in Cursor, every request lands on the gateway's Logs page under the engineer's key, the key's budget stops a runaway agent loop, and the gateway's routing, fallbacks and guardrails apply to editor traffic like any other.

The gateway has a route made for Cursor, /cursor. Cursor's agent mode sends request bodies in the OpenAI Responses format to the chat completions path and expects chat completions answers back. The /cursor route accepts both shapes, converts them, and always answers in the chat completions format Cursor expects, so agent mode, streaming and tool calls work with any model behind the gateway. This page covers the editor. Launching Cursor's cloud agents through the gateway is a different feature, see Cursor pass-through.

A real-world scenario​

A platform team wants its 40 engineers to use the company's approved models in Cursor, with spend charged to each engineer's team and capped per person. The admin creates one key per engineer with the approved models, a 150 USD monthly budget and the code-context tag. Each engineer pastes the key into Cursor, sets the base URL to the gateway's public address with /cursor on the end, and adds the model names. Agent mode works as before, the admin sees each engineer's requests on Logs under their key alias, and one engineer whose agent loops on a failing test hits the budget instead of running up the invoice.

Before you start​

  • A gateway reachable from the public internet over HTTPS, with a certificate from a public certificate authority. Cursor sends chat and agent requests through Cursor's own servers, not from your computer, so http://localhost:4000, an address on a private network or a certificate signed by a company authority does not work for chat models. If the gateway sits behind an IP allowlist, the allowlist must let Cursor's servers in. MCP is different, see Gateway tools in Cursor.
  • A Cursor plan that lets you add your own API key. The key is added under Cursor Settings, Models, and how Cursor bills your own key depends on the plan, so check your plan's billing terms first.
  • At least one chat model on the gateway that supports tool calling. Agent mode needs it.

Make a key for Cursor​

Give every engineer their own key, so spend and errors show per person. The full recipe is make a key for a tool.

  1. Open Virtual Keys (/ui/api-keys) and click + Create New Key.
  2. Under Key Ownership, pick Another User and the engineer, or You for your own editor.
  3. Set Key Name to a name such as jane-cursor and leave Key Type on AI APIs.
  4. In Models, pick the chat models the engineer may use in Cursor. Cursor uses the same model for chat and agent, so no extra background model is needed.
  5. Open Optional Settings, set Max Budget (USD) to 150 and Reset Budget to monthly, set Requests per minute Limit (RPM) to about 60, and add the Tags code-context and tool:cursor. The code-context tag lets data policy routing treat the key's traffic as code, because Cursor sends no signal of its own.
  6. Click Create Key and copy the key. It is shown once.

The same key from the API:

curl -X POST https://gateway.example.com/key/generate \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \
-d '{"key_alias": "jane-cursor", "key_type": "llm_api", "models": ["gpt-6.1-sol", "claude-sonnet-5-5"], "max_budget": 150, "budget_duration": "30d", "rpm_limit": 60, "tags": ["code-context", "tool:cursor"]}'

Key tags need an Enterprise license. Without one the gateway does not create the key and answers Only premium users can add tags to keys, so leave Tags empty and drop tags from the call. The tool then works the same, only data policy routing cannot match the code-context tag.

Steps​

  1. Check the key and the base URL from a terminal first. This is the same call Cursor makes when it verifies the key.

    curl https://gateway.example.com/cursor/models -H "Authorization: Bearer $SPANWAY_API_KEY"
  2. Open Cursor Settings and go to Models.

  3. Paste the virtual key into the OpenAI API Key field and turn the key on.

  4. Turn on Override OpenAI Base URL and enter https://gateway.example.com/cursor. Do not add /v1. Cursor appends /models and /chat/completions to this address itself.

  5. Add each gateway model name you want as a custom model, typed exactly as the id in the answer to step 1, for example gpt-6.1-sol. Names are case sensitive.

  6. Verify the key in the same settings section, then pick one of the gateway models in the chat model picker and send a prompt.

Setting in CursorValue
OpenAI API KeyYour virtual key, sk-...
Override OpenAI Base URLhttps://gateway.example.com/cursor
Custom model namesPublic model names from GET /cursor/models, for example gpt-6.1-sol and claude-sonnet-5-5

The override applies to every model Cursor treats as an OpenAI model, so while it is on, Cursor can send those requests to the gateway too. If a Cursor built-in model stops working, turn the override off while you use it, or ask the admin to serve that model through the gateway.

Expected result​

The verify step succeeds, the gateway models appear in Cursor's model picker, and answers stream into the chat and agent panels. The answer to step 1 looks like this.

{"data": [{"id": "claude-sonnet-5-5", "object": "model", "created": 1677610602, "owned_by": "openai"}, {"id": "gpt-6.1-sol", "object": "model", "created": 1677610602, "owned_by": "openai"}], "object": "list"}

On the gateway, open Logs (/ui/logs), click Filters, pick your key under Key Alias and click Apply Filters. Each chat turn and each agent step is one row with the model, the tokens and the cost. Cursor does not show response headers, so to see them send the same request with curl and -i.

curl -i https://gateway.example.com/cursor/chat/completions \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"model": "gpt-6.1-sol", "messages": [{"role": "user", "content": "Say hello"}]}'

The headers to read are x-spanway-call-id (the id to search for on Logs), x-spanway-model-group and x-spanway-model-id (the public name and the deployment that answered), x-spanway-response-cost, x-spanway-key-spend and x-spanway-key-max-budget (what this call cost and how much of the budget is used), and x-spanway-attempted-fallbacks when a fallback answered.

Model names and thinking effort​

Cursor sends the model name exactly as you typed it. The /cursor route also understands two suffixes Cursor uses in its own model names, so one gateway model can appear in Cursor in several variants.

Name in CursorWhat the gateway does
gpt-6.1-solCalls the gateway model gpt-6.1-sol.
gpt-6.1-sol-thinking-highCalls gpt-6.1-sol with reasoning effort high. The effort can be none, minimal, low, medium, high, xhigh or max.
gpt-6.1-sol-fastCalls gpt-6.1-sol. The -fast suffix is removed.
gpt-6.1-sol-thinking-low-fastCalls gpt-6.1-sol with reasoning effort low.

The gateway only strips a suffix when the full name is not itself a model it serves and the name without the suffix is, so an admin can still publish a model whose real name ends in -fast. If the request already carries a reasoning effort, the gateway keeps it and ignores the suffix. A model that does not support reasoning effort may reject it with a 400, see Errors.

What works and what does not​

FeatureThrough the gateway
Chat and agent modeYes. Agent mode needs a model with tool calling.
StreamingYes. The gateway converts streamed Responses events into chat completions chunks.
Tool calls, including Cursor's custom and grammar toolsYes. The route rewrites Cursor's tool shapes into the form the provider needs.
Images in the promptYes, when the model behind the name supports images.
Reasoning effortYes, through the -thinking-<effort> names above.
Prompt cachingWhatever the provider behind the name does. The gateway does not add or remove cache settings for Cursor.
Tab completionNo. Cursor serves Tab with its own models whatever key you set.
Cursor's own built-in models while the override is onMay break, see the note under Steps.

Errors​

Cursor shows a failed request as an error in the chat, and a failed key check as a failed verify in Models. The gateway's text is in the answer body, and the same text is on the request's row on Logs. A request that never reached the gateway has no row on Logs.

Gateway messageStatusCauseFix
Authentication Error, Invalid proxy server token passed401The key in OpenAI API Key is wrong, deleted or blocked.Paste the key again, or ask the admin for a new one.
Authentication Error, No api key passed in.401The key field is empty or the key is turned off in Cursor.Paste the key and turn it on.
Cursor API key not found. Add Cursor credentials via the UI (Models + Endpoints -> LLM Credentials) or set CURSOR_API_KEY environment variable.401The base URL ends in /cursor/v1, so chat requests went to the Cloud Agents pass-through instead of the editor route. When the gateway does hold a Cursor credential, Cursor's API answers with its own error instead.Set the base URL to https://gateway.example.com/cursor without /v1.
The requested model '<model>' is not available for this API key, or the model name is invalid.403The key may not use that model.Use a name from GET /cursor/models, or ask the admin to add the model to the key.
Invalid model name passed in model=<name>400No gateway model has that name. A typo, a different case, or a Cursor built-in name sent to the gateway.Type the custom model name exactly as GET /cursor/models lists it.
does not support parameters: <names>, for model=<model>400The model behind the name does not take a setting Cursor sent, such as reasoning effort.Pick a name without -thinking-, or ask the admin to set drop_params: true on the deployment, see drop params.
<route>: Missing required parameter: '<param>'.400The base URL is https://gateway.example.com/v1, so agent mode bodies reached the plain chat route, and the message names messages as missing.Use the /cursor base URL.
Budget has been exceeded! Key=<key alias> Current cost: <spend>, Max budget: <max>422The key's budget is used up.Wait for the reset, or ask the admin to raise Max Budget (USD).
Rate limit exceeded for <scope>: <value>. Limit type: <type>.429The key sent more requests or tokens per minute than its limit. Agent mode sends many requests in a row.Wait a minute, or ask the admin to raise the key's RPM or TPM.
Not Found404A typo in the path, such as /cursr.Copy the base URL from this page.
None, the verify step fails with no row on LogsnoneCursor's servers cannot reach the gateway, for example a localhost or private address, an IP allowlist without Cursor's servers, or a certificate from a company authority.Expose the gateway on a public HTTPS address with a publicly trusted certificate.

The client error reference lists every gateway error with its cause, and connect any client covers connection and certificate problems.

Troubleshooting​

  1. Run the curl from step 1 with the same key. If it answers 200, the key and the address are fine and the problem is in Cursor's settings, usually the base URL or a model name.
  2. Open Logs, filter by your Key Alias and the time of the failure. A row means the request reached the gateway, and the drawer shows the error text, the model the router picked and the provider's answer. No row means Cursor's servers never reached the gateway.
  3. For a wrong answer rather than an error, send the request with curl and -i as in Expected result and read x-spanway-model-id and x-spanway-routing-reason to see which deployment answered and why.
  4. On a test gateway, start it with --detailed_debug to log every request it receives, with the route and the key check result.
  5. Inside Cursor, the Output panel has a log per Cursor feature. For MCP, pick MCP Logs in its dropdown.

More symptoms and their fixes are in troubleshooting.

Gateway tools in Cursor (MCP)​

Cursor can also use the MCP servers registered on the gateway as tools. MCP connections are made by the editor on your computer, so for MCP the gateway only has to be reachable from your machine.

  1. Make sure the key may use the servers, see MCP access control. curl https://gateway.example.com/v1/mcp/tools -H "Authorization: Bearer $SPANWAY_API_KEY" lists the tools the key will see.

  2. Set the key in your environment, for example export SPANWAY_API_KEY=sk-... in your shell profile, and start Cursor from an environment that has it.

  3. Open ~/.cursor/mcp.json to use the tools in every project, or .cursor/mcp.json in one project, and add the entry below. Cursor replaces ${env:SPANWAY_API_KEY} with the variable's value. A bare $SPANWAY_API_KEY is not replaced, and the gateway answers 401.

    {
    "mcpServers": {
    "spanway": {
    "url": "https://gateway.example.com/mcp",
    "headers": {"Authorization": "Bearer ${env:SPANWAY_API_KEY}"}
    }
    }
    }
  4. Open the Customize page in Cursor and check that the spanway server is on. Its tools are listed as <server>-<tool>, for example jira-search_issues.

  5. In the Admin UI open MCP Servers, then Live Connections. Your session is listed with your key alias.

The /mcp address has no /v1. Use https://gateway.example.com/mcp/jira for one server only, or add the header "x-mcp-servers": "jira". The MCP clients page has the errors MCP clients show and how to fix them.

Rotate or remove the key​

To rotate, open the key in Virtual Keys, click Regenerate Key and set a Grace Period such as 24h, then paste the new key into OpenAI API Key in Cursor and into the SPANWAY_API_KEY variable, and restart Cursor so MCP reads the new value. Regenerating needs an Enterprise license. Without one, create a new key, switch Cursor to it and delete the old key. To stop Cursor's access at once, use Block Key in the key's actions menu.

To stop using the gateway in Cursor, turn off Override OpenAI Base URL and the OpenAI key in Models, and remove the spanway entry from mcp.json.