route-switch

Capturing traces to DuckDB

How route-switch logs every call to a per-prompt SQLite dataset and a DuckDB analytics store, and how to read per-prompt cost, latency, and success rate.

Difficulty: intermediateTime: 9 min

route-switch treats analytics as a first-class part of the gateway, not a bolt-on. Every served call is written to two places at once.

Two stores, two jobs

  • Per-prompt SQLite dataset — one file per template under dataset.base_path. Each row records the rendered input, the output, the variables, the model, the provider, whether the call succeeded, and its cost. This is the raw material the optimizer replays. Datasets are trimmed to dataset.max_records.
  • DuckDB analytics store — request/response summaries, latency, error rates, and cost rollups, aggregated per prompt and globally.

Reading the numbers

The gateway surfaces aggregates through operational endpoints:

# per-prompt stats
curl http://localhost:8080/v1/prompts/support-reply/stats

# global analytics rollup
curl http://localhost:8080/v1/system/analytics

Because the store is DuckDB, you can also point any DuckDB client at the file and run SQL directly — useful for ad-hoc cost-per-prompt or success-rate-over-time queries.

Why this matters

Without per-prompt economics, routing is guesswork. With it, performance_based routing has real signal to act on, and you can see prompt drift before it becomes support tickets — which is exactly what prompt optimization from traces needs.

route-switch publishes no synthetic benchmark numbers. The figures you see are the ones your own traffic produced.

Frequently asked questions

Is the SQLite dataset a response cache?

No. It captures every call for optimization and analytics, but identical requests are not deduplicated or served from cache. route-switch has no response cache.

What columns does the per-prompt dataset record?

Rendered input, output, variables, model, provider, success, and cost, with a created_at timestamp. Datasets are trimmed to dataset.max_records.

Related

Run route-switch today

Open source, MIT licensed. One binary, one endpoint, your providers.