What You’ll Build
A tiny Node.js script that sends a few different questions to Routor and prints which model answered each one, what tier it was classified into, and how much cheaper it was than always using a flagship model.Prerequisites
- Node.js 18 or later (
node --versionto check) - A terminal
Step 1 - Get an API Key
- Sign up at routor.io - free, no credit card. New accounts start with a small welcome credit, so you can run this guide without topping up first.
- In the dashboard, go to API Keys and create one. It starts with
sk-routor-. - Copy it now - it’s only shown once.
Step 2 - Set Up the Project
openai package is all you need - no Routor-specific SDK to install.
Set your key as an environment variable instead of hardcoding it:
Step 3 - Write the Script
Createindex.js:
package.json needs "type": "module" for top-level await and import - npm init -y doesn’t add this by default, so add it yourself:
Step 4 - Run It
model: "auto" is the only routing-related line.
Step 5 - See the Full Decision
Every response’sresponse.routor object carries the full decision, not just the model name:
tier and category tell you how the prompt was classified, confidence is how sure the classifier was, savingsPct is versus the baseline comparison model, and qualityPct is the routed model’s benchmark score relative to that same baseline (negative means somewhat below it, which is expected and fine for genuinely simple requests). You can also check any prompt’s routing decision before spending a real request, using the Debug Endpoint - useful while you’re still deciding whether the defaults fit your use case.
Your dashboard’s Logs page shows the same information for every request you’ve made, in one place.
Where to Go Next
- How routing decisions are made - the mechanics behind
model: "auto" - Controlling the tier - pin, floor, or cap which tier a request can use
- Set up a routing profile - save a reusable policy (cost cap, required capabilities, tier range) as its own API key
- Add image understanding - the same
client.chat.completions.createcall, with an image attached