Skip to content

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

fix(combo): use resolved provider for custom provider_nodes prefixes (#3058 follow-up)

diegosouzapw5b62a4be88d7
diff --git a/src/sse/handlers/chat.ts b/src/sse/handlers/chat.ts
index 351a436e31..d8b1c65f96 100644
--- a/src/sse/handlers/chat.ts
+++ b/src/sse/handlers/chat.ts
@@ -463,7 +463,15 @@ export async function handleChat(request: any, clientRawRequest: any = null) {
// "xiaomi/mimo-v2-flash" resolves to provider "xiaomi" but the combo
// target specifies providerId: "opengate" for credential lookup).
const modelInfo = await getModelInfo(modelString);
- const provider = target?.providerId || modelInfo.provider;
+ // Apply the same prefix-override guard as handleSingleModelChat:
+ // if providerId is just the prefix already in the model string, use
+ // the fully-resolved modelInfo.provider for a precise credential check.
+ const provider = (() => {
+ if (!target?.providerId) return modelInfo.provider;
+ if (target.providerId === modelInfo.provider) return modelInfo.provider;
+ if (modelString.startsWith(target.providerId + "/")) return modelInfo.provider;
+ return target.providerId;
+ })();
if (!provider) return true; // can't determine provider, let it try
const resolvedModel = modelInfo.model || modelString;
@@ -756,7 +764,21 @@ async function handleSingleModelChat(
// provider prefix may differ from the credential provider ID (e.g. model
// "xiaomi/mimo-v2-flash" resolves to provider "xiaomi" but the combo target
// may specify providerId: "opengate" for credential lookup).
- const provider = runtimeOptions.providerId || resolvedProvider;
+ // Guard: if runtimeOptions.providerId is merely the prefix already encoded in
+ // the model string (e.g. "p2" from "p2/test-model"), and resolveModelOrError
+ // expanded it to a full custom-node ID (e.g. "openai-compatible-chat-e2e-p2"),
+ // trust resolvedProvider so the executor receives the full node ID and can
+ // correctly resolve the custom baseUrl. (#3058 follow-up)
+ const provider = (() => {
+ if (!runtimeOptions.providerId) return resolvedProvider;
+ // If the override is identical to resolvedProvider, no-op.
+ if (runtimeOptions.providerId === resolvedProvider) return resolvedProvider;
+ // If the model string already encodes runtimeOptions.providerId as its prefix,
+ // the override is implicit (not an intentional redirect) — use resolvedProvider.
+ if (modelStr.startsWith(runtimeOptions.providerId + "/")) return resolvedProvider;
+ // Intentional override (e.g. providerId points to a different credential pool).
+ return runtimeOptions.providerId;
+ })();
const forceLiveComboTest = runtimeOptions.forceLiveComboTest === true;
const hasForcedConnection =
typeof runtimeOptions.forcedConnectionId === "string" &&
diff --git a/tests/integration/resilience-http-e2e.test.ts b/tests/integration/resilience-http-e2e.test.ts
index 8e873426f5..fbcb6c0533 100644
--- a/tests/integration/resilience-http-e2e.test.ts
+++ b/tests/integration/resilience-http-e2e.test.ts
@@ -332,7 +332,7 @@ function buildResilienceConfig(overrides: Record<string, unknown> = {}) {
maxBackoffSteps: 3,
},
apikey: {
- baseCooldownMs: 300,
+ baseCooldownMs: 5_000,
useUpstreamRetryHints: false,
maxBackoffSteps: 0,
},
@@ -606,6 +606,10 @@ test("priority combo falls back on 503 and skips the cooled-down primary on the
assert.equal(relay.getState(TOKENS.p1).hits, 1);
assert.equal(relay.getState(TOKENS.p2).hits, 1);
+ // Brief pause to ensure the P1 connection cooldown write has been committed
+ // and is visible to the second request's credential lookup.
+ await sleep(200);
+
const second = await postChat(app.baseUrl, "res-priority-fallback", "priority fallback again");
assert.equal(second.response.status, 200, JSON.stringify(second.json));
assert.equal(second.json.choices[0].message.content, "secondary stable");