Skip to main content

Claude Desktop through the gateway

Claude Desktop is Anthropic's desktop app for macOS and Windows, with Chat, Cowork and Code in one window. Two separate kinds of traffic can go through Spanway, and they are set up in different places. Model calls go through the gateway when the app runs in third-party inference mode with Spanway as its gateway, so every conversation uses the company's models, budgets and logs instead of a personal claude.ai plan. MCP tools go through the gateway when the app connects to the gateway's /mcp endpoint, so people get the company's approved tools, such as a Jira or docs server, with one key and every tool call logged.

The two are independent. A person signed in to claude.ai can use the gateway's MCP tools while their chats still go to Anthropic under their plan, and in that case only the tool calls show on the gateway. A fleet on third-party inference sends both through the gateway.

A real-world scenario​

A legal team of thirty people wants Claude Desktop, but the company only allows models through its own gateway, where prompts are logged and a guardrail removes client names. The admin turns on third-party inference for the team's laptops with one exported configuration file, pointing the app at https://gateway.example.com with a key per person, and adds the gateway's contracts search server as a managed MCP server. On the first launch the app opens straight into a chat on claude-sonnet-5-5, the contracts tools appear under Connectors, and the Logs page shows each conversation turn and each tool call under the person's key, with the guardrail result next to it.

Before you start​

  • Claude Desktop installed and updated. The third-party inference settings named here need a current release.
  • A gateway reachable from the person's computer over HTTPS. For a custom connector it must also be reachable from the public internet, see step 2.
  • For model calls, at least one model registered in Models + Endpoints. The app's model list only shows ids it recognizes as Claude, so serve Claude models under their Anthropic ids, such as claude-sonnet-5-5, or list the names yourself as shown in step 1.
  • For MCP tools, at least one MCP server registered on MCP Servers, see MCP gateway.

Make a key for Claude Desktop​

Make one key per person, so each person's spend and tool calls are separate and one key can be blocked without touching the others. Make a key for a tool has every field.

  1. Open Virtual Keys (/ui/api-keys) and click + Create New Key.
  2. Pick Another User and the person under Key Ownership, and set Key Name to something like maria-claude-desktop. Leave Key Type on AI APIs.
  3. In Models, pick every model the app may use. Claude Desktop's Code tab runs Claude Code, which can call a smaller background model, so include the model you serve for that tier, see Claude Code models.
  4. For MCP tools, pick the servers the person may use in the key's MCP server picker, or grant them as in MCP access control.
  5. Under Optional Settings, set Max Budget (USD) with Reset Budget monthly and a Requests per minute Limit (RPM), then click Create Key and copy the key.

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": "maria-claude-desktop", "key_type": "llm_api", "models": ["claude-sonnet-5-5", "claude-haiku-5-5"], "max_budget": 100, "budget_duration": "30d", "rpm_limit": 60}'

Steps​

1. Route model calls through the gateway​

The base URL is the gateway root, https://gateway.example.com, without /v1, because the app adds /v1/messages and /v1/models itself. The app does not read ANTHROPIC_BASE_URL or Claude Code's settings.json, it has its own configuration.

  1. In Claude Desktop open Help, Troubleshooting, Enable Developer Mode. The app restarts with a Developer menu.
  2. Open Developer, Configure Third-Party Inference….
  3. In the Connection section set Inference provider to Gateway. In the Gateway credentials card set Gateway base URL to https://gateway.example.com, paste the key into Gateway API key, leave Credential kind on Static API key and Gateway auth scheme on Bearer. The gateway also accepts x-api-key.
  4. Leave the model list empty to let the app fill it from the gateway's GET /v1/models, or list the exact gateway names when a model does not appear.
  5. Apply the configuration, quit the app fully and open it again. Send a message in Chat.

To set up many machines, click Export in the same window. It writes a .mobileconfig file for macOS or a .reg file for Windows that you push with your device management tool, and a configuration pushed that way makes the form read-only on the machine. The keys it carries are:

{
"inferenceProvider": "gateway",
"inferenceGatewayBaseUrl": "https://gateway.example.com",
"inferenceGatewayApiKey": "sk-your-spanway-key",
"inferenceGatewayAuthScheme": "bearer",
"inferenceModels": ["claude-sonnet-5-5", {"name": "claude-opus-5-5", "supports1m": true}]
}

inferenceModels replaces discovery with your own list, and the first entry is the default model. A key in a configuration file is a shared secret on every machine that gets the file, so for a fleet prefer one file per person, or the app's credential helper (inferenceCredentialHelper), which runs a command that prints the key at runtime. The app can also sign each person in with the company identity provider and send that token instead of a key, which the gateway accepts when JWT authentication is set up for the same provider.

2. Add the gateway's MCP tools​

