For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Claude Desktop
Configure Claude Desktop to use agentgateway
Configure Claude Desktop to route requests through your agentgateway proxy.
About third-party inference mode
Claude Desktop sends model traffic to Anthropic by default. Third-party inference mode changes that destination to an endpoint that you operate, such as an agentgateway proxy. Anthropic made this mode generally available on July 9, 2026.
Anthropic designed the mode for organizations whose security, regulatory, or contractual requirements prevent them from sending data to Anthropic’s first-party infrastructure. Prompts, responses, files, and tool outputs go only to the endpoint that you configure, and conversation history stays on the user’s device. You can create an agentgateway proxy at that endpoint, so that every Claude Desktop request passes through your policies for authentication, guardrails, rate limits, and observability before it reaches a model.
Keep the following behavior in mind:
- One setting covers the whole Claude Desktop app. Chat, Cowork, and Code all send inference to the endpoint that you configure.
- Claude Desktop reads its configuration once, at launch. After you change a setting, fully quit the app and reopen it.
- The gateway URL must use HTTPS unless it is a loopback address. A plain HTTP URL on any other host fails validation with the error
Invalid custom3p enterprise config: baseUrl: must use https (or http on loopback). - Managed configuration wins. When an administrator delivers settings through mobile device management (MDM), users cannot override them.
For the full list of settings, see the Claude Desktop configuration reference.
The steps in this guide run agentgateway on the same machine as Claude Desktop and use the loopback address 127.0.0.1, so no certificate is needed. To point Claude Desktop at an agentgateway proxy on another host, serve the proxy over HTTPS. For more information, see HTTPS listeners.
Before you begin
- Install the
agentgatewaybinary. Install Claude Desktop.
Choose how the proxy authenticates callers.
Method When to use Upstream billing Gateway API key Recommended starting point. Agentgateway validates a client key and adds a separately managed Anthropic API key upstream. Anthropic API account Identity provider Recommended for an enterprise rollout. Agentgateway validates each user’s OIDC token and adds a separately managed Anthropic API key upstream. Anthropic API account Claude subscription passthrough Advanced option for preserving per-user Claude subscription usage. Agentgateway passes each user’s token upstream and does not independently authenticate the caller. User’s Claude subscription For a gateway API key, configure an LLM model and a virtual API key in agentgateway. For subscription passthrough, you need a Claude Pro, Max, Team, or Enterprise subscription and the Claude Code CLI, which provides the
claude setup-tokencommand. For identity-provider authentication, you need an OIDC provider and an Anthropic API key for the proxy to send upstream.
Use Client Setup with a gateway API key
Tip
If you manage models and virtual API keys in the standalone UI, Client Setup can generate the connection settings or snippet for this client. Review the gateway URL, select a model and key, choose the client from the Integration dropdown, and copy the recipe. Each recipe uses only the values that its client supports.
Client Setup generates client-side values from existing configuration. It does not create a route, model, authentication policy, virtual key, or provider credential. Follow the steps in this guide to configure those prerequisites or to set up the client manually.
For Claude Desktop, Client Setup outputs the gateway URL and API key; it does not configure a model name in Claude Desktop. The gateway route must already accept the key and support the Anthropic Messages API at /v1/messages, and agentgateway must hold the upstream provider credential. An endpoint that exposes only the OpenAI-compatible /v1/chat/completions API is not sufficient. For more information about the UI, see UI.
For a managed rollout, see Manage gateway API keys with Microsoft Intune.
To preserve per-user subscription billing instead of using a gateway API key, continue with the following advanced configuration.
Optional: Use Claude subscription passthrough
Start agentgateway with the Teams configuration. Agentgateway listens on port 4001 and exposes Claude at the /claude path.
Create a configuration file.
cat > config.yaml << 'EOF' gateways: default: port: 4001 protocol: HTTP routes: - name: claude-agent matches: - path: pathPrefix: /claude policies: urlRewrite: path: prefix: / backends: - ai: name: claude-agent provider: anthropic: {} policies: ai: routes: /v1/messages: messages /v1/messages/count_tokens: anthropicTokenCount '*': passthrough EOFStart agentgateway.
agentgateway -f config.yaml
The backend deliberately has no backendAuth policy. In subscription mode,
the bearer token that each user creates with claude setup-token must pass
through agentgateway to Anthropic. Do not add a provider API key or apply a
virtual API key policy to this route.
Note
Claude Code automatically sends the anthropic-beta: oauth-2025-04-20 header required for OAuth-based authentication. Claude Desktop may require this header to be set as well depending on your client version. If requests fail with a 400 error, add the following to the passthrough route policy in your config:
policies:
requestHeaderModifier:
add:
anthropic-beta: oauth-2025-04-20Configure Claude Desktop with a Claude subscription
Get a bearer token for your Claude account.
claude setup-tokenCopy the token printed to the terminal.
Open Claude Desktop and enable developer mode: Help → Troubleshooting → Enable Developer Mode. Then fully quit and relaunch Claude Desktop. A new Developer menu appears in the menu bar.
In the menu bar, go to Developer → Configure Third Party Inference → Gateway.
Enter the gateway URL. Use
127.0.0.1rather thanlocalhost.http://127.0.0.1:4001/claudeFor Credential kind, select Static API key. For Gateway auth scheme, select Bearer, and enter the token from step 1 in Gateway API key. Each user must use their own subscription token. To authenticate users with your identity provider and use a centrally managed provider credential instead, see Authenticate users with your identity provider.
Open Models and add at least one full model ID that the subscription can use, such as
claude-opus-5. Do not use an alias such asopus. The first entry is the default. Turn off Model discovery, or leave it unset; an explicit model list makes discovery unnecessary.Click Test connection. Claude Desktop tests inference with the first configured model. If no explicit model is configured, the test first calls
<base-url>/v1/modelsand fails when the gateway or provider does not make that endpoint available to the subscription token.Note
With subscription passthrough, the connection test might return HTTP 429 with
rate_limit_erroreven when normal Cowork inference works. Apply the configuration, send a harmless prompt, and check the agentgateway request log. If the actual/v1/messagesrequest returns HTTP 200, treat the connection-test result as a false negative.Click Apply Changes, then fully quit Claude Desktop and reopen it. Claude Desktop reads its configuration only at launch.
Note
On macOS, Claude Desktop might not enter third-party inference mode from the settings panel alone. If the app still signs in to Anthropic after you reopen it, set
deploymentModeto3pin the third-party configuration file, then quit and reopen the app again.python3 - <<'EOF' import json, os p = os.path.expanduser('~/Library/Application Support/Claude-3p/claude_desktop_config.json') d = json.load(open(p)) d['deploymentMode'] = '3p' open(p, 'w').write(json.dumps(d, indent=2)) EOF
For a managed rollout of this subscription configuration, see Manage Claude subscriptions with Microsoft Intune.
Authenticate users with your identity provider
If you distribute one static API key to every user, you cannot attribute requests to a person or revoke access for only one user. Instead, select the Interactive sign-in credential kind. Claude Desktop then runs an OAuth 2.0 authorization code flow with Proof Key for Code Exchange (PKCE) against your identity provider and sends the resulting token on every inference request. Agentgateway validates the token and adds the LLM provider credential itself, so the user’s device never holds a provider API key.
The interactive sign-in flow is the same for standalone and Kubernetes deployments. Only the agentgateway configuration differs: standalone configures JWT validation directly on the route, whereas Kubernetes uses an AgentgatewayPolicy and an AgentgatewayBackend for the JWKS endpoint.
sequenceDiagram
participant C as Claude Desktop
participant B as Browser or OS broker
participant E as Microsoft Entra ID
participant G as agentgateway
participant A as Anthropic
alt Browser flow for initial testing
C->>B: Open the system browser
B->>E: Authorization request with PKCE challenge
E-->>C: Authorization code through loopback callback
C->>E: Exchange code and PKCE verifier
E-->>C: ID token
else Broker flow for managed production devices
C->>B: Request an identity token
B->>E: Authenticate the user and device
E-->>B: ID token
B-->>C: ID token
end
C->>G: Inference request with bearer ID token
G->>E: Fetch and cache signing keys
G->>G: Validate signature, issuer, and audience
G->>A: Inference request with provider credential
A-->>G: Model response
G-->>C: Model response
The OAuth callback returns to Claude Desktop, not to agentgateway. The gateway hostname is the inference endpoint and must not be registered as the OAuth redirect URI.
After you disable or offboard a user, the identity provider prevents new sign-ins and token refreshes. An ID token that was already issued can remain valid until it expires, depending on the identity provider’s revocation and session policies.
The following steps use Microsoft Entra ID as the example identity provider. Any OpenID Connect (OIDC) provider works the same way. Substitute your own issuer URL, client ID, and JWKS URL.
Register a public-client application with your identity provider, and record the client ID and issuer URL. Do not create a client secret. The following values configure Claude Desktop’s browser flow.
Setting Value Client type Public client. Claude Desktop holds no client secret. Redirect URI http://127.0.0.1/callbackScopes openid profile email offline_accessImportant
Two details about the redirect URI cause most failures:
- Include the
/callbackpath. Claude Desktop redirects tohttp://127.0.0.1:<port>/callback, and a registration ofhttp://127.0.0.1alone does not match. On Entra ID, the mismatch returnsAADSTS50011. - Register the URI as a native or desktop client, not a web client. Claude Desktop picks an ephemeral port for each sign-in. A native client registration accepts any loopback port, as described in RFC 8252, and a web client registration requires an exact port match. On Entra ID, select the Mobile and desktop applications platform. The browser and broker authorization-code flows do not require the legacy Allow public client flows toggle; leave it disabled.
- Do not register the agentgateway hostname as the redirect URI. Claude Desktop receives the authorization response, then sends the resulting token to the gateway URL on inference requests.
- Include the
Save the identifiers from your registration and your Anthropic API key, so that agentgateway can resolve them. Agentgateway reads variable references in the configuration file from the environment at startup.
export TENANT_ID=<your-tenant-id> export CLIENT_ID=<your-client-id> export ANTHROPIC_API_KEY=<your-anthropic-api-key>Update your configuration file to validate the token on the route and to send an Anthropic API key upstream. Interactive sign-in puts the identity provider token in the
Authorizationheader, so the proxy must supply the provider credential itself rather than pass a user token upstream. Replace any client API key authentication on this route instead of requiring both authentication methods.cat > config.yaml << 'EOF' # yaml-language-server: $schema=https://agentgateway.dev/schema/config gateways: default: port: 4001 protocol: HTTP routes: - name: claude-agent matches: - path: pathPrefix: /claude policies: urlRewrite: path: prefix: / jwtAuth: mode: strict issuer: https://login.microsoftonline.com/$TENANT_ID/v2.0 audiences: - $CLIENT_ID jwks: url: https://login.microsoftonline.com/$TENANT_ID/discovery/v2.0/keys backends: - ai: name: claude-agent provider: anthropic: {} policies: backendAuth: key: "$ANTHROPIC_API_KEY" ai: routes: /v1/messages: messages /v1/messages/count_tokens: anthropicTokenCount '*': passthrough EOFReview the following table to understand this configuration.
Setting Description jwtAuth.modeSet to strictso that agentgateway rejects any request that has no valid token. The default value,optional, admits requests that carry no token at all.jwtAuth.issuerThe expected issclaim. Validating the issuer alongside the signature is what ties a token to your tenant.jwtAuth.audiencesThe expected audclaim. For an ID token, the audience is the client ID of the application that you registered.jwtAuth.jwks.urlThe JWKS endpoint that agentgateway fetches signing keys from. backendAuth.keyThe Anthropic API key that agentgateway sends upstream. Because the user token authenticates the caller, this credential no longer comes from the client. Use the issuer base URL shown in the example. Do not use the OpenID discovery-document URL, which ends in
/.well-known/openid-configuration, as the issuer.For more detail on JWT validation, see JWT authentication.
Restart agentgateway to load the new configuration.
agentgateway -f config.yamlIn Claude Desktop, go to Developer → Configure Third Party Inference → Gateway and set the following fields.
Field Value Credential kind Interactive sign-in Gateway base URL http://127.0.0.1:4001/claudeClient ID The client ID of the application that you registered Issuer URL https://login.microsoftonline.com/$TENANT_ID/v2.0Bearer token ID token Scopes openid profile email offline_accessSign-in flow Browser for this initial test; use the Intune guide to move managed devices to Broker Model discovery Off when you use a fixed model list Models One or more full model IDs that the backend exposes Warning
Set the bearer token type to ID token. With the access token setting, Entra ID returns a Microsoft Graph token that validation against your tenant JWKS rejects with
InvalidSignature. The ID token carries the client ID as its audience, which matches the configured audience.From Claude Desktop, click Test connection. Then click Apply Changes, fully quit Claude Desktop, and reopen it. A browser window opens to your identity provider. After you sign in, send a real prompt and confirm a successful
POST /v1/messagesrequest in the agentgateway logs. The request must return HTTP 200 and includejwt.subfor the signed-in user. This confirms that Claude Desktop sent the Entra ID token and that agentgateway validated it before forwarding the request.
Send custom headers
Use the Custom inference headers field to add a header to every inference request, such as a tenant identifier that a route or a policy matches on. Claude Desktop sends these headers on requests from Chat, Cowork, and Code alike.
To supply a header value that changes over time, set a credential helper instead. A credential helper is an executable that Claude Desktop runs with no arguments and that prints either a bare token or a JSON object in the form {"token": "...", "headers": {"Name": "Value"}}. Claude Desktop caches the result and re-runs the helper when the cache expires, with no prompt and no relaunch. Helper headers override custom inference headers of the same name, and a configured helper replaces any static API key. Use a helper to read a short-lived credential from a secret store.
Roll out to your organization
Configure and test one machine in developer mode first. When the connection works, click Export in the Configure Third Party Inference panel to produce a profile for your device management system, and distribute it with the tool that you already use, such as Jamf, Intune, Workspace ONE, or Group Policy. Users then receive the configuration on first launch and do not configure anything by hand.
For an end-to-end Microsoft Intune rollout with Entra ID and managed-device enforcement, see Manage Claude Desktop with Microsoft Intune.
Managed configuration takes precedence over local settings, so a user cannot point the app at a different endpoint. The delivery mechanism differs per operating system.
| Operating system | Managed configuration |
|---|---|
| macOS | A configuration profile that writes /Library/Managed Preferences/<user>/com.anthropic.claudefordesktop.plist |
| Windows | Registry values under HKLM\SOFTWARE\Policies\Claude, which override any values under HKCU |
| Linux | A root-owned /etc/claude-desktop/managed-settings.json file that is not writable by group or other |
The following example shows the Linux form. On macOS and Windows, write every value as a string, including numbers, booleans, and nested JSON.
{
"inferenceProvider": "gateway",
"inferenceGatewayBaseUrl": "https://agentgateway.example.com/claude",
"inferenceCredentialKind": "interactive",
"inferenceGatewayOidcAuthFlow": "browser",
"inferenceGatewayOidc": {
"issuer": "https://login.microsoftonline.com/$TENANT_ID/v2.0",
"clientId": "$CLIENT_ID",
"scopes": "openid profile email offline_access",
"bearerTokenType": "id_token"
},
"modelDiscoveryEnabled": false,
"inferenceModels": ["claude-opus-5"],
"inferenceCustomHeaders": {
"X-Tenant-Id": "acme"
}
}For every available key and for the per-region profiles that a multi-region deployment needs, see the Claude Desktop configuration reference.
Verify the connection
Send a message in Claude Desktop. If the connection is successful, responses flow through your agentgateway proxy and appear in the terminal where agentgateway is already running.
Look for log entries like the following in your running agentgateway output:
info request gateway=default/default listener=http route=claude-agent endpoint=api.anthropic.com:443 http.method=POST http.path=/v1/messages http.status=200 protocol=llmIf you configured gateway API key or OIDC authentication in strict mode, send a request without the Authorization header and confirm that agentgateway rejects it. This negative check verifies that the route does not admit unauthenticated requests.
Troubleshoot the connection
| Symptom | Likely cause and action |
|---|---|
The connection test calls an unexpected path such as /claude/claude/v1/models | Make the base URL match the route prefix exactly. Claude Desktop appends /v1/models and /v1/messages. |
| The gateway API key connection returns HTTP 401 | Confirm that Claude Desktop sends the client key generated by Client Setup and that the route is protected by the matching virtual-key policy. |
Entra sign-in returns api key authentication failure | The Claude Desktop route still requires its old virtual API key. Replace that authentication with JWT validation; do not require both. |
Entra Test connection succeeds, but restart logs InvalidToken | An older managed profile restored a static key. Update the assigned profile to interactive, remove inferenceGatewayApiKey, sync the device, and fully restart Claude Desktop. |
A subscription request logs api key authentication failure | A virtual API key policy is protecting the subscription route. Remove it from this route so that the subscription bearer token can pass upstream. |
The test needs at least one model after /v1/models fails | Add a full model ID under Models and disable or skip model discovery. |
Anthropic returns authentication_error in gateway API key or OIDC mode | Confirm that the backend holds a valid Anthropic API key. |
Anthropic returns authentication_error in subscription mode | Generate a new token with claude setup-token, confirm that the auth scheme is Bearer, and make sure the backend does not inject a provider API key. |
| Anthropic returns HTTP 400 in subscription mode | Add or forward anthropic-beta: oauth-2025-04-20 as described in Configure agentgateway with a Claude subscription. |
| The subscription connection test returns HTTP 429, but a normal prompt succeeds | The connection test can produce a false negative with subscription passthrough. Confirm that the real /v1/messages request returns HTTP 200 in the agentgateway log, and use actual inference as the final validation. |
Normal inference returns HTTP 429 with rate_limit_error | The request reached Anthropic, but the subscription or API account might be at a usage limit or temporarily throttled. Check the applicable Anthropic usage dashboard or Claude usage indicator, wait for the reset, or choose an available model. See the Claude error reference. |
| No request appears in the agentgateway output | Check the base URL, agentgateway process, certificate for a remote host, DNS, and network path. |