Skip to content

fix(auth): preserve prefixed API-key model capabilities / 修复带前缀 API Key 模型的能力路由#4215

Open
rdself wants to merge 1 commit into
router-for-me:devfrom
rdself:coder/api-key-prefix-capabilities-v3
Open

fix(auth): preserve prefixed API-key model capabilities / 修复带前缀 API Key 模型的能力路由#4215
rdself wants to merge 1 commit into
router-for-me:devfrom
rdself:coder/api-key-prefix-capabilities-v3

Conversation

@rdself

@rdself rdself commented Jul 11, 2026

Copy link
Copy Markdown

Summary

Configured API-key models can be exposed with a provider prefix while executors send the unprefixed upstream model name. A global registry lookup cannot identify the exact auth, configured upstream entry, or endpoint kind selected for one attempt, so prefixed requests could receive unrelated static capabilities.

This change:

  • compiles API-key aliases and model capabilities into an immutable per-auth routing snapshot
  • binds the exact configured model definition to each selected upstream attempt
  • adds configured thinking support for Gemini, Interactions, Claude, Codex, xAI, and Vertex-compatible API-key providers while preserving OpenAI-compatible support
  • resolves configured catalog and execution metadata through one suffix-free static-capability path
  • preserves prefixed OpenAI-compatible image: true discovery and filters image execution by the exact auth registration before scheduling
  • leaves OAuth and static-registry execution unchanged when no exact API-key binding exists

Failure Examples Without This Change

A prefixed API-key request can select the correct upstream model but fail to match its configured capabilities during execution.

For example, with force-model-prefix: true, provider prefix sp-anthropic, and configured model claude-opus-4-6, a client request for sp-anthropic/claude-opus-4-6 reaches the executor as claude-opus-4-6. A global lookup can miss the provider-specific thinking levels, causing xhigh or max to be mapped, rejected, or removed using unrelated metadata.

A suffixed configured upstream such as gpt-5.6-luna(high) can also lose static xhigh and max catalog capabilities if static lookup uses the suffixed name while execution uses the base name.

Likewise, when an image-capable API-key registration and a chat-only registration expose the same model ID, aggregate image validation alone can admit the request and then select the chat-only auth. Selection must filter against the exact client registration.

Implementation

  • Builds one per-auth routing snapshot from a deep-cloned runtime config.
  • Carries the selected configured model metadata through candidate selection and execution.
  • Uses one configured-model resolver for suffix-free static lookup, explicit thinking overrides, and modality normalization.
  • Maps cross-family high intent using xhigh -> xhigh, max, high and max -> max, xhigh, high.
  • Keeps same-family validation strict and preserves legacy behavior when no configured API-key model is resolved.
  • Restricts image candidates before both normal and plugin-delegated built-in scheduling.
  • Validates known Home-dispatched registrations before executor entry and advances the Home count when a chat-only auth is skipped.
  • Includes thinking metadata in watcher hashes so capability-only edits reload correctly.

Validation

  • go test ./... -count=1
  • targeted go test -race across registry, thinking, executor helpers, and auth routing
  • go build ./cmd/server
  • stream, non-stream, token-count, repeated alias pool, prefix, hot-reload, catalog, plugin scheduler, and image routing regression tests

Copilot AI review requested due to automatic review settings July 11, 2026 07:59

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces support for configuring and binding thinking/reasoning capabilities and image execution configurations to specific API-key models across various providers (Claude, Codex, Gemini, Vertex, and OpenAI Compatibility). It refactors the executors to resolve and apply these configured capabilities dynamically at request time, updates the model hashing and summarization logic to include thinking settings, and refines the routing and filtering of image models. A critical review feedback points out that configuredAPIKeyModelInfo directly mutates the global shared static registry entry returned by registry.LookupStaticModelInfo, which can cause race conditions and data corruption. A code suggestion is provided to copy the struct before modification.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread sdk/cliproxy/auth/api_key_model_capabilities.go Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a2e75a45ec

ℹ️ 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".

Comment thread sdk/api/handlers/handlers.go
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch from a2e75a4 to be209ec Compare July 11, 2026 08:18

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be209ecb63

ℹ️ 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".

Comment thread sdk/cliproxy/auth/api_key_model_capabilities.go Outdated
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch 2 times, most recently from 3ec44bf to 5cab7d5 Compare July 12, 2026 17:52

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5cab7d5a07

