## Summary Nests the CLI reference by subcommand so the Command Line sidebar collapses from 156 flat entries to 49 top-level verbs. Each page's URL follows the invocation, its page title is the full command as inline code, and its sidebar label is only its own verb as inline code. | | Before | After | | --- | --- | --- | | File | `docs/reference/cli/oauth2-provider_dcr_disable.md` | `docs/reference/cli/oauth2-provider/dcr/disable.md` | | URL | `/reference/cli/oauth2-provider_dcr_disable` | `/reference/cli/oauth2-provider/dcr/disable` | | Page title (front matter) | `oauth2-provider dcr disable` | `` `coder oauth2-provider dcr disable` `` | | Sidebar label (manifest) | `oauth2-provider dcr disable` | `` `disable` `` | Resolves DOCS-140 (coder/coder half). Also fixes the Makefile part of DOCS-1073 / DOCS-912, which this change depends on. ## Changes - `scripts/clidocgen`: pages nest by command path. A command with visible subcommands becomes its directory's `index.md`, so `oauth2-provider/index.md` and `oauth2-provider/dcr/index.md` sit above `oauth2-provider/dcr/disable.md`. Subcommand table links are relative to the parent page. - `scripts/clidocgen`: the manifest "Command Line" section is built from the command tree (nested, sorted by name, hidden commands skipped) instead of a flat list. The redundant `coder` child that pointed back at `reference/cli/index.md` is gone. - `Makefile`: the CLI rule now replaces `docs/reference/cli/` wholesale, so stale pages get removed. The manifest rule now runs `clidocgen -manifest-only` on top of the API staging manifest, so the CLI nav is generated instead of edited by hand. As a result, the nine pages that had no nav entry (`ai-gateway*`, `secret enable/disable`, `server fix-oidc-links`) now have one. - `scripts/configdocgen` and 48 prose pages: links point at the new paths (for example `reference/cli/server.md` is now `reference/cli/server/index.md`). ## How to review/QA this PR - `docs/reference/cli/**/*` (approximately 190 pages): Each of these pages are generated automatically. Some pages appear deleted, and some pages appear new. Every deleted page corresponds to a new page somewhere else, so no information is being deleted. The docs in this section should adhere to the following, so a test in the build preview for each of these items should be satisfactory: - [ ] Each subcommand of a command gets nested as a child instead of being displayed as a flat list. - [ ] Each parent command is stored in an `index.md` file. - [ ] The title of each page inside the page should now feature the full `coder XYZ` command. - [ ] The title of each page inside the page should now be formatted as inline code. - [ ] The title of each page in the sidebar should be the most granular subcommand of the whole command string (if the page's title is `coder ai-gateway keys create`, the sidebar label is `create`). - [ ] The title of each page in the sidebar should now be formatted as inline code. - [ ] The page slug for each page is now the most granular subcommand. - [ ] All links now point to the correct page. - `docs/manifest.json`: The changes here reflect the updated structure of the `docs/reference/cli` section. - `docs/**/*.md` outside of `docs/reference/cli/**/*` (approximately 50 pages): The extent of the changes in these pages are just updating the paths to point to the new page locations. - [ ] The links on the page all point to the correct new path in `docs/reference/cli`. - `scripts/clidocgen` (4 files): This is the Go code responsible for generating everything inside of `docs/reference/cli/**/*`. A typical code review here should be satisfactory. - `scripts/configdocgen` (2 files): these two files just have updates to the raw `.md` path used by `docs/admin/setup/configuration-reference.md` and updates the tests to reflect that. - `Makefile`: This updates the `make` targets for generating the CLI docs to fit the new structure. ## Merge ordering Without the renderer PRs deployed, both docs sites show literal backticks in titles and sidebar labels. Without the redirects, the old flat URLs return 404. 1. Deploy before merging this PR: coder/docs-engine#176 (beta-docs renders these titles as inline code) and coder/coder.com#1111 (classic docs renders them as inline code). Both are safe to ship first, because titles without backticks render as before. 2. Merge this PR. 3. Merge coder/coder.com#1112 (redirects from the old flat URLs) only once this content reaches the mainline release branch that serves unversioned `/docs`. ## Testing - `go test ./scripts/clidocgen/ ./scripts/configdocgen/ ./scripts/docshtmlcheck/`: pass. New tests cover page paths, subcommand links, the nested manifest, and front matter quoting. - `make docs/reference/cli/index.md docs/manifest.json docs/admin/setup/configuration-reference.md`, then a forced rerun: the second run produced no diff. - Checked the manifest: all 164 CLI entries resolve to a file, no page is missing a nav entry, and everything outside "Command Line" is byte-identical. - Relative `.md` links across `docs/`: 0 broken, same as `main`. - `make pre-commit` and `make pre-push`: pass. On earlier pre-push attempts, different unrelated vitest files timed out under host load. Those files pass when run alone, and the final push passed with `PARALLEL_JOBS=1`. <details> <summary>Implementation plan and decision log</summary> **Goal (from DOCS-140 and the requester):** URLs follow the command hierarchy. Pages are titled with the full command, and sidebar entries with the last verb only. Both are formatted as inline code. **Contract with the renderers:** a title wrapped entirely in one pair of backticks (``^`[^`]+`$``) renders as inline code. Plain-text consumers (`<title>`, meta, search, llms corpus) strip the backticks. Page title comes from front matter `title`, and the sidebar label from the manifest node `title`. **Decisions** - A parent command is `dir/index.md` rather than a sibling `dir.md`. The root CLI page is already `index.md`, and both docs-engine and the legacy coder.com renderer map `x/index.md` to `/x`. - The manifest is built from the command tree, not from the written files, so ordering is deterministic and the nesting matches the pages exactly. - The manifest discard bug (DOCS-1073 item 1) is fixed here, because without that fix the generated nested manifest would never reach the tree. DOCS-1073 items 2 through 4 (a prose fix and a hidden-command policy) are out of scope. - `-manifest-only` keeps the existing parallel `make gen` layout: the API rule still owns `_gen/manifest-staging.json`, and CLI regeneration doesn't retrigger swag. - The renderer and redirect work lives in the companion PRs in coder/docs-engine and coder/coder.com. It is linked above and not duplicated here. </details> --- > [!NOTE] > Generated by Coder Agents on behalf of @nickvigilante.
8.9 KiB
title
| title |
|---|
| Authentication |
Note
AI Gateway is part of AI Governance, which is included with a Premium license.
AI Gateway uses different credentials for different kinds of connections:
- AI clients use a Coder API token to authenticate with AI Gateway as a user.
- Standalone gateway replicas use AI Gateway keys to connect to the Coder control plane.
- AI Gateway uses provider credentials configured by an administrator to authenticate to upstream AI providers.
- In Bring Your Own Key (BYOK) mode, a user also supplies a personal provider credential or subscription token.
These credentials are not interchangeable. A gateway key does not authenticate an AI client, and a Coder API token does not authenticate a standalone replica.
Authenticate AI clients
AI Gateway authenticates clients with the same Coder API token that a user uses for the rest of the Coder API. No separate AI Gateway login is required for client traffic. For token creation, expiration, and revocation, refer to Sessions and API tokens.
Authenticating with a Coder token avoids distributing centralized provider API keys, such as OpenAI or Anthropic keys, to individual users. AI Gateway handles upstream credentials centrally and forwards each request to the configured provider on the user's behalf.
The exact environment variable or setting name differs between tools. Refer to the list of supported clients and your tool's documentation for details.
Create a Coder API token
You can generate a token from the Coder dashboard or the CLI.
From the dashboard, go to Account settings > Tokens and create a new token. For long-lived tokens, refer to Sessions and API tokens. For headless or service-account use, refer to Headless authentication.
From the CLI, print your current session token with coder login token:
coder login token
Or create a new long-lived token with a name and lifetime:
coder tokens create --lifetime 30d -n my-ai-token
Use short lifetimes for automation and CI to limit the blast radius if a token leaks.
Retrieve your session token
If you're logged in with the Coder CLI, retrieve your current session token with coder login token:
export ANTHROPIC_API_KEY=$(coder login token)
export ANTHROPIC_BASE_URL="https://coder.example.com/api/v2/ai-gateway/anthropic"
AI Gateway Proxy authentication
For tools that don't support a configurable base URL, AI Gateway Proxy intercepts traffic and forwards it to AI Gateway. The Coder token is supplied in the proxy URL:
export HTTPS_PROXY="https://coder:$(coder login token)@<proxy-host>:8888"
The client machine also needs to trust the proxy's CA certificate. For full setup, refer to AI Gateway Proxy setup.
Authenticate standalone gateway replicas
AI Gateway keys are scoped to the Coder deployment.
A standalone AI gateway uses one of these keys to connect to coderd.
Only the built-in owner role can create, list, and delete these keys.
Coder custom roles are organization-scoped and cannot grant the site-level ai_gateway_key permissions.
Create a key with a descriptive name:
coder ai-gateway keys create standalone-production
The command displays the plaintext key once. Save it immediately in your secret manager, because you cannot retrieve it later. Coder stores only a short prefix of the key for display and a SHA-256 hash for authentication, never the full secret.
Names must be unique, 64 characters or fewer, and use only lowercase letters, numbers, and hyphens. A name cannot start or end with a hyphen or contain consecutive hyphens. Gateway keys do not expire and cannot be scoped or restricted.
Configure the standalone process with either of the following options, but not both:
CODER_AI_GATEWAY_KEYor--keysupplies the key directly.CODER_AI_GATEWAY_KEY_FILEor--key-filereads the key from a file.
A user login and CODER_SESSION_TOKEN are not used by coder ai-gateway start.
The same gateway key can authenticate multiple replicas.
Separate keys make it easier to rotate or revoke each deployment independently.
List keys and the most recent heartbeat for each:
coder ai-gateway keys list
A replica records a heartbeat when its control connection is established, then refreshes it every 60 seconds while that connection is active. The heartbeat reports control-connection liveness rather than client request volume. Coder stores one timestamp per key, so replicas that share a key cannot be distinguished.
For usage and flags, refer to the generated CLI reference for creating, listing, and deleting gateway keys.
Rotate a gateway key
Rotate a key with a rolling restart. Run more than 1 replica behind a load balancer so client traffic continues during the rollout:
- Create a new gateway key.
- Update the Kubernetes Secret, environment variable, or key file used by every replica.
- Restart or roll out the standalone deployment so every replica uses the new key.
- Verify readiness and confirm that the new key has a recent heartbeat.
- Delete the old key.
Delete a key by name or ID:
coder ai-gateway keys delete standalone-production
Add --yes to skip the confirmation prompt in automation.
Deleting a key rejects new connections immediately. An established session closes when its next heartbeat detects the deletion, within 60 seconds. The replica then tries to reconnect, receives HTTP 401, and treats that as fatal: the process exits non-zero rather than retrying. Stop or update every replica before deleting its key for an orderly rotation.
Authenticate to upstream providers
Administrators configure provider credentials in the Coder dashboard or with the AI Providers API.
Standalone replicas fetch this provider configuration from coderd, so do not copy centralized provider credentials into each standalone deployment.
For provider setup and credential failover, refer to Provider configuration.
Bring Your Own Key (BYOK)
In addition to centralized key management, AI Gateway supports Bring Your Own Key (BYOK) mode. Users can provide their own LLM API keys or provider subscriptions, such as Claude Pro or Max and ChatGPT Plus or Pro, while AI Gateway continues to provide observability and governance.
In BYOK mode, users need two credentials:
- A Coder API token to authenticate with AI Gateway.
- Their own LLM credential, such as a personal API key or subscription token, which AI Gateway forwards to the upstream provider.
BYOK and centralized modes can be used together. When a user provides their own credential, AI Gateway forwards it directly. When no user credential is present, AI Gateway uses the administrator-configured provider key. This approach offers centralized keys as a default while allowing individual users to bring their own key.
Note
When a BYOK credential is present, key failover is skipped.
Coder Agents requests routed through AI Gateway are in-process control plane requests, not external client requests that send their own AI Gateway bearer token. Coder Agents use the same global BYOK setting. When BYOK is enabled, users can save personal API keys for any enabled AI provider from the Agents settings page. For AWS Bedrock providers, the personal key is an AWS Bedrock API key that AI Gateway forwards as a bearer token in place of the deployment-managed AWS credentials, for every model family Bedrock serves. Refer to Agents credential selection for the Agents-specific behavior.
Visit individual client pages for configuration details.
Enable or disable BYOK
BYOK is enabled by default.
Administrators can disable it for the embedded gateway with --ai-gateway-allow-byok=false or CODER_AI_GATEWAY_ALLOW_BYOK=false:
coder server --ai-gateway-allow-byok=false
For a standalone gateway, set the option on each replica:
CODER_AI_GATEWAY_ALLOW_BYOK=false coder ai-gateway start
Each replica enforces its own local value, which governs only the traffic that replica handles.
The standalone process does not receive the coderd value, so set the option on every replica that should reject BYOK requests.
When disabled, BYOK requests are rejected with a 403 Forbidden response, and only centralized provider credentials are permitted.
