From d1e3195e6ff412c81f36413ee4e6aa16daf8b15c Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Tue, 10 Mar 2026 11:20:37 +0800 Subject: [PATCH] feat(codex): register models by plan tier --- internal/registry/model_definitions.go | 4 +- .../registry/model_definitions_static_data.go | 496 +++++++++++++++++- .../runtime/executor/claude_executor_test.go | 4 +- internal/watcher/synthesizer/file.go | 11 + .../openai/openai_responses_websocket_test.go | 1 - sdk/auth/codex_device.go | 3 + sdk/cliproxy/service.go | 17 +- 7 files changed, 517 insertions(+), 19 deletions(-) diff --git a/internal/registry/model_definitions.go b/internal/registry/model_definitions.go index c1796979..1eb774ef 100644 --- a/internal/registry/model_definitions.go +++ b/internal/registry/model_definitions.go @@ -35,7 +35,7 @@ func GetStaticModelDefinitionsByChannel(channel string) []*ModelInfo { case "aistudio": return GetAIStudioModels() case "codex": - return GetOpenAIModels() + return GetCodexProModels() case "qwen": return GetQwenModels() case "iflow": @@ -83,7 +83,7 @@ func LookupStaticModelInfo(modelID string) *ModelInfo { GetGeminiVertexModels(), GetGeminiCLIModels(), GetAIStudioModels(), - GetOpenAIModels(), + GetCodexProModels(), GetQwenModels(), GetIFlowModels(), GetKimiModels(), diff --git a/internal/registry/model_definitions_static_data.go b/internal/registry/model_definitions_static_data.go index 5cf472ba..cc2136ef 100644 --- a/internal/registry/model_definitions_static_data.go +++ b/internal/registry/model_definitions_static_data.go @@ -364,6 +364,10 @@ func GetGeminiVertexModels() []*ModelInfo { Version: "3.1", DisplayName: "Gemini 3.1 Flash Image Preview", Description: "Gemini 3.1 Flash Image Preview", + InputTokenLimit: 1048576, + OutputTokenLimit: 65536, + SupportedGenerationMethods: []string{"generateContent", "countTokens", "createCachedContent", "batchGenerateContent"}, + Thinking: &ThinkingSupport{Min: 128, Max: 32768, ZeroAllowed: false, DynamicAllowed: true, Levels: []string{"minimal", "high"}}, }, { ID: "gemini-3.1-flash-lite-preview", @@ -756,8 +760,474 @@ func GetAIStudioModels() []*ModelInfo { } } -// GetOpenAIModels returns the standard OpenAI model definitions -func GetOpenAIModels() []*ModelInfo { +// GetCodexFreeModels returns model definitions for the Codex free plan tier. +func GetCodexFreeModels() []*ModelInfo { + return []*ModelInfo{ + { + ID: "gpt-5", + Object: "model", + Created: 1754524800, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5-2025-08-07", + DisplayName: "GPT 5", + Description: "Stable version of GPT 5, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"minimal", "low", "medium", "high"}}, + }, + { + ID: "gpt-5-codex", + Object: "model", + Created: 1757894400, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5-2025-09-15", + DisplayName: "GPT 5 Codex", + Description: "Stable version of GPT 5 Codex, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}, + }, + { + ID: "gpt-5-codex-mini", + Object: "model", + Created: 1762473600, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5-2025-11-07", + DisplayName: "GPT 5 Codex Mini", + Description: "Stable version of GPT 5 Codex Mini: cheaper, faster, but less capable version of GPT 5 Codex.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}, + }, + { + ID: "gpt-5.1", + Object: "model", + Created: 1762905600, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5", + Description: "Stable version of GPT 5, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"none", "low", "medium", "high"}}, + }, + { + ID: "gpt-5.1-codex", + Object: "model", + Created: 1762905600, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5.1 Codex", + Description: "Stable version of GPT 5.1 Codex, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}, + }, + { + ID: "gpt-5.1-codex-mini", + Object: "model", + Created: 1762905600, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5.1 Codex Mini", + Description: "Stable version of GPT 5.1 Codex Mini: cheaper, faster, but less capable version of GPT 5.1 Codex.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}, + }, + { + ID: "gpt-5.1-codex-max", + Object: "model", + Created: 1763424000, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-max", + DisplayName: "GPT 5.1 Codex Max", + Description: "Stable version of GPT 5.1 Codex Max", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high", "xhigh"}}, + }, + { + ID: "gpt-5.2", + Object: "model", + Created: 1765440000, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.2", + DisplayName: "GPT 5.2", + Description: "Stable version of GPT 5.2", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"none", "low", "medium", "high", "xhigh"}}, + }, + { + ID: "gpt-5.2-codex", + Object: "model", + Created: 1765440000, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.2", + DisplayName: "GPT 5.2 Codex", + Description: "Stable version of GPT 5.2 Codex, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high", "xhigh"}}, + }, + } +} + +// GetCodexTeamModels returns model definitions for the Codex team plan tier. +func GetCodexTeamModels() []*ModelInfo { + return []*ModelInfo{ + { + ID: "gpt-5", + Object: "model", + Created: 1754524800, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5-2025-08-07", + DisplayName: "GPT 5", + Description: "Stable version of GPT 5, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"minimal", "low", "medium", "high"}}, + }, + { + ID: "gpt-5-codex", + Object: "model", + Created: 1757894400, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5-2025-09-15", + DisplayName: "GPT 5 Codex", + Description: "Stable version of GPT 5 Codex, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}, + }, + { + ID: "gpt-5-codex-mini", + Object: "model", + Created: 1762473600, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5-2025-11-07", + DisplayName: "GPT 5 Codex Mini", + Description: "Stable version of GPT 5 Codex Mini: cheaper, faster, but less capable version of GPT 5 Codex.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}, + }, + { + ID: "gpt-5.1", + Object: "model", + Created: 1762905600, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5", + Description: "Stable version of GPT 5, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"none", "low", "medium", "high"}}, + }, + { + ID: "gpt-5.1-codex", + Object: "model", + Created: 1762905600, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5.1 Codex", + Description: "Stable version of GPT 5.1 Codex, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}, + }, + { + ID: "gpt-5.1-codex-mini", + Object: "model", + Created: 1762905600, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5.1 Codex Mini", + Description: "Stable version of GPT 5.1 Codex Mini: cheaper, faster, but less capable version of GPT 5.1 Codex.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}, + }, + { + ID: "gpt-5.1-codex-max", + Object: "model", + Created: 1763424000, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-max", + DisplayName: "GPT 5.1 Codex Max", + Description: "Stable version of GPT 5.1 Codex Max", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high", "xhigh"}}, + }, + { + ID: "gpt-5.2", + Object: "model", + Created: 1765440000, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.2", + DisplayName: "GPT 5.2", + Description: "Stable version of GPT 5.2", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"none", "low", "medium", "high", "xhigh"}}, + }, + { + ID: "gpt-5.2-codex", + Object: "model", + Created: 1765440000, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.2", + DisplayName: "GPT 5.2 Codex", + Description: "Stable version of GPT 5.2 Codex, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high", "xhigh"}}, + }, + { + ID: "gpt-5.3-codex", + Object: "model", + Created: 1770307200, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.3", + DisplayName: "GPT 5.3 Codex", + Description: "Stable version of GPT 5.3 Codex, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high", "xhigh"}}, + }, + { + ID: "gpt-5.4", + Object: "model", + Created: 1772668800, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.4", + DisplayName: "GPT 5.4", + Description: "Stable version of GPT 5.4", + ContextLength: 1_050_000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high", "xhigh"}}, + }, + } +} + +// GetCodexPlusModels returns model definitions for the Codex plus plan tier. +func GetCodexPlusModels() []*ModelInfo { + return []*ModelInfo{ + { + ID: "gpt-5", + Object: "model", + Created: 1754524800, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5-2025-08-07", + DisplayName: "GPT 5", + Description: "Stable version of GPT 5, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"minimal", "low", "medium", "high"}}, + }, + { + ID: "gpt-5-codex", + Object: "model", + Created: 1757894400, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5-2025-09-15", + DisplayName: "GPT 5 Codex", + Description: "Stable version of GPT 5 Codex, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}, + }, + { + ID: "gpt-5-codex-mini", + Object: "model", + Created: 1762473600, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5-2025-11-07", + DisplayName: "GPT 5 Codex Mini", + Description: "Stable version of GPT 5 Codex Mini: cheaper, faster, but less capable version of GPT 5 Codex.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}, + }, + { + ID: "gpt-5.1", + Object: "model", + Created: 1762905600, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5", + Description: "Stable version of GPT 5, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"none", "low", "medium", "high"}}, + }, + { + ID: "gpt-5.1-codex", + Object: "model", + Created: 1762905600, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5.1 Codex", + Description: "Stable version of GPT 5.1 Codex, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}, + }, + { + ID: "gpt-5.1-codex-mini", + Object: "model", + Created: 1762905600, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5.1 Codex Mini", + Description: "Stable version of GPT 5.1 Codex Mini: cheaper, faster, but less capable version of GPT 5.1 Codex.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}, + }, + { + ID: "gpt-5.1-codex-max", + Object: "model", + Created: 1763424000, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-max", + DisplayName: "GPT 5.1 Codex Max", + Description: "Stable version of GPT 5.1 Codex Max", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high", "xhigh"}}, + }, + { + ID: "gpt-5.2", + Object: "model", + Created: 1765440000, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.2", + DisplayName: "GPT 5.2", + Description: "Stable version of GPT 5.2", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"none", "low", "medium", "high", "xhigh"}}, + }, + { + ID: "gpt-5.2-codex", + Object: "model", + Created: 1765440000, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.2", + DisplayName: "GPT 5.2 Codex", + Description: "Stable version of GPT 5.2 Codex, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high", "xhigh"}}, + }, + { + ID: "gpt-5.3-codex", + Object: "model", + Created: 1770307200, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.3", + DisplayName: "GPT 5.3 Codex", + Description: "Stable version of GPT 5.3 Codex, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high", "xhigh"}}, + }, + { + ID: "gpt-5.3-codex-spark", + Object: "model", + Created: 1770912000, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.3", + DisplayName: "GPT 5.3 Codex Spark", + Description: "Ultra-fast coding model.", + ContextLength: 128000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high", "xhigh"}}, + }, + { + ID: "gpt-5.4", + Object: "model", + Created: 1772668800, + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.4", + DisplayName: "GPT 5.4", + Description: "Stable version of GPT 5.4", + ContextLength: 1_050_000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high", "xhigh"}}, + }, + } +} + +// GetCodexProModels returns model definitions for the Codex pro plan tier. +func GetCodexProModels() []*ModelInfo { return []*ModelInfo{ { ID: "gpt-5", @@ -1047,18 +1517,18 @@ type AntigravityModelConfig struct { // Keys use upstream model names returned by the Antigravity models endpoint. func GetAntigravityModelConfig() map[string]*AntigravityModelConfig { return map[string]*AntigravityModelConfig{ - "gemini-2.5-flash": {Thinking: &ThinkingSupport{Min: 0, Max: 24576, ZeroAllowed: true, DynamicAllowed: true}}, - "gemini-2.5-flash-lite": {Thinking: &ThinkingSupport{Min: 0, Max: 24576, ZeroAllowed: true, DynamicAllowed: true}}, - "gemini-3-pro-high": {Thinking: &ThinkingSupport{Min: 128, Max: 32768, ZeroAllowed: false, DynamicAllowed: true, Levels: []string{"low", "high"}}}, - "gemini-3-pro-low": {Thinking: &ThinkingSupport{Min: 128, Max: 32768, ZeroAllowed: false, DynamicAllowed: true, Levels: []string{"low", "high"}}}, - "gemini-3.1-pro-high": {Thinking: &ThinkingSupport{Min: 128, Max: 32768, ZeroAllowed: false, DynamicAllowed: true, Levels: []string{"low", "high"}}}, - "gemini-3.1-pro-low": {Thinking: &ThinkingSupport{Min: 128, Max: 32768, ZeroAllowed: false, DynamicAllowed: true, Levels: []string{"low", "high"}}}, - "gemini-3.1-flash-image": {Thinking: &ThinkingSupport{Min: 128, Max: 32768, ZeroAllowed: false, DynamicAllowed: true, Levels: []string{"minimal", "high"}}}, + "gemini-2.5-flash": {Thinking: &ThinkingSupport{Min: 0, Max: 24576, ZeroAllowed: true, DynamicAllowed: true}}, + "gemini-2.5-flash-lite": {Thinking: &ThinkingSupport{Min: 0, Max: 24576, ZeroAllowed: true, DynamicAllowed: true}}, + "gemini-3-pro-high": {Thinking: &ThinkingSupport{Min: 128, Max: 32768, ZeroAllowed: false, DynamicAllowed: true, Levels: []string{"low", "high"}}}, + "gemini-3-pro-low": {Thinking: &ThinkingSupport{Min: 128, Max: 32768, ZeroAllowed: false, DynamicAllowed: true, Levels: []string{"low", "high"}}}, + "gemini-3.1-pro-high": {Thinking: &ThinkingSupport{Min: 128, Max: 32768, ZeroAllowed: false, DynamicAllowed: true, Levels: []string{"low", "high"}}}, + "gemini-3.1-pro-low": {Thinking: &ThinkingSupport{Min: 128, Max: 32768, ZeroAllowed: false, DynamicAllowed: true, Levels: []string{"low", "high"}}}, + "gemini-3.1-flash-image": {Thinking: &ThinkingSupport{Min: 128, Max: 32768, ZeroAllowed: false, DynamicAllowed: true, Levels: []string{"minimal", "high"}}}, "gemini-3.1-flash-lite-preview": {Thinking: &ThinkingSupport{Min: 128, Max: 32768, ZeroAllowed: false, DynamicAllowed: true, Levels: []string{"minimal", "high"}}}, - "gemini-3-flash": {Thinking: &ThinkingSupport{Min: 128, Max: 32768, ZeroAllowed: false, DynamicAllowed: true, Levels: []string{"minimal", "low", "medium", "high"}}}, - "claude-opus-4-6-thinking": {Thinking: &ThinkingSupport{Min: 1024, Max: 64000, ZeroAllowed: true, DynamicAllowed: true}, MaxCompletionTokens: 64000}, - "claude-sonnet-4-6": {Thinking: &ThinkingSupport{Min: 1024, Max: 64000, ZeroAllowed: true, DynamicAllowed: true}, MaxCompletionTokens: 64000}, - "gpt-oss-120b-medium": {}, + "gemini-3-flash": {Thinking: &ThinkingSupport{Min: 128, Max: 32768, ZeroAllowed: false, DynamicAllowed: true, Levels: []string{"minimal", "low", "medium", "high"}}}, + "claude-opus-4-6-thinking": {Thinking: &ThinkingSupport{Min: 1024, Max: 64000, ZeroAllowed: true, DynamicAllowed: true}, MaxCompletionTokens: 64000}, + "claude-sonnet-4-6": {Thinking: &ThinkingSupport{Min: 1024, Max: 64000, ZeroAllowed: true, DynamicAllowed: true}, MaxCompletionTokens: 64000}, + "gpt-oss-120b-medium": {}, } } diff --git a/internal/runtime/executor/claude_executor_test.go b/internal/runtime/executor/claude_executor_test.go index 7bf77a7a..fa458c0f 100644 --- a/internal/runtime/executor/claude_executor_test.go +++ b/internal/runtime/executor/claude_executor_test.go @@ -842,8 +842,8 @@ func TestClaudeExecutor_ExecuteStream_AcceptEncodingOverrideCannotBypassIdentity executor := NewClaudeExecutor(&config.Config{}) // Inject Accept-Encoding via the custom header attribute mechanism. auth := &cliproxyauth.Auth{Attributes: map[string]string{ - "api_key": "key-123", - "base_url": server.URL, + "api_key": "key-123", + "base_url": server.URL, "header:Accept-Encoding": "gzip, deflate, br, zstd", }} payload := []byte(`{"messages":[{"role":"user","content":[{"type":"text","text":"hi"}]}]}`) diff --git a/internal/watcher/synthesizer/file.go b/internal/watcher/synthesizer/file.go index 02a0cefa..ab54aeaa 100644 --- a/internal/watcher/synthesizer/file.go +++ b/internal/watcher/synthesizer/file.go @@ -10,6 +10,7 @@ import ( "strings" "time" + "github.com/router-for-me/CLIProxyAPI/v6/internal/auth/codex" "github.com/router-for-me/CLIProxyAPI/v6/internal/runtime/geminicli" coreauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth" ) @@ -149,6 +150,16 @@ func synthesizeFileAuths(ctx *SynthesisContext, fullPath string, data []byte) [] } } ApplyAuthExcludedModelsMeta(a, cfg, perAccountExcluded, "oauth") + // For codex auth files, extract plan_type from the JWT id_token. + if provider == "codex" { + if idTokenRaw, ok := metadata["id_token"].(string); ok && strings.TrimSpace(idTokenRaw) != "" { + if claims, errParse := codex.ParseJWTToken(idTokenRaw); errParse == nil && claims != nil { + if pt := strings.TrimSpace(claims.CodexAuthInfo.ChatgptPlanType); pt != "" { + a.Attributes["plan_type"] = pt + } + } + } + } if provider == "gemini-cli" { if virtuals := SynthesizeGeminiVirtualAuths(a, metadata, now); len(virtuals) > 0 { for _, v := range virtuals { diff --git a/sdk/api/handlers/openai/openai_responses_websocket_test.go b/sdk/api/handlers/openai/openai_responses_websocket_test.go index c7348583..981c6630 100644 --- a/sdk/api/handlers/openai/openai_responses_websocket_test.go +++ b/sdk/api/handlers/openai/openai_responses_websocket_test.go @@ -266,7 +266,6 @@ func TestAppendWebsocketEvent(t *testing.T) { } } - func TestAppendWebsocketEventTruncatesAtLimit(t *testing.T) { var builder strings.Builder payload := bytes.Repeat([]byte("x"), wsBodyLogMaxSize) diff --git a/sdk/auth/codex_device.go b/sdk/auth/codex_device.go index 78a95af8..10f59fb9 100644 --- a/sdk/auth/codex_device.go +++ b/sdk/auth/codex_device.go @@ -287,5 +287,8 @@ func (a *CodexAuthenticator) buildAuthRecord(authSvc *codex.CodexAuth, authBundl FileName: fileName, Storage: tokenStorage, Metadata: metadata, + Attributes: map[string]string{ + "plan_type": planType, + }, }, nil } diff --git a/sdk/cliproxy/service.go b/sdk/cliproxy/service.go index 10cc35f3..596db3dd 100644 --- a/sdk/cliproxy/service.go +++ b/sdk/cliproxy/service.go @@ -829,7 +829,22 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) { } models = applyExcludedModels(models, excluded) case "codex": - models = registry.GetOpenAIModels() + codexPlanType := "" + if a.Attributes != nil { + codexPlanType = strings.TrimSpace(a.Attributes["plan_type"]) + } + switch strings.ToLower(codexPlanType) { + case "pro": + models = registry.GetCodexProModels() + case "plus": + models = registry.GetCodexPlusModels() + case "team": + models = registry.GetCodexTeamModels() + case "free": + models = registry.GetCodexFreeModels() + default: + models = registry.GetCodexProModels() + } if entry := s.resolveConfigCodexKey(a); entry != nil { if len(entry.Models) > 0 { models = buildCodexConfigModels(entry)