Skip to content

Tags and usage breakdown

Tag requests with your end user and your own key-value metadata, then break spending down per customer, feature or preset in the dashboard and through the API.

Markdown
On this page

When several products, features or customers share one Lykia company, you want to know who spends what. Projects already split usage per product. Tags go further: you label each request with your end user (or tenant) and with your own key-value pairs, and Lykia adds them up for you.

Tag a request

Send user and metadata in the request body:

curl https://api.getlykia.com/v1/chat/completions \
  -H "Authorization: Bearer $LYKIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "@text",
    "messages": [
      { "role": "user", "content": "Summarize this support ticket in one sentence: the invoice PDF is missing." }
    ],
    "user": "tenant-42",
    "metadata": { "feature": "ticket-summary", "plan": "pro" }
  }'
userstring

Your end user or tenant id, at most 128 characters. Send a pseudonymous id rather than an email address or a name.

metadataobject

Up to 16 key-value pairs. Keys are 1 to 64 characters, must not contain . and must not start with $; values are strings of at most 512 characters. Good keys name a dimension you want to compare: feature, plan, region, customer.

Tags are stored with the request record and are never sent to the provider, whichever route the request takes. They are stored even when prompt logging is off for the project, since they are measurements, not content. A request whose tags are over the limits gets 400 with the code invalid_tags; nothing is trimmed silently. The JavaScript SDK's sanitizeTags() fits any input to the limits before you send it.

Tags work the same way in POST /embeddings. When you call a preset, the preset name is recorded too, so you can compare @text with @fast without tagging anything.

Break usage down in the dashboard

On the Activity page, choose what to break the period down by: model, API key, user, preset, or a metadata key you type in (for example feature). Each value gets its requests, tokens, spend and share, and the untagged row shows the share of requests that carried no value for that dimension, so you can see how much of your traffic is covered.

You can also filter the whole page, and the request log, by one tag at a time: a user, a preset, or one metadata.key=value pair. The filters stay in the page address, so you can bookmark or share a filtered view. The breakdown is kept separately from the request records, so it covers periods longer than their retention.

Read records through the API

GET /generations lists the project's request records, newest first, filtered by user, preset, model, metadata.<key> and time range. Each record has the request's cost and cost_details, so you can total spending per customer in your own billing:

curl "https://api.getlykia.com/v1/generations?limit=20&user=tenant-42&metadata.feature=ticket-summary" \
  -H "Authorization: Bearer $LYKIA_API_KEY"

A single record, with the same fields, comes from GET /generation.

Next steps