Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
fix(codex): apply global service tiers to combo request bodies
Jan Leonaf96e33184dd
diff --git a/src/lib/providers/codexFastTier.ts b/src/lib/providers/codexFastTier.tsindex de796f2087..9fe973e467 100644--- a/src/lib/providers/codexFastTier.ts+++ b/src/lib/providers/codexFastTier.ts@@ -130,8 +130,8 @@ export interface ApplyCodexGlobalFastServiceTierOptions {*/model?: string | null;/**- * Outbound request body. Per-request body.service_tier is left untouched if- * already set.+ * Outbound request body. A valid per-request body.service_tier is left untouched+ * when already set.*/body?: Record<string, unknown> | null;}@@ -188,12 +188,11 @@ export function applyCodexGlobalFastServiceTier<T extends JsonRecord | null | un} as T;}- if (resolved.tier === "flex") {- // Write the wire value directly to the outbound body when possible. The executor- // also accepts requestDefaults.serviceTier = "flex" for downstream accounting.- if (body && typeof body === "object" && !Array.isArray(body)) {- (body as JsonRecord).service_tier = "flex";- }+ if (body && typeof body === "object" && !Array.isArray(body)) {+ // Write the wire value directly to the outbound body when possible, so combo+ // request previews and logs show the same effective tier that the executor sends.+ // The executor also accepts requestDefaults.serviceTier for downstream accounting.+ (body as JsonRecord).service_tier = resolved.tier;}// Intentional precedence: body service_tier > global mode > connection defaults.diff --git a/tests/integration/chat-pipeline.test.ts b/tests/integration/chat-pipeline.test.tsindex 7476240b2c..2773023a11 100644--- a/tests/integration/chat-pipeline.test.ts+++ b/tests/integration/chat-pipeline.test.ts@@ -606,6 +606,47 @@ test("chat pipeline persists Codex responses cache and reasoning tokens to callassert.equal(callLog.tokens.reasoning, 13);});+test("chat pipeline applies global Codex priority service tier inside combos", async () => {+ await seedConnection("codex", { apiKey: "sk-codex-combo-priority" });+ await settingsDb.updateSettings({+ codexServiceTier: { enabled: true, tier: "priority" },+ });+ await combosDb.createCombo({+ name: "codex-priority-combo",+ strategy: "priority",+ config: { maxRetries: 0, retryDelayMs: 0 },+ models: ["codex/gpt-5.5"],+ });+ const fetchCalls = [];++ globalThis.fetch = async (url, init: RequestInit = {}) => {+ fetchCalls.push({+ url: String(url),+ headers: toPlainHeaders(init.headers),+ body: init.body ? JSON.parse(String(init.body)) : null,+ });+ return buildOpenAIResponsesSSE({ text: "combo priority ok", model: "gpt-5.5" });+ };++ const response = await handleChat(+ buildRequest({+ body: {+ model: "codex-priority-combo",+ stream: false,+ messages: [{ role: "user", content: "Use Codex combo priority" }],+ },+ })+ );++ const json = (await response.json()) as any;+ assert.equal(response.status, 200);+ assert.equal(fetchCalls.length, 1);+ assert.match(fetchCalls[0].url, /\/responses$/);+ assert.equal(fetchCalls[0].headers.Authorization, "Bearer sk-codex-combo-priority");+ assert.equal(fetchCalls[0].body.service_tier, "priority");+ assert.equal(json.choices[0].message.content, "combo priority ok");+});+test("chat pipeline applies Codex CLI fingerprint to OAuth responses requests", async () => {setCliCompatProviders(["codex"]);await seedConnection("codex", {@@ -950,12 +991,7 @@ test("chat pipeline sends Gemini CLI OAuth requests with native Cloud Code transassert.equal(generateCall.body.requestId, undefined);assert.equal(generateCall.body.user_prompt_id, generateCall.body.request.session_id);const keys = Object.keys(generateCall.body).slice(0, 4);- assert.deepEqual(keys.sort(), [- "model",- "project",- "request",- "user_prompt_id",- ]);+ assert.deepEqual(keys.sort(), ["model", "project", "request", "user_prompt_id"]);assert.equal(generateCall.body.request.sessionId, undefined);assert.match(generateCall.body.request.session_id, /^[0-9a-f-]{36}$/i);assert.equal(generateCall.body.request.contents.at(-1).parts[0].text, "Hello Gemini CLI");diff --git a/tests/unit/codex-fast-tier.test.ts b/tests/unit/codex-fast-tier.test.tsindex 4aea837ccb..f411574345 100644--- a/tests/unit/codex-fast-tier.test.ts+++ b/tests/unit/codex-fast-tier.test.ts@@ -106,15 +106,17 @@ test("Codex global service tier injects selected mode and can override connectio});test("Codex global service tier matches provider-prefixed combo model ids", () => {+ const body: Record<string, unknown> = {};assert.deepEqual(applyCodexGlobalFastServiceTier("codex",{ providerSpecificData: {} },{ codexServiceTier: { enabled: true, tier: "priority" } },- { model: "codex/gpt-5.5" }+ { model: "codex/gpt-5.5", body }),{ providerSpecificData: { requestDefaults: { serviceTier: "priority" } } });+ assert.equal(body.service_tier, "priority");const unsupported = { providerSpecificData: {} };assert.equal(@@ -155,7 +157,7 @@ test("Codex global service tier only short-circuits on valid body service_tier",assert.deepEqual(injected, {providerSpecificData: { requestDefaults: { serviceTier: "priority" } },});- assert.equal(invalidBody.service_tier, "invalid");+ assert.equal(invalidBody.service_tier, "priority");const validBody: Record<string, unknown> = { service_tier: " Flex " };const unchanged = { providerSpecificData: {} };