Skip to content

refactor(coderd/x/chatd): derive the BYOK auth header from the AI Gateway client choice - #30979

Draft
ibetitsmike wants to merge 3 commits into
mike/chatd-gateway-byok-header-testfrom
mike/chatd-bridge-client-family
Draft

ibetitsmike wants to merge 3 commits into
mike/chatd-gateway-byok-header-testfrom
mike/chatd-bridge-client-family

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

fantasyConfigForAIBridge picked the fantasy client for an AI Gateway route, and aiGatewayRequestFormatForProviderType mapped the same provider type and model again, only to choose X-Api-Key or Authorization: Bearer for a user's own key. This PR moves the client choice into aibridgeClientProvider and passes its result to aiGatewayProviderAuthForUser, so the header follows the client. It deletes the request-format enum, the mapper, the mapper's test, and the superseded TestNewModelAttribution.

Why it is safe

  • aibridgeClientProvider is the old fantasyConfigForAIBridge switch without the base URL. TestAIBridgeProviderFormatMapping (12 rows, unchanged) still pins the client and base URL; the mapper test's 9 rows are a subset of them.
  • The mapper returned the Anthropic format for exactly the inputs that get the Anthropic client, so no header changes. TestAIGatewayProviderAuthForUser and the test(coderd/x/chatd): cover BYOK header choice for Bedrock and OpenAI-compatible routes #30978 subtest pin the header.
  • TestNewModelAttributionImmutablePerRequest covers both workspace bindings that TestNewModelAttribution checked, plus the API key ID, also without a database.
  • Mutants through go test -overlay each fail a remaining test: every arm of aibridgeClientProvider and the base URL check; an auth switch keyed on openai, an auth case matching openai-compat instead of anthropic, and a dropped model ID at the resolveAIGatewayRoute call; the workspace check, the workspace ID copy, and an empty API key ID. A garbage copy fails to build, so the overlay applies.
  • rg -n 'aiGatewayRequestFormat' . finds nothing.

Review focus

Only the Anthropic client gets X-Api-Key; openai and openai-compat keep Authorization: Bearer, as the old default format gave them. Only the #30978 subtest catches an auth switch keyed on openai.

Validation

  • go test ./coderd/x/chatd/... -count=1 -p 4 -parallel 4: pass.
  • 12 mutants: each fails a remaining test.
  • make pre-commit: pass.

Stack

This stack removes provider code that only direct, non-gateway clients used, so chatprovider builds just the three clients the AI Gateway path needs; #30979 then derives the BYOK auth header from that same client choice.

  1. refactor(coderd/x/chatd/chatprovider): drop the direct Bedrock client #30928 Drop the direct Bedrock client
  2. refactor(coderd/x/chatd): drop the remaining direct provider clients #30929 Drop the remaining direct provider clients
  3. refactor(coderd/x/chatd/chatprovider): drop provider options only direct clients read #30958 Drop provider options only direct clients read
  4. refactor(coderd/x/chatd): drop transport branches only direct clients used #30966 Drop transport branches only direct clients used
  5. test(coderd/x/chatd): cover BYOK header choice for Bedrock and OpenAI-compatible routes #30978 Cover the BYOK header choice for Bedrock and OpenAI-compatible routes
  6. refactor(coderd/x/chatd): derive the BYOK auth header from the AI Gateway client choice #30979 Derive the BYOK auth header from the client choice

Xum, an AI agent, opened this PR for @ibetitsmike and wrote this description.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, requested this review for Mike.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T17:35:44.958844Z c133ab9 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: c133ab96cf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

This branch has not been deployed

No deployments
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.

1 participant