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

Run combo health probes concurrently

R.D.ba227c5ec304
diff --git a/src/app/api/combos/test/route.ts b/src/app/api/combos/test/route.ts
index fb9888ea29..5e93979a79 100644
--- a/src/app/api/combos/test/route.ts
+++ b/src/app/api/combos/test/route.ts
@@ -5,6 +5,87 @@ import { getComboByName } from "@/lib/localDb";
import { testComboSchema } from "@/shared/validation/schemas";
import { isValidationFailure, validateBody } from "@/shared/validation/helpers";
+async function testComboModel(modelStr, internalUrl) {
+ const startTime = Date.now();
+ try {
+ // Send a minimal but real chat request through the same internal
+ // endpoint an external OpenAI-compatible client would use.
+ const testBody = buildComboTestRequestBody(modelStr);
+
+ const controller = new AbortController();
+ const timeout = setTimeout(() => controller.abort(), 20000);
+
+ let res;
+ try {
+ res = await fetch(internalUrl, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ // Internal dashboard tests still use the normal /v1 pipeline but
+ // bypass REQUIRE_API_KEY so admins can test with local session auth.
+ "X-Internal-Test": "combo-health-check",
+ // Force a fresh execution path so combo tests cannot be satisfied by
+ // OmniRoute's semantic cache or other request reuse layers.
+ "X-OmniRoute-No-Cache": "true",
+ "X-Request-Id": `combo-test-${randomUUID()}`,
+ },
+ body: JSON.stringify(testBody),
+ signal: controller.signal,
+ });
+ } finally {
+ clearTimeout(timeout);
+ }
+
+ const latencyMs = Date.now() - startTime;
+
+ if (res.ok) {
+ let responseBody = null;
+ try {
+ responseBody = await res.json();
+ } catch {
+ responseBody = null;
+ }
+
+ const responseText = extractComboTestResponseText(responseBody);
+ if (!responseText) {
+ return {
+ model: modelStr,
+ status: "error",
+ statusCode: res.status,
+ error: "Provider returned HTTP 200 but no text content.",
+ latencyMs,
+ };
+ }
+
+ return { model: modelStr, status: "ok", latencyMs, responseText };
+ }
+
+ let errorMsg = "";
+ try {
+ const errBody = await res.json();
+ errorMsg = errBody?.error?.message || errBody?.error || res.statusText;
+ } catch {
+ errorMsg = res.statusText;
+ }
+
+ return {
+ model: modelStr,
+ status: "error",
+ statusCode: res.status,
+ error: errorMsg,
+ latencyMs,
+ };
+ } catch (error) {
+ const latencyMs = Date.now() - startTime;
+ return {
+ model: modelStr,
+ status: "error",
+ error: error.name === "AbortError" ? "Timeout (20s)" : error.message,
+ latencyMs,
+ };
+ }
+}
+
/**
* POST /api/combos/test - Quick test a combo
* Sends a real chat completion request through each model in the combo
@@ -44,93 +125,11 @@ export async function POST(request) {
return NextResponse.json({ error: "Combo has no models" }, { status: 400 });
}
- const results = [];
- let resolvedBy = null;
-
- // Test each model sequentially
- for (const modelStr of models) {
- const startTime = Date.now();
- try {
- // Send a minimal but real chat request through the same internal
- // endpoint an external OpenAI-compatible client would use.
- const testBody = buildComboTestRequestBody(modelStr);
-
- const internalUrl = `${getBaseUrl(request)}/v1/chat/completions`;
- const controller = new AbortController();
- const timeout = setTimeout(() => controller.abort(), 20000);
-
- let res;
- try {
- res = await fetch(internalUrl, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- // Internal dashboard tests still use the normal /v1 pipeline but
- // bypass REQUIRE_API_KEY so admins can test with local session auth.
- "X-Internal-Test": "combo-health-check",
- // Force a fresh execution path so combo tests cannot be satisfied by
- // OmniRoute's semantic cache or other request reuse layers.
- "X-OmniRoute-No-Cache": "true",
- "X-Request-Id": `combo-test-${randomUUID()}`,
- },
- body: JSON.stringify(testBody),
- signal: controller.signal,
- });
- } finally {
- clearTimeout(timeout);
- }
-
- const latencyMs = Date.now() - startTime;
-
- if (res.ok) {
- let responseBody = null;
- try {
- responseBody = await res.json();
- } catch {
- responseBody = null;
- }
-
- const responseText = extractComboTestResponseText(responseBody);
- if (!responseText) {
- results.push({
- model: modelStr,
- status: "error",
- statusCode: res.status,
- error: "Provider returned HTTP 200 but no text content.",
- latencyMs,
- });
- continue;
- }
-
- results.push({ model: modelStr, status: "ok", latencyMs, responseText });
- if (!resolvedBy) resolvedBy = modelStr;
- } else {
- let errorMsg = "";
- try {
- const errBody = await res.json();
- errorMsg = errBody?.error?.message || errBody?.error || res.statusText;
- } catch {
- errorMsg = res.statusText;
- }
-
- results.push({
- model: modelStr,
- status: "error",
- statusCode: res.status,
- error: errorMsg,
- latencyMs,
- });
- }
- } catch (error) {
- const latencyMs = Date.now() - startTime;
- results.push({
- model: modelStr,
- status: "error",
- error: error.name === "AbortError" ? "Timeout (20s)" : error.message,
- latencyMs,
- });
- }
- }
+ const internalUrl = `${getBaseUrl(request)}/v1/chat/completions`;
+ const results = await Promise.all(
+ models.map((modelStr) => testComboModel(modelStr, internalUrl))
+ );
+ const resolvedBy = results.find((result) => result.status === "ok")?.model || null;
return NextResponse.json({
comboName,
diff --git a/tests/unit/combo-test-route.test.mjs b/tests/unit/combo-test-route.test.mjs
index 3f09834152..3a75a3322f 100644
--- a/tests/unit/combo-test-route.test.mjs
+++ b/tests/unit/combo-test-route.test.mjs
@@ -189,3 +189,67 @@ test("combo test route surfaces provider errors instead of downgrading them to r
assert.equal(body.results[0].error, "Upstream rejected this request shape");
assert.equal("probeMethod" in body.results[0], false);
});
+
+test("combo test route launches model probes concurrently while preserving combo order", async () => {
+ await createTestCombo(["provider/first", "provider/second", "provider/third"]);
+
+ const fetchCalls = [];
+ const resolvers = [];
+ globalThis.fetch = (url, init = {}) =>
+ new Promise((resolve) => {
+ fetchCalls.push({ url: String(url), init });
+ resolvers.push(resolve);
+ });
+
+ const responsePromise = route.POST(makeRequest());
+ await new Promise((resolve) => setTimeout(resolve, 0));
+
+ assert.equal(fetchCalls.length, 3);
+ assert.deepEqual(
+ fetchCalls.map(({ init }) => JSON.parse(init.body).model),
+ ["provider/first", "provider/second", "provider/third"]
+ );
+
+ resolvers[2](
+ new Response(
+ JSON.stringify({
+ choices: [{ message: { role: "assistant", content: "THIRD" } }],
+ }),
+ { status: 200, headers: { "content-type": "application/json" } }
+ )
+ );
+ resolvers[1](
+ new Response(
+ JSON.stringify({
+ choices: [{ message: { role: "assistant", content: "SECOND" } }],
+ }),
+ { status: 200, headers: { "content-type": "application/json" } }
+ )
+ );
+ resolvers[0](
+ new Response(
+ JSON.stringify({
+ choices: [{ message: { role: "assistant", content: "FIRST" } }],
+ }),
+ { status: 200, headers: { "content-type": "application/json" } }
+ )
+ );
+
+ const response = await responsePromise;
+ const body = await response.json();
+
+ assert.equal(response.status, 200);
+ assert.equal(body.resolvedBy, "provider/first");
+ assert.deepEqual(
+ body.results.map((result) => ({
+ model: result.model,
+ status: result.status,
+ responseText: result.responseText,
+ })),
+ [
+ { model: "provider/first", status: "ok", responseText: "FIRST" },
+ { model: "provider/second", status: "ok", responseText: "SECOND" },
+ { model: "provider/third", status: "ok", responseText: "THIRD" },
+ ]
+ );
+});