Skip to content

[AI Gateway] Add wrangler auth token hint to cURL examples#31406

Open
superhighfives wants to merge 4 commits into
productionfrom
cgleason/aig-1220-wrangler-auth-token-hint
Open

[AI Gateway] Add wrangler auth token hint to cURL examples#31406
superhighfives wants to merge 4 commits into
productionfrom
cgleason/aig-1220-wrangler-auth-token-hint

Conversation

@superhighfives

Copy link
Copy Markdown
Contributor

The AI Gateway cURL code examples reference $CLOUDFLARE_API_TOKEN / $CF_AIG_TOKEN but never tell readers how to mint one. This surfaces wrangler auth token in two places per page so readers hit it whichever way they read the block.

This pairs with a dashboard change that adds the same hint to the AI Gateway in-app code examples: stratus!39025 (AIG-1220).

What changed

  • New partial at src/content/partials/ai-gateway/auth-token-hint.mdx with one sentence linking wrangler auth token to the wrangler CLI reference.
  • Rendered the partial once above the first cURL block on each affected page (11 pages).
  • Added a # Run \wrangler auth token` to get an auth token to replace $TOKEN for use with the API.shell comment as the first line inside every cURL block that references one of the two env vars (31 blocks). The token name in each comment matches the block —$CLOUDFLARE_API_TOKENfor most blocks,$CF_AIG_TOKENfor the two blocks inconfiguration/custom-providers.mdx` that use the per-gateway auth header.

Pages touched

  • ai-gateway/get-started.mdx
  • ai-gateway/usage/rest-api.mdx
  • ai-gateway/configuration/custom-providers.mdx
  • ai-gateway/configuration/authentication.mdx
  • ai-gateway/configuration/request-handling.mdx
  • ai-gateway/features/caching.mdx
  • ai-gateway/features/unified-billing.mdx
  • ai-gateway/observability/custom-metadata.mdx
  • ai-gateway/observability/logging/index.mdx
  • ai-gateway/tutorials/create-first-aig-workers.mdx
  • ai-gateway/usage/providers/workersai.mdx

Out of scope

  • 4 cURL blocks in configuration/custom-providers.mdx that only reference $PROVIDER_API_KEY or $INTERNAL_API_KEY (not Cloudflare-issued tokens) — these aren't replaced by wrangler auth token.
  • 4 prettier warnings on touched files are pre-existing on production — left alone to keep this diff focused.

View AI session

The cURL code examples in the AI Gateway docs reference
$CLOUDFLARE_API_TOKEN and $CF_AIG_TOKEN but never tell readers how
to mint one. Surface 'Run `wrangler auth token` to get an auth token
to replace $CLOUDFLARE_API_TOKEN for use with the API.' in two places
per page so readers hit it whichever way they read the block:

- A shared partial (partials/ai-gateway/auth-token-hint.mdx) linking to
  the wrangler CLI reference, rendered once above the first cURL block
  on each affected page.
- An inline shell comment as the first line inside every cURL block,
  so the hint survives copy-paste. The token name in the comment
  matches whichever env var the block uses ($CLOUDFLARE_API_TOKEN or
  $CF_AIG_TOKEN).

Covers 31 cURL blocks across 11 pages: get-started, REST API reference,
caching, unified billing, logging, the Workers tutorial, custom
providers, custom metadata, request handling, authentication, and the
Workers AI provider page.

Companion change in the Cloudflare dashboard:
https://gitlab.cfdata.org/cloudflare/fe/stratus/-/merge_requests/39025
Copilot AI review requested due to automatic review settings June 11, 2026 18:58
@cloudflare-docs-bot

cloudflare-docs-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review

⏸️ Automatic reviews for this PR are paused.

This PR has already received 2 automatic reviews. To run another review, a codeowner can comment /review or /full-review.

Tip: Keep PRs in draft mode until they are ready for review — the bot skips draft PRs automatically.


✅ No style-guide issues found in commit 3331362.

Commands

Only codeowners can run commands. Post a comment with the command to trigger it.

Command Description
/review Runs a review now. Incremental if a prior review exists, full if not.
/full-review Re-reviews the entire PR diff from scratch, ignoring incremental history. Useful after a rebase, when you want a fresh review, or if the bot gets out of sync and reports issues that no longer exist.

