JuliusBrussee/caveman · error

eval evidence import failed

Error message

eval evidence import failed (${response.status}): ${JSON.stringify(body)}

What it means

Thrown by the `eval evidence import` CLI command after the HTTP POST to the eval evidence import endpoint returns a non-2xx response. The error embeds the HTTP status code and the JSON body returned by the server so the developer can see the API's own error detail. It means the server rejected the import request (bad payload, auth, project, or server-side validation failure), not that the request failed to send.

Solutions

  1. Read the JSON body embedded in the error message — it usually names the exact field or reason the server rejected the import.
  2. Re-authenticate (refresh/login) if the status is 401/403, then retry the import.
  3. Verify the project_id and endpoint URL match the intended environment.
  4. Run with --dry-run first to let the server validate items without committing them.

Example fix

// before
await importEvidence(items); // throws: eval evidence import failed (422): {"error":"invalid item schema"}
// after
try {
  await importEvidence(items);
} catch (e) {
  console.error("import rejected:", (e as Error).message);
  process.exitCode = 1;
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!items.length) throw new Error('no items to import');
if (!process.env.API_TOKEN) throw new Error('not authenticated');

Try / catch

try {
  await importEvidence(items);
} catch (e) {
  const m = /import failed \((\d+)\): (.*)/.exec((e as Error).message);
  if (m) console.error(`HTTP ${m[1]}:`, m[2]);
  process.exitCode = 1;
}

Prevention

When it happens

Trigger: Running the eval evidence import command with --dry-run or a set of items and the server responds with status >= 400; e.g. invalid item payloads, expired/missing auth token, unknown project_id, or server-side validation errors reported in the response body.

Common situations: Importing evidence after the CLI's token expired; posting items that violate the server's schema after an API version bump; pointing the CLI at the wrong environment (staging URL with a project_id that only exists in prod); server returns 422 with field-level errors in the body.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/94bef159b6aa1488. Report an issue: GitHub.

Appendix: source

Thrown at packages/cli/src/index.ts:17637

  if (items.length === 0) throw new Error("eval evidence file contains no records");

  const cfg = await config();
  const project = flagFrom(argv, "--project", cfg.projectId ?? "");
  const response = await fetch(`${cfg.baseURL}/api/v1/eval-evidence/batches`, {
    method: "POST",
    headers: {
      authorization: `Bearer ${cfg.token}`,
      "content-type": "application/json",
      "x-cave-csrf": "cli",
    },
    body: JSON.stringify({
      ...(project ? { project_id: project } : {}),
      dry_run: argv.includes("--dry-run"),
      items,
    }),
  });
  const body = await response.json();
  if (!response.ok) throw new Error(`eval evidence import failed (${response.status}): ${JSON.stringify(body)}`);
  print(body);
}

// ---------------------------------------------------------------------------
// Signed usage receipts: air-gapped export + offline verification.
//
// A receipt is a per-(org,project,day) aggregate, Ed25519-signed and chained by
// prev_receipt_hash. `verify` recomputes each canonical hash, checks the
// signature against the published public key, and walks the chain — all offline,
// so finance (either party) can re-derive trust without contacting Caveman. It is
// the cross-language counterpart of cloud/metering's VerifyChain.
// ---------------------------------------------------------------------------

type ReceiptSignature = { alg: string; key_id: string; sig: string };
type ReceiptScope = { org_hash: string; project_hash: string };
type ReceiptOptimizer = { optimizer_id_hash: string; requests_optimized: number };
type Receipt = {
  schema: string;

View on GitHub (pinned to 3ee70a1026)