JuliusBrussee/caveman · error
cave_provider_cost_mismatch
cave_provider_cost_mismatch
Error message
cave_provider_cost_mismatch
What it means
validateProviderUsage throws cave_provider_cost_mismatch when options.reportedCostUsd is provided but is not a finite non-negative number or differs from the catalog-computed cost (priced.usd) by more than 1e-12 — including the case where the usage is unpriced (priced.priced is false) while a cost was reported.
Solutions
- Omit options.reportedCostUsd if you don't need to assert the reported cost
- Update the library's cost catalog so priced.usd matches current provider pricing
- Compare your reported cost to priced.usd locally and reconcile rounding before calling
- If the cost is genuinely provider-computed, stop enforcing the catalog comparison and record it separately
Example fix
// before
kernel.priced(evidence, { reportedCostUsd: 0.0045 }); // catalog says 0.0030
// after
kernel.priced(evidence, { reportedCostUsd: priced.usd }); // or omit reportedCostUsd Defensive patterns
Strategy: try-catch
Validate before calling
if (reportedCostUsd !== undefined && (!Number.isFinite(reportedCostUsd) || reportedCostUsd < 0)) throw new Error("bad reportedCostUsd"); Type guard
const isValidReportedCost = (c) => typeof c === "number" && Number.isFinite(c) && c >= 0;
Try / catch
try { return kernel.priced(evidence, { reportedCostUsd }); } catch (err) { if (err.message === "cave_provider_cost_mismatch") { return kernel.priced(evidence); } throw err; } Prevention
- Only pass reportedCostUsd when it should exactly equal catalog pricing
- Refresh the cost catalog when provider prices change
- Beware float formatting: compare with a tolerance, never string round-trips
- Don't report costs for unpriced models
When it happens
Trigger: Passing reportedCostUsd from the provider API response that disagrees with the kernel's catalog price (rounding, tiered pricing, catalog drift); passing reportedCostUsd for an unpriced model; passing NaN/undefined-coerced values.
Common situations: Provider changed its prices but the local cost catalog is stale; provider cost includes features (e.g. cached-token discounts) priced differently by the catalog; reporting cost for a model with no catalog entry.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- cave_provider_usage_unpriced
- cave_budget_denomination_unavailable
- cave_provider_model_identity_mismatch
- cave_subagent_unpriced_budget
- : pricing.batch_discount_fraction must be <= 1
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/0194fb05ae56cc61.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/execution-kernel.ts:168
throw new Error("cave_provider_usage_incomplete");
}
const priced = catalogCost({
provider: evidence.provider,
model: evidence.model,
inputTokens: evidence.inputTokens,
outputTokens: evidence.outputTokens,
cacheReadTokens: evidence.cacheReadTokens,
cacheWriteTokens: evidence.cacheWriteTokens,
reasoningTokens: evidence.reasoningTokens,
});
if (!priced.priced && options.requirePriced === true) {
throw new Error("cave_provider_usage_unpriced");
}
if (options.reportedCostUsd !== undefined &&
(!priced.priced || !Number.isFinite(options.reportedCostUsd) ||
options.reportedCostUsd < 0 ||
Math.abs(options.reportedCostUsd - priced.usd) > 1e-12)) {
throw new Error("cave_provider_cost_mismatch");
}
return Object.freeze({
...evidence,
priced: priced.priced,
catalogCostUsd: priced.priced ? priced.usd : 0,
});
}
View on GitHub (pinned to 3ee70a1026)