@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
/src/content/docs/ai-gateway/ @abhishekkankani, @palashgo, @thebongy, @roerohan, @kathayl, @mchenco, @zeke, @superhighfives, @bfirsh, @mattrothenberg, @ethulia, @aninibread, @kflansburg, @cloudflare/product-owners

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a reusable “how to get a token” hint to AI Gateway docs so readers can quickly obtain an auth token for the cURL examples, and annotates relevant cURL snippets with an inline reminder.

Changes:

  • Added a new partial (auth-token-hint.mdx) linking to wrangler auth token.
  • Rendered the partial above the first relevant cURL block on each affected AI Gateway doc page.
  • Added a leading shell comment to each cURL snippet that references $CLOUDFLARE_API_TOKEN or $CF_AIG_TOKEN.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/content/partials/ai-gateway/auth-token-hint.mdx New shared hint snippet linking to wrangler auth token.
src/content/docs/ai-gateway/usage/rest-api.mdx Imports/uses the hint partial and adds token reminder comments to multiple cURL examples.
src/content/docs/ai-gateway/usage/providers/workersai.mdx Renders the hint partial and adds token reminder comment to the Workers AI cURL example.
src/content/docs/ai-gateway/tutorials/create-first-aig-workers.mdx Renders the hint partial within the tutorial flow and adds token reminder comment to the cURL example.
src/content/docs/ai-gateway/observability/logging/index.mdx Renders the hint partial and adds token reminder comments to logging-related cURL examples.
src/content/docs/ai-gateway/observability/custom-metadata.mdx Updates imports, renders the hint partial, and adds token reminder comment to the metadata cURL example.
src/content/docs/ai-gateway/get-started.mdx Renders the hint partial and adds token reminder comments to getting-started cURL examples.
src/content/docs/ai-gateway/features/unified-billing.mdx Updates imports, renders the hint partial, and adds token reminder comments to Unified Billing cURL examples.
src/content/docs/ai-gateway/features/caching.mdx Updates imports, renders the hint partial, and adds token reminder comments to caching cURL examples.
src/content/docs/ai-gateway/configuration/request-handling.mdx Renders the hint partial and adds a token reminder comment to the timeout cURL example.
src/content/docs/ai-gateway/configuration/custom-providers.mdx Updates imports, renders the hint partial, and adds token reminder comments across custom provider API cURL examples (incl. $CF_AIG_TOKEN blocks).
src/content/docs/ai-gateway/configuration/authentication.mdx Imports/uses the hint partial and adds token reminder comment to the example request.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/content/docs/ai-gateway/configuration/request-handling.mdx Outdated
@ask-bonk

ask-bonk Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review for PR #31406

Title: [AI Gateway] Add wrangler auth token hint to cURL examples
Status: Ready to merge after one minor fix


What changed

This PR improves the AI Gateway documentation by helping readers understand how to generate the auth tokens referenced in cURL examples. It introduces:

  1. A new reusable partial at src/content/partials/ai-gateway/auth-token-hint.mdx that links to the wrangler auth token CLI reference.
  2. Partial rendering once above the first cURL block on each of 11 affected pages.
  3. Inline shell comments as the first line inside every cURL block that uses a Cloudflare-issued token (31 blocks total), so the hint survives copy-paste.

The token name in each inline comment correctly matches the env var used in that block ($CLOUDFLARE_API_TOKEN for most, $CF_AIG_TOKEN for the two blocks in custom-providers.mdx that use per-gateway auth).


Validation results

  • pnpm run check0 errors, 0 warnings
  • pnpm run lintclean
  • pnpm run format:core:checkclean
  • Link /workers/wrangler/commands/general/#auth-tokenvalid

Issues flagged

Line highlight off-by-one in request-handling.mdx

The Expressive Code block at line 38 uses {4} to highlight the cf-aig-request-timeout header. After inserting the shell comment as line 1, the highlight now points to the Content-Type header instead.

