API

Usage ingest

Record LLM usage for the signed-in user. Events power the Consumption & Costs dashboard (models, pipelines, daily spend, tokens).

Endpoint

POST /api/usage/ingest
Content-Type: application/json
Cookie: (Supabase session — same site)

Body

{
  "events": [
    {
      "provider": "openai",
      "model": "gpt-4o",
      "pipeline": "document-ingestion",
      "tokens_input": 1200,
      "tokens_output": 400,
      "tokens_cached": 0,
      "cost_usd": 0.012,
      "latency_ms": 890,
      "error": false,
      "occurred_at": "2026-03-28T12:00:00.000Z"
    }
  ]
}

Fields

  • provider, model — required strings
  • pipeline — optional, default default
  • tokens_*, cost_usd — numbers (defaults 0)
  • latency_ms — optional integer
  • error — boolean, counts toward error rate
  • occurred_at — optional ISO 8601; defaults to now

Limits

Up to 500 events per request.

Response

{ "inserted": 1 }
From another origin, use a backend that forwards the user session or add a dedicated API key flow (not included in the template).