JuliusBrussee/caveman · error

usage export has no recognizable token columns

Error message

usage export has no recognizable token columns (saw: %s)

What it means

After requiring a model column, mapReconcileHeader requires at least one recognized token column (input, output, cache_read, cache_write or their aliases). With zero token columns reconciliation has nothing to sum, so it fails closed and echoes the original header.

Solutions

  1. Include at least one token column (input/output/cache_read/cache_write or a recognized alias) in the export
  2. Re-export the full usage report rather than a cost summary
  3. Add the new column alias to the token matcher in mapReconcileHeader if the provider renamed it

Example fix

// before
model,total_cost
gpt-4o,1.23
// after
model,input_tokens,output_tokens,total_cost
gpt-4o,1000,200,1.23
Defensive patterns

Strategy: validation

Validate before calling

header, _ := firstCsvLine(path); need := []string{"input","output","cache_read","cache_write"}; if !anyAliasPresent(header, need) { return fmt.Errorf("usage export missing token columns") }

Try / catch

if _, err := store.BuildLearnReconcile(ctx, opts); err != nil { if strings.Contains(err.Error(), "no recognizable token columns") { log.Error("export lacks input/output token columns") } }

Prevention

When it happens

Trigger: parseUsageExport on a CSV whose header has a model column but none of the token-count columns (e.g. only cost or request-count columns).

Common situations: Exporting a spend-only report instead of a token usage report; provider renaming token columns beyond the alias set; trimming the CSV to remove 'unused' token columns.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at proxy/internal/store/learn_reconcile.go:112

			for _, alias := range aliases {
				if normalized == normalizeHeader(alias) {
					found[field] = index
					break
				}
			}
		}
	}
	if _, ok := found["model"]; !ok {
		return nil, fmt.Errorf("usage export has no recognizable model column (saw: %s)", strings.Join(header, ", "))
	}
	tokenFields := 0
	for _, field := range []string{"input", "output", "cache_read", "cache_write"} {
		if _, ok := found[field]; ok {
			tokenFields++
		}
	}
	if tokenFields == 0 {
		return nil, fmt.Errorf("usage export has no recognizable token columns (saw: %s)", strings.Join(header, ", "))
	}
	return found, nil
}

func reconcileCell(record []string, columns map[string]int, field string) int64 {
	index, ok := columns[field]
	if !ok || index >= len(record) {
		return 0
	}
	raw := strings.TrimSpace(strings.ReplaceAll(record[index], ",", ""))
	if raw == "" {
		return 0
	}
	value, err := strconv.ParseFloat(raw, 64)
	if err != nil || value < 0 {
		return 0
	}
	return int64(value)

View on GitHub (pinned to 3ee70a1026)