Feat(aigw): v2 azure claude cli#5948
Conversation
✅ Deploy Preview for kongdeveloper ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
Adds a new v2 AI Gateway how-to that walks users through routing Claude Code (Claude CLI) traffic through Kong AI Gateway to an Azure-hosted Anthropic model using kongctl.
Changes:
- Introduces a new how-to page for configuring an AI Model Provider (Azure) and AI Model, then running Claude Code via
ANTHROPIC_BASE_URL. - Provides example
kongctl applymanifests for the provider and model entities. - Includes a basic “verify traffic” section using a Claude Code session prompt and sample query.
|
Replicated this how-to end-to-end against Azure AI Foundry Claude — the config as written doesn't work; here are the fixes, all validated live (Claude Code → Kong → Azure Foundry Claude returning The core issue: Foundry Claude is a native Anthropic MaaS endpoint, not Azure-OpenAI — so the 🔴 Blockers1. Env-var names don't match between the export steps and the config. 2. Wrong provider driver + endpoint. 3. Wrong auth header + missing version header. Foundry Claude authenticates with 4. No beta-field strip → real Claude Code sessions 400. Claude Code sends beta body fields ( 🟡 Minor
✅ Validated drop-in for steps 6–9Env vars (one consistent set, used in both the exports and the export AZURE_AI_FOUNDRY_TOKEN='<your Azure AI Foundry API key>'
# BASE MaaS endpoint — ends at /anthropic, NO /v1/messages:
export AZURE_AI_FOUNDRY_UPSTREAM_URL='https://<your-resource>.services.ai.azure.com/anthropic'Provider (Anthropic driver → Foundry MaaS): ai_gateway_model_providers:
- ref: azure-claude
name: azure-claude
ai_gateway: ai-quickstart
type: anthropic # Foundry Claude is native Anthropic MaaS, not Azure-OpenAI
config:
auth:
type: basic
headers:
- name: x-api-key # Foundry MaaS Claude authenticates with x-api-key
value: !env AZURE_AI_FOUNDRY_TOKENRequest-compat policy (mandatory ai_gateway_policies:
- ref: claude-code-compat
name: claude-code-compat
ai_gateway: ai-quickstart
type: request-transformer-advanced
enabled: true
global: false
config:
add:
headers: ["anthropic-version:2023-06-01"] # REQUIRED — Foundry 400s without it
remove:
headers: [anthropic-beta]
querystring: [beta]
body: [output_config, context_management, mcp_servers, container, service_tier]Model: ai_gateway_models:
- ref: claude-code-azure-sonnet
name: claude-code-azure-sonnet # the value passed to `claude --model`
ai_gateway: ai-quickstart
type: model
enabled: true
formats: [{ type: anthropic }]
config:
route: { paths: [/] }
model: { name_header: true }
capabilities: [generate]
policies: [ !ref claude-code-compat#name ]
targets:
- name: claude-sonnet-4-6 # the real Foundry Claude model
provider: azure-claude
config:
type: anthropic
upstream_url: !env AZURE_AI_FOUNDRY_UPSTREAM_URL # base .../anthropicVerify (unchanged): ANTHROPIC_BASE_URL=http://localhost:8000/ claude --model 'claude-code-azure-sonnet'Happy to pair on the rewrite. (Validated against the shared |
felderi
left a comment
There was a problem hiding this comment.
Validation feedback — I ran this config end-to-end on an AI Gateway 2.0 dev build (Claude Code → local DP → Kong → Azure AI Foundry Claude, returning 200 with real Claude responses). The provider-shape fixes from the Slack thread have landed (type: anthropic, x-api-key, the anthropic-version header, display_name) 👍. A few things still block a clean, from-scratch run:
1. (Breaking) The three separate kongctl apply blocks break the model's policy !ref. The AI Model apply references policies: [ !ref claude-code-compat#name ], but claude-code-compat is created in a different apply and isn't re-declared in the model apply — so this fails with resource not found: claude-code-compat (the exact error hit during testing). !ref only resolves within a single apply. Two fixes:
- Combine provider + policy + model into one
kongctl apply(simplest), or - Re-declare the policy (and provider) in the model apply via
_externalselectors, the way the Bedrock how-to (#5942) does.
2. Prereq env vars don't match the config. prereqs/azure-ai-claude.md exports DECK_AZURE_INSTANCE_NAME / DECK_AZURE_OPENAI_API_KEY / DECK_AZURE_DEPLOYMENT_ID, but the config reads !env AZURE_AI_FOUNDRY_TOKEN and !env AZURE_AI_FOUNDRY_UPSTREAM_URL. A reader following the prereqs ends up with empty values, and AZURE_AI_FOUNDRY_UPSTREAM_URL is never set or documented anywhere.
3. Document the upstream URL format — this is the non-obvious bit. It must be the base endpoint ending at /anthropic, with no /v1/messages (the driver appends that):
export AZURE_AI_FOUNDRY_UPSTREAM_URL='https://<resource>.services.ai.azure.com/anthropic'Verified: a raw curl to .../anthropic/v1/messages with x-api-key + anthropic-version: 2023-06-01 returns 200.
4. The provider prose is stale. Under "Configure an AI Model Provider," the bullets still describe the old Azure-OpenAI driver — type: azure, name: azure-anthropic, config.instance — none of which match the actual config (type: anthropic, name: azure-claude, no instance).
5. Terminology. Title/description/prereqs say "Azure OpenAI," but this targets Claude on Azure AI Foundry — a native Anthropic MaaS endpoint, not Azure-OpenAI. That framing is exactly what led to the wrong type: azure shape originally; worth correcting so readers don't re-derive the mistake.
6. Add a "validate directly" step (like the Bedrock doc's) that curls the Foundry endpoint bypassing Kong first — it isolates credential/deployment problems from gateway problems in a single command, which would have short-circuited most of the debugging in the thread.
Minor: drop the DECK_ prefixes throughout (this how-to uses kongctl, not decK).
Squashes: init content, init content, initial config, copilot fixes, Fel fixes, Fel fixes, works. Drops an accidental app/.repos/kuma submodule pointer regression (4d676877 -> a92a32a8) that crept into "init content" and persisted through every later commit on this branch.
4d5d410 to
9abe837
Compare
Co-authored-by: Diana <75819066+cloudjumpercat@users.noreply.github.com>
|
manually approving links, the broken one is not even in this PR, it's in an include |
109720c
into
release/ai-gateway-2.0
felderi
left a comment
There was a problem hiding this comment.
One addition to my earlier review — gateway ownership. The provider/policy/model applies here fully declare the gateway:
ai_gateways:
- ref: ai-quickstart
name: ai-quickstart
display_name: "ai-quickstart"Since ai-quickstart's control plane and data plane are created and owned by the AI quickstart/bootstrap script, kongctl should reference it link-only and manage just the children — not try to own the gateway. Switch each block to _external:
ai_gateways:
- ref: ai-quickstart
_external:
selector:
matchFields:
name: ai-quickstartThis matches the pattern in the Bedrock how-to (#5942) and the note on the Vertex how-to (#5952) — keeping all three "Claude Code with X" docs consistent. (Fully declaring it would make kongctl contend with the script for the gateway's lifecycle.)
Everything in my original review still stands (cross-apply !ref, the DECK_AZURE_* vs AZURE_AI_FOUNDRY_* env mismatch + undocumented upstream URL, the stale type: azure/config.instance prose, and the "Azure OpenAI" vs Foundry-Claude terminology).
Description
Fixes #issue
Preview Links
https://deploy-preview-5948--kongdeveloper.netlify.app/ai-gateway/use-claude-code-with-ai-gateway-azure/
Checklist
descriptionentry in frontmatter.