Skip to content

Add lab 25: use your gateway's models and tools in Claude Code - #36

Merged
Alex Vieira (vieiraae) merged 11 commits into
mainfrom
vieiraae-lab-25-claude-code
Nov 16, 2026
Merged

Alex Vieira (vieiraae) merged 11 commits into
mainfrom
vieiraae-lab-25-claude-code

Conversation

@vieiraae

@vieiraae Alex Vieira (vieiraae) commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #25, which merged before this commit was pushed.

What's new

Lab 25, "Use your gateway's models and tools in Claude Code": connect Claude Code to Claude models (claude-opus-5-5, plus Sonnet and Haiku) and MCP tools through an Azure AI Gateway, then govern it with token limits and cost budgets.

  • labs/25-claude-code/README.md: the guide, with Portal, Azure CLI, Bicep, and code tracks.
  • labs/25-claude-code/25-claude-code.ipynb: merges the rate-limit and cost-limit demos into the standard lab structure, with branded output. Committed without outputs.
  • labs/25-claude-code/infra/claude-code.bicep: the infrastructure for the lab.
  • labs/assets/diagrams/claude-code.svg and the claudeCode diagram in labs/tools/diagrams/set-c.mjs.
  • labs/TROUBLESHOOTING.md: a lab 25 section with the real error messages.
  • labs/catalog.json, labs/README.md, the root README.md (27 labs), AUTHORING.md, and the agent skill.

Findings documented in the lab

  • Claude Code must send the gateway key in ANTHROPIC_AUTH_TOKEN. ANTHROPIC_API_KEY sends it as x-api-key, which the gateway rejects with 401.
  • When the cost budget runs out, Claude Code shows "Failed to authenticate. API Error: 403 LLM cost quota is exceeded". --fallback-model doesn't cover a 403, so the lab switches with /model sonnet.
  • Keyless sign-in works with an apiKeyHelper that runs az account get-access-token --scope https://ai.gateway.azure.com/Data.All.

Product-team corrections (all labs)

Three corrections from the AI Gateway product team, applied to every lab, notebook, script, Bicep sample, diagram, and
troubleshooting entry, plus AGENTS.md, AUTHORING.md, and the labs agent skill:

  • Gateway keys use Authorization: Bearer <key>, not the api-key header. Verified live: the Bearer key and
    api-key both return 200 today, x-api-key returns 401, and sending both headers returns 400. The labs now
    follow the docs and keep a warning about sending both.
  • The Entra token audience is ai.gateway.azure.com, not https://azure-api.net/aigateway. Users request the
    scope https://ai.gateway.azure.com/Data.All, and managed identities request the resource
    https://ai.gateway.azure.com. Verified live: the token is v2.0 with the Data.All scope. The old audience
    still works today.
  • The portal no longer has Connectors. Creating a gateway doesn't create a connector gateway. To use a
    connector, you create a Connector Namespace in Azure and import its MCP endpoint. The labs' setup and cleanup
    steps no longer include a connector gateway.

Media updated to match:

  • Seven diagrams regenerated: architecture, claude-code, create-gateway, github-copilot-byok,
    identity-boundaries, mcp-federation, and quickstart.
  • Two screenshots recaptured from the live portal: copilot-mcp-06-cli-add.webp and quickstart-13-code.webp.
  • Lab 01's walkthrough video: the narration line about the connector gateway was re-recorded, the spotlight now
    shows the managed identity instead of the connector, and the automate scene shows az aigateway create and
    infra/gateway.bicep. Only the two changed segments were re-encoded; the rest of the video is unchanged. The
    matching caption is updated.

The coding-agent plugin at the root is unchanged in this PR: main's v4 plugin (#32, #39) already uses Bearer and
the new audience, so the merge kept main's version.

Lab 17 for the v4 aigateway plugin

  • The plugin is now aigateway: install ai-gateway@azure fails with Plugin "ai-gateway" not found in marketplace "azure". Available plugins: aigateway. The lab, notebook, and uninstall steps use aigateway@azure and /aigateway:*.
  • Discover lists model aliases with their operations and lists MCP tools through a handshake only when you name a key. Build prefers Entra, asks before a call that costs tokens, and writes .env only with approval.
  • New Manage the gateway from your agent section (/aigateway:manage, read-only example), and roles and scopes in Go keyless.
  • The notebook ran end to end on a throwaway gateway with Copilot CLI 1.0.110: 5 of 5 checks passed, only Azure reads, and no key secret read.
  • Troubleshooting: the renamed plugin, tools "not runtime-verified", and build making no model call.