Pick one of three ways. Each gives the app every tool the key may use from https://gateway.example.com/mcp, or one server's tools from https://gateway.example.com/mcp/<server name>.

A. Custom connector, for people signed in to claude.ai. On Pro and Max plans open Customize, Connectors, click + Add, then Add custom connector. On Team and Enterprise plans an owner adds it under Organization settings, Connectors, Add, Custom, Web, and members then turn it on under Customize, Connectors.

  1. Enter a name such as Company tools and the URL https://gateway.example.com/mcp, then click Continue.
  2. Under Request headers, add Authorization with the value Bearer sk-your-spanway-key. To have people sign in through the gateway's own login instead of pasting a key, leave the headers out and use the gateway's OAuth sign-in. If you register your own OAuth client for the connector, its redirect URL is https://claude.ai/api/mcp/auth_callback.
  3. Click Add. In a chat, turn the connector on from the + button, Connectors.

Custom connectors are called from Anthropic's cloud, not from the person's computer, even in the desktop app. The gateway's /mcp address must therefore be reachable from the public internet on port 443 with a certificate from a public authority. A gateway on localhost, on a private network, behind a VPN or on another port such as :4000 cannot be added this way. Use option B for those.

B. mcp-remote in the configuration file, for a private or local gateway. The app's own configuration file only starts local programs, so a small bridge, mcp-remote, runs on the computer and talks to the gateway over HTTPS. This works for any gateway the computer can reach, including http://localhost:4000. It needs Node.js on the computer.

  1. Open Settings, Developer, Edit Config. The file is ~/Library/Application Support/Claude/claude_desktop_config.json on macOS and %APPDATA%\Claude\claude_desktop_config.json on Windows.

  2. Add the gateway under mcpServers. The key goes in env, which the app passes to the bridge, and the header is written without a space after the colon because the app on Windows does not quote spaces inside args:

    {
    "mcpServers": {
    "spanway": {
    "command": "npx",
    "args": ["-y", "mcp-remote@0.16.5", "https://gateway.example.com/mcp", "--header", "Authorization:${SPANWAY_AUTH_HEADER}"],
    "env": {"SPANWAY_AUTH_HEADER": "Bearer sk-your-spanway-key"}
    }
    }
    }

    Pin the bridge's version, as above, so a new release never runs on the computer unreviewed. For a gateway on the same computer use http://localhost:4000/mcp. mcp-remote accepts plain HTTP only on loopback, and refuses it elsewhere unless you add --allow-http, which you should use only on a trusted private network.

  3. Quit Claude Desktop fully and open it again. Click the + button in a chat, open Connectors and check that spanway is listed with its tools.

C. Managed MCP servers, for a fleet on third-party inference. The same configuration window and exported file from step 1 carry a managedMcpServers list, which pushes the gateway to every machine as a remote server. Use the HTTPS address and a header helper, a command that prints the key header as JSON such as {"Authorization": "Bearer sk-..."}, rather than putting the key in plain configuration:

{
"managedMcpServers": [
{"name": "spanway", "transport": "http", "url": "https://gateway.example.com/mcp", "headersHelper": "/usr/local/bin/spanway-mcp-header"}
]
}

Give the final address, because the app does not follow redirects for this entry.

Expected result​

For model calls, a message in Chat gets a normal answer, the model picker shows the gateway's Claude models, and the Logs page (/ui/logs) shows each turn under the person's key alias with the model, the deployment that served it, tokens and cost. The answer carries the x-spanway-call-id, x-spanway-model-group and x-spanway-response-cost headers, which the drawer on Logs shows for the same row, see routing headers.

For MCP tools, the connector or the spanway entry lists the tools namespaced as <server>-<tool>, for example jira-search_issues. Claude asks for approval before it calls a tool, unless you allowed it. On the gateway, MCP Servers, Live Connections lists the session with the client name and version it reported, the user and the key alias, and each tool call shows on Logs against the key. A quick check of what the key will see, from a terminal:

curl https://gateway.example.com/v1/mcp/tools -H "Authorization: Bearer sk-your-spanway-key"

Streaming, tools, images, caching and reasoning​

Claude Desktop needs POST /v1/messages with streaming and tool use, which the gateway serves for every model behind a public name, and it uses GET /v1/models to fill the picker when no model list is set. For deployments on Anthropic the gateway forwards the request in native form, so prompt caching, thinking, images and the long context window work unchanged. Chat, Cowork and Code send cache_control markers on every turn, and a provider without prompt caching bills each turn as full input. The app assumes a 200,000 token window for a model id it does not recognize, so a long conversation on such a name is compacted early. Mark a long context model with supports1m in inferenceModels only when the deployment accepts one million tokens. The Code tab runs Claude Code, so the request field clashes and switches in Claude Code features apply there too.

Errors​

What Claude Desktop showsCauseFix
Gateway was unreachable at startupThe app could not reach the Gateway base URL. Nothing reaches the gateway.Check the address from a terminal on the same computer with curl https://gateway.example.com/health/liveliness, and check the VPN and proxy.
A credentials card, such as Credentials rejected, and 401 on Logs with Authentication Error, Invalid proxy server token passedThe key in Gateway API key is wrong, deleted or blocked.Paste the key again, or ask the admin for a new one.
A permissions card, and 403 on Logs with The requested model '<model>' is not available for this API key, or the model name is invalid.The key may not use that model, often a background or second model the app or the Code tab asked for.Add the model to the key.
Invalid request in Code or a general error card, and 400 on Logs with Invalid model name passed in model=<name>The app sent a name no deployment carries, often a name typed into inferenceModels with the wrong case or a /v1 at the end of the base URL.Use names exactly as GET /v1/models lists them, and the bare root as the base URL.
A general error card, and 422 on Logs with Budget has been exceeded! Key=<key alias> Current cost: <spend>, Max budget: <max>The key, team or user spent its budget.Wait for the reset or raise Max Budget (USD).
Server is temporarily limiting requests after a few minutesThe key is over its rate limit, 429 with Rate limit exceeded for <scope>: <value>. Limit type: <type>. on Logs. The app retries for about three minutes first.Raise the RPM limit or wait.
The model picker is empty or misses modelsGET /v1/models lists no id the app recognizes as Claude, or the key has no models.Serve Claude models under their Anthropic ids, or list the gateway names in inferenceModels.
SSL certificate verification failed (UNABLE_TO_VERIFY_LEAF_SIGNATURE) in Chat or CoworkThe gateway does not send its intermediate certificate, or uses a private authority the computer does not trust. Nothing reaches the gateway.Serve the full certificate chain from the gateway or its load balancer, and install the company root certificate on the computer. Check with openssl s_client -connect gateway.example.com:443 -servername gateway.example.com -showcerts </dev/null.
The custom connector cannot be added or never connectsThe gateway is not reachable from the public internet on port 443, or uses a private certificate.Expose /mcp on a public HTTPS address, or use option B for a private gateway.
spanway is missing from Connectors after editing the fileThe JSON is invalid, the app was not fully quit, or npx is not on the computer.Check the file, quit and reopen the app, and read the logs under troubleshooting.
The bridge log shows 401 with the literal text ${SPANWAY_AUTH_HEADER}The env block is missing or the variable name in args does not match it.Make the two names match exactly.
403 on the MCP connection, and the gateway log reads Rejected MCP request from a disallowed client applicationThe admin restricted which MCP clients may connect, and this client is not on the list.Add the client on MCP Servers, Network Settings, see MCP access control.
The connector lists no toolsThe key has no grant for any server, or the server's allowed tools leave nothing.Grant the server to the key. The GET /v1/mcp/tools check above shows what the key gets.
404 with mcp-session-id was terminated by an administrator. Send initialize to start a new session.An admin closed the session on Live Connections.Turn the connector off and on, or restart the app.

The client error reference lists every gateway error text with its status.

Troubleshooting​

  1. Check the gateway side first. Run the GET /v1/mcp/tools check for tools, or a one token POST /v1/messages as in the Claude Code steps for models, with the same key from the same computer. If those work, the problem is the app's configuration.
  2. Open Logs on the gateway and filter Key Alias by the person's key. A row with an error gives the status and the gateway's message, which you can match in errors. No row means the request never arrived, so check the address, TLS and the network.
  3. Read the app's MCP logs. On macOS run tail -n 20 -f ~/Library/Logs/Claude/mcp*.log. On Windows the logs are in %APPDATA%\Claude\logs. Each MCP entry has its own mcp-server-<name>.log.
  4. For the mcp-remote bridge, add --debug to its args. It writes a detailed log to ~/.mcp-auth/<hash>_debug.log. Deleting ~/.mcp-auth clears a stuck sign-in.
  5. On MCP Servers, Live Connections, look for the session. No session means the client never finished connecting.

Rotate or remove the key​

  1. In Virtual Keys, open the key, click Regenerate Key with a Grace Period such as 24h, and copy the new key. Without an Enterprise license, create a new key and delete the old one afterwards.
  2. Put the new key in each place it is used: Gateway API key in the third-party inference window or the exported configuration file, the connector's Request headers, the env block of claude_desktop_config.json, or what your header helper prints.
  3. Quit and reopen the app and send one message. The new key shows on Logs.

To take the app off the gateway, set Inference provider back or remove the pushed configuration, and remove the connector or the spanway entry. To cut a person off at once, click Block Key in the key's actions menu.