--- a/src/content/docs/ai-gateway/configuration/request-handling.mdx
+++ b/src/content/docs/ai-gateway/configuration/request-handling.mdx
@@ -35,7 +35,7 @@ For a provider-specific endpoint, configure the timeout value by adding a `cf-ai
 
 <Render file="auth-token-hint" product="ai-gateway" />
 
-```bash title="Request with timeout" {4}
+```bash title="Request with timeout" {5}
 # Run `wrangler auth token` to get an auth token to replace $CLOUDFLARE_API_TOKEN for use with the API.
 curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/chat/completions" \
   --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \

Everything else looks good

  • Partial frontmatter (---\n{}\n---) is valid.
  • All pages correctly add the Render component import where needed.
  • No unescaped MDX characters ({, }, <, >).
  • No style guide violations.
  • The 4 cURL blocks referencing $PROVIDER_API_KEY / $INTERNAL_API_KEY were correctly left untouched, as noted in the PR description.

Suggested labels

documentation, ai-gateway

github run

The previous commit added a second shell-comment line (`wrangler whoami`)
without preserving the 3-space indent the block needed to stay inside its
parent numbered-list item. That broke the code fence: the second comment
and the cURL body spilled out as plain MDX, the closing fence became four
backticks, and the next code block on the page got its own fences
mangled.

Restore the indent so the entire block sits inside the list-item code
fence.
@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Preview URL: https://e70c9eee.preview.developers.cloudflare.com
Preview Branch URL: https://cgleason-aig-1220-wrangler-auth-token-hint.preview.developers.cloudflare.com

Files with changes (up to 15)

Original Link Updated Link
https://developers.cloudflare.com/ai-gateway/configuration/custom-providers/ https://cgleason-aig-1220-wrangler-auth-token-hint.preview.developers.cloudflare.com/ai-gateway/configuration/custom-providers/
https://developers.cloudflare.com/ai-gateway/usage/rest-api/ https://cgleason-aig-1220-wrangler-auth-token-hint.preview.developers.cloudflare.com/ai-gateway/usage/rest-api/
https://developers.cloudflare.com/ai-gateway/observability/custom-metadata/ https://cgleason-aig-1220-wrangler-auth-token-hint.preview.developers.cloudflare.com/ai-gateway/observability/custom-metadata/
https://developers.cloudflare.com/ai-gateway/observability/logging/ https://cgleason-aig-1220-wrangler-auth-token-hint.preview.developers.cloudflare.com/ai-gateway/observability/logging/
https://developers.cloudflare.com/ai-gateway/features/caching/ https://cgleason-aig-1220-wrangler-auth-token-hint.preview.developers.cloudflare.com/ai-gateway/features/caching/
https://developers.cloudflare.com/ai-gateway/configuration/request-handling/ https://cgleason-aig-1220-wrangler-auth-token-hint.preview.developers.cloudflare.com/ai-gateway/configuration/request-handling/
https://developers.cloudflare.com/ai-gateway/features/unified-billing/ https://cgleason-aig-1220-wrangler-auth-token-hint.preview.developers.cloudflare.com/ai-gateway/features/unified-billing/
https://developers.cloudflare.com/ai-gateway/configuration/authentication/ https://cgleason-aig-1220-wrangler-auth-token-hint.preview.developers.cloudflare.com/ai-gateway/configuration/authentication/
https://developers.cloudflare.com/ai-gateway/get-started/ https://cgleason-aig-1220-wrangler-auth-token-hint.preview.developers.cloudflare.com/ai-gateway/get-started/
https://developers.cloudflare.com/ai-gateway/usage/providers/workersai/ https://cgleason-aig-1220-wrangler-auth-token-hint.preview.developers.cloudflare.com/ai-gateway/usage/providers/workersai/
https://developers.cloudflare.com/ai-gateway/tutorials/create-first-aig-workers/ https://cgleason-aig-1220-wrangler-auth-token-hint.preview.developers.cloudflare.com/ai-gateway/tutorials/create-first-aig-workers/

- Fix line-highlight `{4}` -> `{6}` in configuration/request-handling.mdx
  so the highlight still points to the `cf-aig-request-timeout` header
  after the two-line shell comment shifted everything down. Flagged by
  Copilot and the docs-bot reviewer.
- Expand the auth-token-hint partial and the inline shell comments to
  also cover `wrangler whoami` for the account ID, mirroring the pattern
  in the cURL blocks.
@superhighfives

Copy link
Copy Markdown
Contributor Author

Thanks @ask-bonk \u2014 the {4} -> {6} fix is in 6fb181e. The highlight now correctly lands on the cf-aig-request-timeout header after the two-line shell comment shifted everything down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:ai-gateway AI Gateway: https://developers.cloudflare.com/ai-gateway/ size/s

Projects

None yet

Development

Successfully merging this pull request may close these issues.