different-ai/openwork · error

Endpoint test returned an unexpected response.

Error message

Endpoint test returned an unexpected response.

What it means

After a successful (2xx) POST to /v1/llm-providers/test-connection, the function expects payload.result to be a valid probe result; if asProbeResult cannot coerce payload.result, the 200 response is considered malformed and this error is thrown. It protects callers from trusting an unparseable probe result.

Source

Thrown at ee/apps/den-web/app/(den)/dashboard/_components/llm-provider-data.tsx:455

 * mistakes and returns the model ids the endpoint actually serves.
 */
export async function requestLlmProviderTestConnection(input: {
  api: string;
  apiKey?: string;
  modelIds?: string[];
}) {
  const timeoutMs = input.modelIds?.length ? 60000 : 20000;
  const { response, payload } = await requestJson(
    `/v1/llm-providers/test-connection`,
    { method: "POST", body: JSON.stringify(input) },
    timeoutMs,
  );
  if (!response.ok) {
    throw new Error(getErrorMessage(payload, `Endpoint test failed (${response.status}).`));
  }
  const result = isRecord(payload) ? asProbeResult(payload.result) : null;
  if (!result) {
    throw new Error("Endpoint test returned an unexpected response.");
  }
  const verifications = isRecord(payload) && Array.isArray(payload.verifications)
    ? payload.verifications
        .map(asModelVerification)
        .filter((entry): entry is LlmProviderModelVerification => entry !== null)
    : [];
  return { ...result, verifications };
}

export async function requestLlmProviderCatalog(orgId: string) {
  const { response, payload } = await requestJson(`/v1/llm-provider-catalog`, { method: "GET" }, 20000);
  if (!response.ok) {
    throw new Error(getErrorMessage(payload, `Failed to load the provider catalog (${response.status}).`));
  }

  return isRecord(payload) && Array.isArray(payload.providers)
    ? payload.providers.map(asCatalogProviderSummary).filter((entry): entry is DenModelsDevProviderSummary => entry !== null)
    : [];

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Log the raw payload and compare its `result` shape against the LlmProviderProbeResult type / asProbeResult expectations.
  2. Update asProbeResult to match the server's current result schema.
  3. Align frontend and backend deployments so both use the same API version.
  4. Fix the server handler if it returns 200 without a valid result on probe failure (it should return non-ok or a well-formed result).

Example fix

// before (server returns result without ok flag)
return NextResponse.json({ result: { latencyMs: 120 } });
// after
return NextResponse.json({ result: { ok: true, latencyMs: 120 } });
Defensive patterns

Strategy: type-guard

Validate before calling

// after receiving a 2xx, guard before use
function looksLikeProbeResult(p: unknown): boolean {
  return typeof p === "object" && p !== null && typeof (p as {result?:unknown}).result === "object" && (p as {result?:unknown}).result !== null;
}

Type guard

function isProbeResult(v: unknown): v is LlmProviderProbeResult {
  return typeof v === "object" && v !== null && "ok" in v && typeof (v as {ok:unknown}).ok === "boolean";
}

Try / catch

try {
  const result = await requestLlmProviderTestConnection(input, timeoutMs);
} catch (err) {
  if (err instanceof Error && err.message === "Endpoint test returned an unexpected response.") {
    console.error("test-connection 200 body malformed — check server/client versions");
  } else throw err;
}

Prevention

When it happens

Trigger: The test-connection endpoint returns 200 with a body whose `result` field is missing, null, or shaped differently than asProbeResult expects (e.g. newer server fields, changed nesting, plain string instead of object).

Common situations: Frontend and backend version skew after an API change to the probe result schema; a middleware/proxy transforming the JSON; a mock or test server returning a partial body; server bug returning `{}` on success.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/a511e9d09694d517. Report an issue: GitHub.