Also

  • Fixed the tracks label on lab pages, which overflowed its border on phones (labs/site/css/04-catalog-lab.css). It affected every lab.

  • Fixed the two Dependabot alerts on main, in lab 16's hosted agent lockfile (labs/16-foundry-hosted-agent/infra/src/gateway-agent/requirements.txt). Both packages come in through other dependencies:

    • certifi 2026.7.22 → 2026.10.23 (critical: bundled emSign root certificates whose intermediate CA keys were compromised).
    • oauthlib 4.0.0 → 4.0.1 (high: device workflow secret disclosure). Pinned by hand: the Microsoft package feed proxy doesn't serve 4.0.1 yet, so uv pip compile can't resolve it here. Its metadata is compatible, and Foundry builds the agent from PyPI.

Validation

  • The notebook ran end to end on a throwaway gateway: the token limit, the cost budget, the Entra helper, and the key suspend and resume checks all passed. One change after the run wasn't re-run: step 17's prompt is now clearer and has a higher max_tokens.
  • npm run check finishes with 0 warnings after merging main.
  • The corrections were verified on a throwaway gateway, and the Bash, Python, Node.js, and JSON files and the notebooks
    pass syntax checks. Not checked: the .ps1 scripts (no PowerShell here) and the .NET sample (not compiled).
  • npm run releases -- --check now exits with 1: the product releases of October 28, November 6, and November 9,
    2026 aren't covered by the labs yet. They're left for a follow-up PR.
  • Previewed in light and dark themes and at mobile width.
  • Verification resources deleted.

- Publish Claude Opus, Sonnet, and Haiku 5.5 from Foundry behind aliases with a
  per-caller token limit and an Opus daily budget, and the claude-code key
- Point Claude Code at the gateway's Anthropic route with environment
  variables, and add the Learn MCP server with claude mcp add
- Hit the token limit and the budget from Claude Code, carry on with Sonnet,
  sign in with Entra ID through apiKeyHelper, and suspend the key
- Add the notebook, the Bicep template, the architecture diagram, the
  Troubleshooting section, the catalog entries, and the skill facts
- Let the tracks pill wrap on mobile

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d05b6670-abba-4799-9d8e-3b2580e7bf94
Fixes the two Dependabot alerts on main:
- certifi 2026.7.22 -> 2026.10.23 (critical: bundled emSign root CAs with
  compromised intermediate CA keys; fixed in 2026.10.18)
- oauthlib 4.0.0 -> 4.0.1 (high: device workflow secret disclosure)

Both are transitive pins. certifi was resolved with uv pip compile
--upgrade-package; oauthlib is pinned by hand because the Microsoft package
feed proxy doesn't serve 4.0.1 yet. Its metadata is compatible
(requires-python >=3.9, no required dependencies; requests-oauthlib 2.0.0
needs oauthlib>=3.0.0), and Foundry builds the agent from PyPI.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d05b6670-abba-4799-9d8e-3b2580e7bf94
ANTHROPIC_AUTH_TOKEN outranks apiKeyHelper. With both set, Claude Code sends
the gateway key as the bearer token and the helper's token only in x-api-key,
so the requests still succeed with the key and Entra ID is silently skipped.
The lab exports ANTHROPIC_AUTH_TOKEN earlier, so "Don't set" wasn't enough:
the Go further tip now says to unset it and keep it out of the settings' env
block. The skill fact says the same.

The troubleshooting row for the 401 retry hang now names the cause precisely:
the key is in ANTHROPIC_API_KEY instead of ANTHROPIC_AUTH_TOKEN.

Verified with Claude Code 2.1.319 against a local header-capture server.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d05b6670-abba-4799-9d8e-3b2580e7bf94
@vieiraae
Alex Vieira (vieiraae) requested review from Paul Yuknewicz (paulyuk) and a balanced review from Copilot November 11, 2026 20:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

…ctor Namespace imports

Align the labs with the product team's corrections:

- Send gateway keys as `Authorization: Bearer <key>` instead of the `api-key`
  header, across the labs, notebooks, scripts, samples, and the coding-agent plugin.
- Request Entra tokens for `https://ai.gateway.azure.com` (scope
  `https://ai.gateway.azure.com/Data.All`), not `https://azure-api.net/aigateway`.
- Remove the companion connector gateway: creating a gateway no longer creates one,
  and connectors come from a Connector Namespace that you create in Azure and import.
- Regenerate the affected diagrams, recapture two portal screenshots, and patch the
  lab 01 walkthrough video's "what provisioning creates" and "automate" scenes,
  narration, and captions.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d05b6670-abba-4799-9d8e-3b2580e7bf94
