orq.aiAdvent of Routing

Door 18 · still sealed

Hands off the wax, elf. This door opens on Dec 18.

-days--hours--min--sec

Rudolph is still polishing this one. Back to the calendar

Door 18 · Dec 18 Identities & app tracking

Who spent what

Four hundred elves, one API key, one bill. Tag each call with its app and its elf, and the spend splits per identity.

Six days to Christmas Eve. The AI bill lands on Ledger's desk in the counting house, twice as long as last week's and not one elf's name on it.

  1. Ledger

    The bill doubled and every line says 'workshop'. Four hundred elves, one key. The counting house is having an identity crisis.

  2. Mrs. Claus

    Before you go elf-hunting, dear: whatever you write on those calls stays on the traces. Who will see it?

  3. Ledger

    Then I'll mint four hundred API keys and rotate them by hand. That's four hundred keys, every December, forever.

  4. Tinsel

    Keep the one key: app in name, elf in identity. An elf id, not a home address.

  5. Ledger

    First split's in. Elf 17 has been asking the model to rhyme every single gift tag. Of course it's Elf 17.

elfElf 17identity.id: elf-17elfElf 42identity.id: elf-42orq.aiTagged callname: toy-shop · identityprovideranthropic/claude-haiku-5-5activitySpend per identity12callcost
  1. elfElf 17identity.id: elf-17
    elfElf 42identity.id: elf-42
  2. orq.aiTagged callname: toy-shop · identity
  3. provideranthropic/claude-haiku-5-5
    activitySpend per identity
Elf 17 and Elf 42 share one app and one key, but each call carries the elf's own id, so the counting house can split the bill per elf.

How it works

Tinsel’s fix is two labels on the request you already send. Each one answers a different question.

  1. name is the app. It answers “which app, service or feature made this call?” It shows on every trace and filters the Traces view and the Monitors dashboards by application.
  2. identity is the person. It answers “which end user, team or client is this call for?” Only identity.id is required (up to 255 characters). display_name, email, metadata and tags (up to 10) are optional.
  3. The router picks one identity. It uses the first it finds: the identity object in the body (tags the call and saves the record’s details), then the X-ORQ-IDENTITY-ID header (tags only), then the owner of a user-owned API key (tags only).
  4. Cost is added up per identity. Each span’s cost is computed on the server. The Identities list shows requests, cost, tokens and error rate per identity, and Activity > Spend can split spend by Identities (with a project selected, Spend shows only that project).

You do not have to create an identity first. The router creates the record the first time it sees a new id.

Try it with curl

Two elves, one app:

for elf in elf-17 elf-42; do
  curl -sS -o /dev/null -w "$elf %{http_code}\n" https://my.orq.ai/v3/router/responses \
    -H "Authorization: Bearer $ORQ_API_KEY" \
    -H "Content-Type: application/json" \
    -d "{
      \"model\": \"anthropic/claude-haiku-5-5\",
      \"input\": \"Write a two-line label for a wooden sleigh\",
      \"name\": \"toy-shop\",
      \"identity\": {\"id\": \"$elf\", \"tags\": [\"wrapping\"]}
    }"
done

Or from the OpenAI SDK

The fields are not part of the OpenAI request types, so pass them in extra_body:

import os

from openai import OpenAI

client = OpenAI(
    api_key=os.environ["ORQ_API_KEY"],
    base_url="https://my.orq.ai/v3/router",
)

response = client.responses.create(
    model="openai/gpt-6-luna",
    input="Which reindeer pulls best in fog?",
    extra_body={
        "name": "toy-shop",
        "identity": {"id": "elf-17", "display_name": "Elf 17"},
    },
)
print(response.output_text)

Read the spend back

orq identities list --include-metrics -o json

curl "https://my.orq.ai/v2/identities?include_metrics=true" \
  -H "Authorization: Bearer $ORQ_API_KEY"

With include_metrics=true, each identity carries metrics for the last 30 days: total_cost in USD, total_tokens, total_requests and error_rate.

Which label for what

Question Field
Which app made this call? name
Which user, team or client is it for? identity
Which conversation does it belong to? thread
What business context applies? metadata

The docs’ rule: if it describes the app, use name. If it describes the user, use identity. If it is business context, use metadata. Historical traces keep their original name, so pick names you can live with.

Chat Completions and headers

On /v3/router/chat/completions, identity and thread go under the orq object (orq.identity). name stays at the top level.

Clients that cannot change the body, like coding agents or a proxy that passes the payload through untouched, can send X-ORQ-IDENTITY-ID instead. It tags the call, but it never fills in a display name, email or metadata. On endpoints with a JSON body, the metadata headers (X-ORQ-METADATA, X-ORQ-METADATA-<key>) also reach routing rules, guardrail rules and budgets. A caller who can set them can change which rules match, so only let trusted callers set them.

Nice list

  • A small, fixed set of app names. The docs suggest around 50 per workspace: letters, digits and hyphens, under 50 characters.
  • Generating identity ids in one place, in one format. Mixed formats for the same person are how duplicate identities appear.
  • Sending the identity object in the body when you want display_name, email or metadata saved on the identity record.
  • Checking cost per elf with orq identities list --include-metrics.

Naughty list

  • Naming the app toy-shop-elf-17. You end up with an app per elf instead of one app with four hundred identities. Per-user values belong in identity.
  • Sending identity at the top level on Chat Completions. There it goes under orq.identity, next to orq.thread. name stays at the top level.
  • Putting an elf's email or home address in name, metadata or thread.tags. They persist on the traces.
  • Passing identity_id to the Orq SDK constructor. It was removed in SDK v4.10.0: pass identity on each request instead.

Elf's challenge

Shout your name at the door without filling in the form: send one call with only the header X-ORQ-IDENTITY-ID: elf-99, then GET https://my.orq.ai/v2/identities/elf-99 with your API key. Did Elf 99 get a display name?

Stuck? Ask Tinsel for a hint

No. A header only tags the request. When the identity does not exist yet, it is created from the trace with no display name, email or metadata. The body identity object fills those in.

Christmas crackerWhy is Elf 99's mitten still in lost property?Pull it for the punchline

Only his id was sewn in. Headers don't stitch on the name.