ℹ️ 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".

Comment thread sdk/cliproxy/service.go Outdated
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch from 5cab7d5 to efd44a9 Compare July 12, 2026 18:08

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: efd44a9b3f

ℹ️ 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".

Comment thread sdk/cliproxy/auth/conductor.go
Comment thread sdk/cliproxy/service.go Outdated
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch from efd44a9 to 6f1bc8b Compare July 12, 2026 18:28

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6f1bc8b91b

ℹ️ 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".

Comment thread sdk/cliproxy/auth/conductor.go
Comment thread sdk/api/handlers/openai/openai_images_handlers.go Outdated
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch from 6f1bc8b to ddd1231 Compare July 12, 2026 18:51

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

func buildConfigModels[T modelEntry](models []T, ownedBy, modelType string) []*ModelInfo {

P2 Badge Propagate configured thinking into model registrations

When a claude-api-key, codex-api-key, gemini-api-key, or vertex-api-key model uses the new thinking block, request routing consumes it via the API-key capability snapshot, but model registration still goes through buildConfigModels, which only copies static upstream thinking and never reads the configured value. The Codex client model catalog derives supported_reasoning_levels from the registry, so these configured aliases are advertised with missing or stale reasoning levels and clients that rely on the catalog will not offer the configured reasoning options even though runtime accepts them.

ℹ️ 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".

@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch from ddd1231 to a394ad3 Compare July 12, 2026 19:11
@rdself

rdself commented Jul 12, 2026

Copy link
Copy Markdown
Author

Addressed in a394ad31: API-key model registrations now prefer configured thinking metadata, with static capabilities used only as fallback. Covered for Claude, Codex, Gemini, and Vertex.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a394ad313d

ℹ️ 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".

Comment thread sdk/cliproxy/auth/api_key_model_capabilities.go
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch from a394ad3 to a87a213 Compare July 12, 2026 19:30

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a87a213bc6

ℹ️ 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".

Comment thread internal/runtime/executor/claude_executor.go Outdated
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch from a87a213 to 1c5cb67 Compare July 12, 2026 19:53

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c5cb67055

ℹ️ 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".

Comment thread sdk/cliproxy/auth/api_key_model_capabilities.go Outdated
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch from 1c5cb67 to 3f958fd Compare July 12, 2026 20:11
@rdself rdself changed the title Fix prefixed API-key model capability routing fix(auth): preserve prefixed API-key model capabilities / 修复带前缀 API Key 模型的能力路由 Jul 13, 2026
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch 3 times, most recently from e3b8e55 to f4c873f Compare July 17, 2026 19:54

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f4c873fc56

ℹ️ 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".

Comment thread internal/registry/model_registry.go Outdated
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch from f4c873f to 44a8687 Compare July 17, 2026 20:12
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch from 44a8687 to 6e200ac Compare July 18, 2026 19:07

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e200acd07

ℹ️ 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".

Comment thread sdk/cliproxy/auth/config_apikey.go
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch from 6e200ac to fa9a29a Compare July 18, 2026 19:26

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fa9a29aaf1

ℹ️ 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".

Comment thread sdk/cliproxy/auth/api_key_model_capabilities.go
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch from fa9a29a to 9e63d26 Compare July 18, 2026 19:44

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e63d269c2

ℹ️ 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".

Comment thread sdk/cliproxy/auth/api_key_model_capabilities.go
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch from 9e63d26 to a24857d Compare July 18, 2026 20:01

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a24857dd34

ℹ️ 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".

Comment thread internal/thinking/apply.go Outdated
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch 2 times, most recently from 07a1fa4 to bcad9cc Compare July 18, 2026 20:35

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bcad9ccfe3

ℹ️ 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".

Comment thread sdk/api/handlers/openai/openai_images_handlers.go
Comment thread sdk/cliproxy/service.go Outdated
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch from bcad9cc to 9b07498 Compare July 18, 2026 21:21

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9b074988a9

ℹ️ 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".

Comment thread internal/watcher/diff/model_hash.go Outdated
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch from 9b07498 to 296a958 Compare July 18, 2026 21:31

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 296a958a41

ℹ️ 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".

Comment thread sdk/cliproxy/auth/conductor.go
@rdself
rdself force-pushed the coder/api-key-prefix-capabilities-v3 branch from 296a958 to 820698b Compare July 18, 2026 21:59
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.

2 participants