sub2api icon indicating copy to clipboard operation
sub2api copied to clipboard

OpenAI passthrough account wrongly excluded by `model_mapping` whitelist during account selection (passthrough bypass missing in scheduler eligibility)

Open HuntercodeT opened this issue 4 months ago • 0 comments

Summary

For an OpenAI OAuth account with auto-passthrough enabled (extra.openai_passthrough = true, "replace auth only, allow all models"), the gateway still refuses to route a model that is not listed in the account's credentials.model_mapping. The request fails account selection and the client receives:

404 Model "<model>" is not supported by any configured account in this group

even though the account can actually serve that model (a direct "test account connection" with the same model succeeds).

Root cause: the OpenAI account-selection eligibility check calls Account.IsModelSupported() directly, which enforces the model_mapping allowlist and is unaware of passthrough. A parallel model-support check does honor passthrough, so the two checks are inconsistent.

Environment

  • Version: observed on v0.1.133 (+46 commits); code paths unchanged through at least 0.1.164.
  • Account type: OpenAI OAuth (Codex/ChatGPT), openai_passthrough = true.

Root cause (code references)

Scheduler eligibility — passthrough-blind path used for OpenAI account selection:

  • internal/service/openai_gateway_service.go:1329 isOpenAIAccountEligibleForRequest(...)
    • line 1344: if requestedModel != "" && !account.IsModelSupported(requestedModel) { return false }
  • internal/service/account.go:622 func (a *Account) IsModelSupported(requestedModel string) bool
    • Returns true only if the account has no model_mapping (len==0 → allow all) or the model is present in the mapping. It has no passthrough awareness.

Parallel model-support check that does honor passthrough (inconsistent with the above):

  • internal/service/gateway_service.go:3801 func (s *GatewayService) isModelSupportedByAccount(...)
    • line 3813: if account.Platform == PlatformOpenAI && account.IsOpenAIPassthroughEnabled() { return true } (bypasses the whitelist for passthrough accounts, then falls back to IsModelSupported)
  • internal/service/account.go:1287 func (a *Account) IsOpenAIPassthroughEnabled() bool

Because isOpenAIAccountEligibleForRequest uses the passthrough-blind check, a passthrough account with a non-empty model_mapping is filtered out of the candidate set for any model not in the mapping → zero candidates → ErrNoAvailableAccounts.

Steps to reproduce

  1. Configure an OpenAI OAuth account and enable auto-passthrough (`extra.openai_passthrough = true).
  2. Ensure the account has a non-empty credentials.model_mapping that does not include some model M that the account can actually serve (e.g. a newly-released model). Note: such a mapping is commonly left over from before passthrough was enabled.
  3. Put the account in a group and, as a client of that group, request model M, e.g. POST /responses with {"model":"M", ...}.

Expected

The request is routed to the account (passthrough means "only replace auth, allow all models"), and M is forwarded upstream as-is.

Actual

  • Account selection excludes the account: openai.account_select_failed, error: "no available accounts", excluded_account_count: 0.
  • Client receives 404 Model "M" is not supported by any configured account in this group.
  • A direct admin "test account connection" with model M on the same account succeeds (it bypasses IsModelSupported), which is what makes the failure look contradictory.

Suggested fix

In isOpenAIAccountEligibleForRequest, honor passthrough before the whitelist check — either:

  • short-circuit when account.Platform == PlatformOpenAI && account.IsOpenAIPassthroughEnabled() (mirroring isModelSupportedByAccount:3813), or
  • route the model-support check through the passthrough-aware isModelSupportedByAccount instead of calling account.IsModelSupported directly.

Workaround (for operators)

Clear credentials.model_mapping on passthrough OpenAI accounts. Note that clearing it via the admin UI may not persist (the edit form can resubmit the existing mapping); clearing it directly in the DB (credentials = credentials - 'model_mapping') and restarting the backend (to drop the cached account) is reliable

HuntercodeT avatar Jul 27 '26 02:07 HuntercodeT