Apply the configuration, connect Claude Desktop to Kong, then send requests with and without the AI Consumer key and send a message from Claude Desktop.
The configuration creates an AI Model Provider with your Anthropic API key, a Key Auth AI Auth Strategy, an AI Consumer with an API key, a global Pre-Function Policy that moves a Bearer token to the apikey header, and a passthrough AI Model on /coding-agents-anthropic. A kongctl namespace scopes every resource, so you can remove this configuration without affecting anything else on the same AI Gateway. See the kongctl documentation for more on namespaces.
Adopt the quickstart AI Gateway into a kongctl namespace so that kongctl can manage it. Adoption adds the KONGCTL-namespace label to the AI Gateway:
kongctl adopt ai-gateway "${KONNECT_CONTROL_PLANE_NAME}" \
--namespace "${KONNECT_CONTROL_PLANE_NAME}" \
--pat "${KONNECT_TOKEN}"
Generate the AI Consumer’s API key. Claude Desktop sends this key to Kong instead of an Anthropic key. The credential’s api_key field is write-only, so its value must come from an environment variable:
export CONSUMER_API_KEY="coding-agents-demo-$(openssl rand -hex 8)"
Apply the configuration. The Anthropic credentials come from the prerequisites:
cat <<'EOF' > kong-recipe.yaml
_defaults:
kongctl:
namespace: coding-agents-claude-desktop-recipe
ai_gateway_model_providers:
- ref: coding-agents-anthropic-provider
ai_gateway: !lookup {id: !env 'AI_GATEWAY_ID'}
name: coding-agents-anthropic-provider
display_name: coding-agents-anthropic
type: anthropic
config:
auth:
type: basic
headers:
- name: x-api-key
value: !secret {source: !env 'ANTHROPIC_TOKEN'}
ai_gateway_auth_strategies:
- ref: coding-agents-key-auth
ai_gateway: !lookup {id: !env 'AI_GATEWAY_ID'}
name: coding-agents-key-auth
display_name: coding-agents key auth
type: key-auth
config:
key_names:
- apikey
- x-api-key
hide_credentials: true
ai_gateway_consumers:
- ref: coding-agents-consumer
ai_gateway: !lookup {id: !env 'AI_GATEWAY_ID'}
name: coding-agents-consumer
display_name: coding-agents demo consumer
type: api-key
credentials:
- ref: coding-agents-credential
name: coding-agents-credential
display_name: coding-agents demo API key
type: api-key
api_key: !secret {source: !env 'CONSUMER_API_KEY'}
ai_gateway_policies:
- ref: coding-agents-bearer-to-apikey
ai_gateway: !lookup {id: !env 'AI_GATEWAY_ID'}
name: coding-agents-bearer-to-apikey
display_name: coding-agents Bearer to apikey
type: pre-function
global: true
config:
rewrite:
- |
local auth = kong.request.get_header("Authorization")
if auth and string.sub(string.lower(auth), 1, 7) == "bearer " then
ngx.req.set_header("apikey", string.sub(auth, 8))
ngx.req.clear_header("Authorization")
end
ai_gateway_models:
- ref: coding-agents-anthropic
ai_gateway: !lookup {id: !env 'AI_GATEWAY_ID'}
name: coding-agents-anthropic
display_name: coding-agents (Anthropic managed)
type: model
formats:
- type: passthrough
capabilities:
- generate
access:
auth_strategies:
- coding-agents-key-auth
config:
max_request_body_size: 16777216
response_streaming: allow
logging:
payloads: true
route:
paths:
- /coding-agents-anthropic
protocols:
- http
- https
methods:
- POST
- OPTIONS
strip_path: true
targets:
- name: anthropic-api
provider: coding-agents-anthropic-provider
config:
version: !env 'ANTHROPIC_VERSION'
type: anthropic
upstream_url: https://api.anthropic.com/
EOF
kongctl apply -f kong-recipe.yaml -o text --auto-approve --pat "${KONNECT_TOKEN}"
rm -f kong-recipe.yaml
Claude Desktop reads its gateway settings from its third-party inference configuration, not from ANTHROPIC_BASE_URL. Print the AI Consumer key, which you enter as the Gateway API key:
echo "${CONSUMER_API_KEY}"
Set up Claude Desktop in its in-app configuration window:
- Launch Claude Desktop and don’t sign in. From the macOS menu bar, or the application menu (☰) on Windows, click Help > Troubleshooting > Enable Developer Mode.
- Click Developer > Configure Third-Party Inference.
- In Connection, set Inference provider to Gateway, then set the fields in the following table.
- Click Apply Changes, then click Save & Restart.
- On the sign-in screen, choose the option to start Claude Desktop with the configuration you entered.
Set the following fields in Connection:
|
Field
|
Value
|
|
Credential kind
|
Static API key
|
|
Gateway base URL
|
http://localhost:8000/coding-agents-anthropic. Don’t add /v1, because Claude Desktop adds /v1/messages.
|
|
Gateway API key
|
The value of CONSUMER_API_KEY. This is the AI Consumer key, not the organization’s Anthropic API key.
|
|
Gateway auth scheme
|
Bearer, the default. Kong also accepts x-api-key.
|
|
Model discovery
|
Off. The AI Model doesn’t serve GET /v1/models.
|
|
Model list
|
Add the full model ID claude-haiku-4-5-20251001. With discovery off, each entry must be a full model ID (Models).
|
If Claude Desktop shows Gateway was unreachable, it couldn’t reach the Gateway base URL at startup (Desktop app). Check that the data plane is running and that the URL matches the AI Model’s path.
Call the Messages API through Kong with the AI Consumer key as a Bearer token, the way Claude Desktop sends it with the default auth scheme:
curl -sS -X POST "http://localhost:8000/coding-agents-anthropic/v1/messages" \
-H "Content-Type: application/json" \
-H "anthropic-version: 2023-06-01" \
-H "Authorization: Bearer ${CONSUMER_API_KEY}" \
-d '{
"model": "claude-haiku-4-5-20251001",
"max_tokens": 32,
"messages": [{"role": "user", "content": "Reply with exactly: smoke-ok"}]
}'
Kong returns Anthropic’s Messages API response unchanged. The response looks similar to the following, with different IDs and token counts:
{
"id": "msg_01...",
"type": "message",
"role": "assistant",
"model": "claude-haiku-4-5-20251001",
"content": [
{
"type": "text",
"text": "smoke-ok"
}
],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 14,
"output_tokens": 6
}
}
To test the x-api-key scheme, send the same request with -H "x-api-key: ${CONSUMER_API_KEY}" instead of the Authorization header.
Send the same request without the Authorization header:
curl -sS -o /dev/null -w '%{http_code}\n' -X POST "http://localhost:8000/coding-agents-anthropic/v1/messages" \
-H "Content-Type: application/json" \
-H "anthropic-version: 2023-06-01" \
-d '{"model": "claude-haiku-4-5-20251001", "max_tokens": 32, "messages": [{"role": "user", "content": "hi"}]}'
Kong rejects the request before it reaches Anthropic:
Start a new chat with claude-haiku-4-5-20251001 selected and send Reply with exactly: desktop-ok. Claude Desktop replies with desktop-ok.
The requests and the Claude Desktop chat confirm the following:
|
Behavior
|
Evidence
|
|
Kong holds the Anthropic API key
|
The request with only the AI Consumer key gets a Messages API response from Anthropic. No Anthropic key is set on the client.
|
|
Bearer token authentication
|
The request with Authorization: Bearer succeeds, because the Pre-Function Policy moves the token to the apikey header.
|
|
AI Consumer authentication
|
The request without a key returns 401, and Anthropic never receives it.
|
|
Claude Desktop works through Kong
|
Claude Desktop replies desktop-ok with the Gateway base URL pointing at the AI Model.
|
To review the created entities and per-consumer usage, open the coding-agents-claude-desktop-recipe AI Gateway in Konnect. For traffic across all your AI Gateways, use the Observability menu.