diff --git a/sdk/cliproxy/service.go b/sdk/cliproxy/service.go index dd22987fd7..54ba7dbb17 100644 --- a/sdk/cliproxy/service.go +++ b/sdk/cliproxy/service.go @@ -879,6 +879,11 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) { if a.Attributes != nil { codexPlanType = strings.TrimSpace(a.Attributes["plan_type"]) } + if authKind != "apikey" { + if override := codexOAuthPlanOverride(); override != "" { + codexPlanType = override + } + } switch strings.ToLower(codexPlanType) { case "pro": models = registry.GetCodexProModels() @@ -1180,6 +1185,20 @@ func (s *Service) resolveConfigCodexKey(auth *coreauth.Auth) *config.CodexKey { return nil } +func codexOAuthPlanOverride() string { + raw := strings.TrimSpace(os.Getenv("CODEX_OAUTH_PLAN_OVERRIDE")) + if raw == "" { + return "" + } + switch strings.ToLower(raw) { + case "free", "plus", "pro", "team", "business", "go": + return raw + default: + log.Warnf("ignoring invalid CODEX_OAUTH_PLAN_OVERRIDE value: %q", raw) + return "" + } +} + func (s *Service) oauthExcludedModels(provider, authKind string) []string { cfg := s.cfg if cfg == nil { diff --git a/sdk/cliproxy/service_codex_plan_override_test.go b/sdk/cliproxy/service_codex_plan_override_test.go new file mode 100644 index 0000000000..3359a46f7e --- /dev/null +++ b/sdk/cliproxy/service_codex_plan_override_test.go @@ -0,0 +1,51 @@ +package cliproxy + +import ( + "testing" + + "github.com/router-for-me/CLIProxyAPI/v6/internal/registry" + coreauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth" +) + +func TestRegisterModelsForAuth_CodexOAuthPlanOverride(t *testing.T) { + t.Setenv("CODEX_OAUTH_PLAN_OVERRIDE", "pro") + + service := &Service{} + auth := &coreauth.Auth{ + ID: "auth-codex-override", + Provider: "codex", + Status: coreauth.StatusActive, + Attributes: map[string]string{ + "auth_kind": "oauth", + "plan_type": "free", + }, + } + + modelRegistry := registry.GetGlobalRegistry() + modelRegistry.UnregisterClient(auth.ID) + t.Cleanup(func() { + modelRegistry.UnregisterClient(auth.ID) + }) + + service.registerModelsForAuth(auth) + + models := modelRegistry.GetModelsForClient(auth.ID) + if len(models) == 0 { + t.Fatal("expected codex models to be registered") + } + + has54 := false + for _, model := range models { + if model == nil { + continue + } + if model.ID == "gpt-5.4" { + has54 = true + break + } + } + + if !has54 { + t.Fatal("expected CODEX_OAUTH_PLAN_OVERRIDE=pro to expose gpt-5.4") + } +}