Take main's v4 coding-agent plugin (commands/aigateway, use-ai-gateway SKILL.md, build.md), which already uses
Authorization: Bearer and the ai.gateway.azure.com audience, and drop the superseded commands/ai-gateway/build.toml.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d05b6670-abba-4799-9d8e-3b2580e7bf94
- Install aigateway@azure and run /aigateway:discover and /aigateway:build:
  the plugin was renamed from ai-gateway, and the old name now fails.
- Describe model aliases with their operations, the MCP handshake that
  lists tools, Entra-first credentials, and build's approval before a
  call that costs tokens.
- Add Go keyless roles and scopes and a "Manage the gateway from your
  agent" section with /aigateway:manage.
- Notebook: new plugin name, and the build prompt approves one model
  call and installs dependencies with the kernel's Python. Ran end to end
  on a live gateway with Copilot CLI 1.0.110.
- Troubleshooting: the renamed plugin, unverified tools, and no model call.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d05b6670-abba-4799-9d8e-3b2580e7bf94

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The notebook fails to preserve pre-deployment alias policies and loses resource-ownership tracking on reruns, while budget probes can bypass the intended Opus checks by using a saved Sonnet default.

3 open issues

Review effort: Balanced

Comment thread labs/25-claude-code/README.md Resolved
…pin --model opus

- Step 2 records what already exists once, before it deploys, so a rerun no
  longer claims the provider, models, aliases, key, or role that the first run
  created, and cleanup still deletes them. Steps 4 and 7 keep the first run's
  record of the practice project and the MCP server the same way.
- Step 2 snapshots the policies of pre-existing aliases before the template
  replaces them, and cleanup restores that snapshot instead of the lab's
  post-deploy policies (now called baseline).
- The role ownership is decided once, and the new assignment is polled for,
  because role assignment reads can lag for a minute or more.
- The quick question and the Opus budget probe pass --model opus, so a model
  saved with /model or ANTHROPIC_MODEL can't bypass the Opus budget. The README
  and TROUBLESHOOTING explain it.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d05b6670-abba-4799-9d8e-3b2580e7bf94

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Download failures silently produce incomplete release data, while deployment overwrites existing alias routing that cleanup does not restore.

2 open issues
3 resolved since last review

Review effort: Balanced

Comment thread labs/tools/product-releases.mjs Resolved
…7: align with the updated plugin

- Lab 25: record the backends, routing and policies of existing aliases and put them back at clean up;
  set_policies keeps an alias's other properties; the template outputs the Foundry User assignment ID,
  so clean up deletes it even when the list hasn't caught up.
- Releases tool: retry network errors, 429 and 5xx, then fail, so a lost docs chunk never passes for an
  empty one.
- Lab 17: build uses an existing credential, never reads or writes keys, integrates into the existing
  project and verifies one request; no GitHub Copilot SDK scaffold. Verified live with the plugin on main.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d05b6670-abba-4799-9d8e-3b2580e7bf94

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Cleanup can break existing model calls by leaving provider authentication altered and deleting shared providers, including unrelated model registrations.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment thread labs/25-claude-code/README.md Resolved
- claude-code.bicep: new createProvider parameter. When the gateway already has
  the account's provider, the template keeps it, with its authentication, and
  only adds the models under it, so a provider on a user-assigned identity keeps
  working after Clean up deletes the lab's Foundry User assignment.
- Notebook: cell 7 passes createProvider from its record; cell 6 explains it.
- README: the Bicep track detects the provider and passes createProvider. The
  Azure CLI Clean up deletes the three Claude models instead of the provider,
  and deletes the provider only when it has no models left.

Verified live on a throwaway gateway, in Bash, PowerShell and the notebook, with
a provider on a user-assigned identity that has another model, and without one.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d05b6670-abba-4799-9d8e-3b2580e7bf94

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because redeploying existing model registrations can remove token limits and cost controls, leaving shared aliases affected even after cleanup.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

- Resolve the root README (take main's layout, labs badge 27) and lab 16's
  requirements.txt (keep the newer certifi 2026.10.23 pin).
- Lab 25: import the Claude deployments with `model-provider import`, because
  from CLI 1.0.0b30 `model-provider create --foundry-resource-id` no longer
  imports them. Note the 1.0.0b30 minimum, with a troubleshooting row for the
  error that older versions print.
- Lab 17: describe the migrate and feedback commands as they work now; the
  feedback skill anonymizes a session summary and no longer creates a ZIP.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d05b6670-abba-4799-9d8e-3b2580e7bf94

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the Claude Code lab addition and authentication updates.

No open issues 🎉

Review effort: Balanced

@vieiraae
Alex Vieira (vieiraae) merged commit 19e71b1 into main Nov 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants