orq.aiAdvent of RoutingDocs

Door 12 · still sealed

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

-days--hours--min--sec

Rudolph is still polishing this one. Back to the calendar

Door 12 · Dec 12 Traces from the terminal (orq CLI)

Following the sleigh's tracks

Find one bad reply among hundreds without leaving your terminal: which model answered, what it cost, and the full conversation, as text or JSON.

Fresh snow over the loading yard, criss-crossed with tonight's sleigh tracks. A child asked for a train set and got a cheerful reply about ponies, and nobody knows which call sent it.

  1. Sprocket

    We answered a train-set letter with ponies! I'll add a print() to every function and redeploy.

  2. Ledger

    Hundreds of replies tonight and one of them is a pony. I want the call, the model and the tokens, counted like candy canes. Not print() lines.

  3. Sprocket

    Then I'll scroll the dashboard. It's only hundreds. I'll be done by Boxing Day!

  4. Tinsel

    Leave the code alone. Every routed call already left tracks: orq traces search finds tonight's, orq traces conv reads the pony one.

clientYour appPOST /v3/routerorq.aiAI Routerrules · guardrails · modeltraceTrace and spansmodel · tokens · cost · mscliorq tracessearch · conv · get-batchreaderYou or your agent-o jsonrequestrecordsreadsprints
  1. clientYour appPOST /v3/router
  2. orq.aiAI Routerrules · guardrails · model
  3. traceTrace and spansmodel · tokens · cost · ms
  4. cliorq tracessearch · conv · get-batch
  5. readerYou or your agent-o json
Every call through the router leaves a trace with model, tokens, cost and time, and `orq traces` reads those tracks back to you or your coding agent.

How it works

Tinsel’s fix needs no redeploy: the router has been keeping notes on every call all night.

  1. Trace. Every call through the AI Router is recorded as a trace. It holds a timeline of steps, from routing decisions to the model call, with model, provider, tokens, cost, status and duration.
  2. Search. orq traces search lists the traces in a time window. It calls POST /v3/traces/search, and every field of that body is a flag: --from, --to, --query, --filters, --limit.
  3. Read. orq traces conversation (alias conv) turns one trace into a list of messages, tool calls and reasoning. Chat Completions, Responses and OpenTelemetry GenAI payloads all come out in the same shape. (The CLI docs page shows it as orq traces thread, which runs the same command.)
  4. Script. -o json prints the API response as JSON on stdout. That is the stable contract, so a shell script, a CI job or a coding agent can read the same traces you do.

Run it

Install the CLI and sign in:

curl -fsSL https://cli.orq.ai/install.sh | sh
orq auth login

Make a trace by sending one request through the router:

curl https://my.orq.ai/v3/router/chat/completions \
  -H "Authorization: Bearer $ORQ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-6-luna",
    "messages": [
      {"role": "user", "content": "Name three reindeer."}
    ]
  }'

The trace lands in the project of the key you sent it with; search that project, or pass --project.

Find it, then read it:

orq traces search --from 1h --to now --limit 20 -o json \
  -j 'data[].{id: trace_id, models: models, status: status}'

orq traces conv <trace_id> --spans
orq traces conv <trace_id> --slice -4: -x reasoning

-j takes a JMESPath expression, so you print only the fields you need. Each search result carries trace_id, status, models, providers, usage, cost and duration_ms.

Narrow it down

You want Add this
Only failed calls --filters with status in ["error"]
The fields you can filter on orq traces list-fields
The last four messages orq traces conv <id> --slice -4:
Messages that mention a word orq traces conv <id> --match pony
The turns without the thinking orq traces conv <id> -x reasoning

A filter entry is {"field", "op", "values"}. Operators include eq, in, gt, between, contains and exists. Values are always strings, even for numbers and timestamps.

To fetch many traces in one process, pipe the ids in:

orq traces search --from 1h --to now -o json \
  -j 'data[].trace_id' --raw | orq traces get-batch -o json

The output is an array in input order, one entry per id, with an error field on any id that could not be read.

Gotchas

Time. Without --from and --to, search covers the last 7 days. Relative values count back from now. Bare dates are read as UTC.

Which workspace. An exported ORQ_API_KEY wins over your browser login. If search answers 401 or shows another project’s traces, unset ORQ_API_KEY and try again. The CLI prints Using ORQ_API_KEY from environment on stderr when this happens, and orq doctor shows which credential is in use. Traces belong to a project; --project picks a different one.

Long messages. The xml and markdown renders of conv cut each block at 4,000 characters by default; -o json, yaml and toon stay uncut unless you pass a cap. Pass --max-chars 0 for everything. conv also refuses -o table: use the default XML, markdown, json, yaml or toon.

Nice list

  • Set the window with --from and --to. Durations like 30m, 24h or 7d count back from now, and bare dates are read as UTC.
  • Run orq traces conv <trace_id> --spans first. It shows which span the command reads and marks it with *.
  • Pipe ids into orq traces get-batch instead of looping over orq traces get. A failing id does not abort the batch.
  • Use orq traces conv <trace_id> -o markdown to paste a conversation into a ticket or chat.

Naughty list

  • Leaving an old ORQ_API_KEY exported. It beats your browser login and brings the key's own project restrictions, so you search the wrong project or get a 401.
  • Trusting a long tool result in the default conv render to be whole. The xml and markdown renders cut each block at 4,000 characters; pass --max-chars 0 to see everything.
  • Sprinkling print() through every function and redeploying to find one bad reply. The router already traced that call, with model, tokens and cost.

Elf's challenge

The pony was a bad answer, not an error. Ledger still wants every call that errored in the last 24 hours. Write the one orq traces search that lists them, and say how many filters it can hold.

Stuck? Ask Tinsel for a hint

Run orq traces search --from 24h --to now --filters '[{"field":"status","op":"in","values":["error"]}]'. One search holds up to 20 filters, combined with and unless you pass --filter-operator or.

Christmas crackerWhy did the night-shift elves' script choke on the workshop carols?Pull it for the punchline

Piped, the CLI sings in TOON. Scripts want -o json.