Docs

Platform

Router

The router lets your app send its AI calls through Token Meter by changing one setting: the base URL (the web address your OpenAI or Anthropic SDK sends requests to). Every call is then metered with exact tokens and cost. The router can also pick a cheaper model, answer from a cache and enforce budgets.

Related guides: Reduce LLM API costs, Anthropic API cost tracking, Gemini and Vertex AI cost tracking

The router speaks the OpenAI Chat Completions API at /v1/chat/completions, the OpenAI Responses API at /v1/responses (the one Codex uses) and the Anthropic Messages API at /v1/messages. A /v1/responses request gets everything a chat request gets, including auto and tools. Its address is https://router.timewastevc.com. The quickest start on Growth and above is model: "auto": the router picks a model for each request and runs it on Token Meter's own provider keys, with nothing else to set up. On Free, add your own provider key and name the model, or let a routing policy claim auto.

Who manages the router

Anyone with a workspace key can send requests. The settings behind the router (provider keys, models, routing policies, caches) live under Router in the sidebar, which Owners and Admins can open. See Gateway and routing.

Before you start

  • A Token Meter workspace.
  • A workspace key: a secret that starts with tl_live_ and tells the router which workspace a call belongs to. Owners, Admins and Team leads can create one under Governance › API keys. The steps are below.
  • The OpenAI SDK for Python (pip install openai) or Node.js (npm install openai), or the Anthropic SDK (pip install anthropic or npm install @anthropic-ai/sdk). You can also use curl in a terminal.
  • For model: "auto" on Growth and above, nothing else. On Free, auto is refused unless a routing policy claims it or the workspace pays from Token Meter credits: add your provider key under Router › Providers (Add provider key) and name a model such as "model": "gpt-4o-mini" instead. To call a model by name, an Owner or Admin first adds the model and your own key for its provider under Router › Providers; see Name a specific model.

Your first request

  1. In the dashboard, open Governance › API keys and click Create key.
  2. Type a Name (for example prod-api) and click Create key. A box titled Key created: copy it now shows the key.
  3. Copy the key. It starts with tl_live_ and is shown only once. If you lose it, create a new one.
  4. In a terminal, save the key as an environment variable so it stays out of your code:
Shell
# macOS or Linux
export TOKEN_METER_KEY="tl_live_..."

# Windows PowerShell
$env:TOKEN_METER_KEY="tl_live_..."
  1. In your code file, create the client with the router's address and your key, and send model: "auto":
TypeScript
import OpenAI from "openai";

const openai = new OpenAI({
  baseURL: "https://router.timewastevc.com/v1",
  apiKey: process.env.TOKEN_METER_KEY,
});

const completion = await openai.chat.completions.create({
  model: "auto",
  messages: [{ role: "user", content: "Say hello in five words." }],
});
console.log(completion.choices[0].message.content);

Or from a terminal:

Shell
curl https://router.timewastevc.com/v1/chat/completions \
  -H "Authorization: Bearer $TOKEN_METER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "auto", "messages": [{"role": "user", "content": "Say hello in five words."}]}'
  1. Run it. You should see a short reply. The call is metered, and an Admin can see it within seconds under Router › Overview (click Activity for the full Routing activity list).

The key goes in the SDK's API key setting. Over plain HTTP, send it as Authorization: Bearer tl_live_… or as an x-api-key header. To see which model auto picked, read the x-tokenmeter-model response header:

TypeScript
import OpenAI from "openai";

const openai = new OpenAI({
  baseURL: "https://router.timewastevc.com/v1",
  apiKey: process.env.TOKEN_METER_KEY,
});

const { data, response } = await openai.chat.completions
  .create({ model: "auto", messages: [{ role: "user", content: "Say hello in five words." }] })
  .withResponse();
console.log("Answered by:", response.headers.get("x-tokenmeter-model"));
console.log(data.choices[0].message.content);

What auto costs

On the Growth, Scale and Enterprise plans auto runs on Token Meter's provider keys, so you need no OpenAI, Anthropic or Google account. Each workspace can use up to US$25 a month of auto traffic on those keys. Past it the router answers 402 auto_monthly_limit_reached until the 1st of the next month (UTC). A named model on your own provider key still works. On the Free plan auto does not run on Token Meter's keys: an auto request gets 402 platform_keys_require_paid_plan unless a routing policy sends it to a model on your own provider key. A workspace that pays from Token Meter credits is the exception to both the allowance and the Free refusal; see Credits. Auto's goals (auto:cheap, auto:quality, auto:fast) and its allow and exclude lists are in Auto routing. Auto is on for every workspace, and there is no switch to turn it off. If Token Meter has turned it off for your workspace, auto requests get 400 auto_routing_disabled: name a model, or contact Token Meter.

Without changing code

The OpenAI and Anthropic SDKs read their address and key from environment variables. If your app creates its client without passing these, setting them in the app's environment is enough:

Shell
# OpenAI SDKs (Python and Node.js)
export OPENAI_BASE_URL="https://router.timewastevc.com/v1"
export OPENAI_API_KEY="$TOKEN_METER_KEY"

# Anthropic SDKs (Python and Node.js): no /v1 at the end
export ANTHROPIC_BASE_URL="https://router.timewastevc.com"
export ANTHROPIC_API_KEY="$TOKEN_METER_KEY"

Your code still decides the model. Set it to auto, or add the model you use as described in the next section.

Name a specific model

Send a model name such as gpt-4o-mini instead of auto and the router calls that model on your own provider key. Two things must be in place first. One is your own key for the model's provider; see Whose provider key is used, below. Without it the router answers 424 provider_not_configured. The other is a capability record: a short entry that tells the router the model's limits and features. Without one the router answers 400 model_capability_not_configured. An Owner or Admin adds it once per model:

  1. Open Router › Providers and expand Advanced.
  2. Click Add capability.
  3. In Provider model, pick the model, for example gpt-4o-mini. Only models Token Meter has a price for are listed.
  4. Fill in Max context tokens and Max output tokens from the provider's model page.
  5. Tick Tools, Structured output and Vision for each feature the model supports. The router refuses a request that needs a feature left unticked.
  6. Click Save capability. The model now appears under Model capabilities.
TypeScript
import OpenAI from "openai";

const openai = new OpenAI({
  baseURL: "https://router.timewastevc.com/v1",
  apiKey: process.env.TOKEN_METER_KEY,
});

const completion = await openai.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Say hello in five words." }],
});
console.log(completion.choices[0].message.content);

Whose provider key is used

There are two kinds of key. On paid plans model: "auto" runs on Token Meter's own provider keys, up to a monthly allowance of US$25. On the Free plan it does not (see What auto costs above). A model you call by name runs on your own key for that provider, and your provider bills you. A new workspace has no provider keys, so add one before you name a model:

  1. Open Router › Providers.
  2. Click Add provider key and pick the provider. If the provider is already in the list, click Rotate on its row instead.
  3. Paste your key from that provider's console into Inference API key.
  4. Click Store key (or Rotate key). New requests that name that provider's models use your key.

Auto keeps running on Token Meter's keys either way, and only auto traffic counts toward its monthly allowance.

Which provider serves a request

With no routing policy, the model name picks the provider:

  • A name containing claude goes to Anthropic.
  • A name containing gemini or gemma goes to Google Gemini.
  • Anything else goes to OpenAI.

Requests to /v1/messages always go to Anthropic. Send the bare model name. A prefix that matches the model's provider (openai/gpt-4o-mini, google/gemini-…) is dropped and the request goes ahead; a prefix that names another provider (anthropic/gpt-4o-mini) is refused with a message that says to drop it. A LiteLLM gateway is reached only through a routing policy. A policy (Router › Rules › Advanced › Policies, Add routing policy) can also move a request to a different model, which is how cheaper-model routing works.

Anthropic Messages API

Point the Anthropic SDK at the router's address with no /v1 at the end. The SDK adds /v1/messages itself.

TypeScript
import Anthropic from "@anthropic-ai/sdk";

// The router's address with no /v1: the SDK adds /v1/messages itself.
const anthropic = new Anthropic({
  baseURL: "https://router.timewastevc.com",
  apiKey: process.env.TOKEN_METER_KEY,
});

const message = await anthropic.messages.create({
  model: "auto", // or a Claude model with a capability record, such as "claude-haiku-4-5"
  max_tokens: 512,
  messages: [{ role: "user", content: "Say hello in five words." }],
});
for (const block of message.content) {
  if (block.type === "text") console.log(block.text);
}
Shell
curl https://router.timewastevc.com/v1/messages \
  -H "x-api-key: $TOKEN_METER_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"model": "auto", "max_tokens": 512, "messages": [{"role": "user", "content": "Say hello in five words."}]}'
  • Only Anthropic models answer on /v1/messages. With auto, the router picks among Claude models. Naming another provider's model there (say gpt-4o-mini), or a routing policy that targets another provider, fails with 400 native_anthropic_cross_provider_routing_not_enabled. Send those to /v1/chat/completions. Fallbacks and experiments that point at another provider are skipped.
  • The router accepts messages, system, max_tokens, temperature, top_p, top_k, tools, tool_choice, stop_sequences, metadata, stream and thinking, plus the router's own fields below. The cache_control markers inside messages are passed through.
  • /v1/messages requests are never answered from the router's caches, and are not captured or sampled for shadow model comparisons.

A Claude model called through /v1/chat/completions is translated to Anthropic's format, but only for plain text message content. Tools, tool_choice and response_format are refused with 400 claude_tools_require_native_messages_api before anything is sent: send those requests to /v1/messages in Anthropic's format. This refusal never counts against the model's health, and a policy fallback to a Claude model is skipped for such a request.

Attribution

Attribution tags say who and what a call was for, so costs can be split by customer, feature or team. Send them as top-level fields of the request body. The router records them and removes them before the request reaches the provider.

FieldMeaning
actionWhat the call does, e.g. "weekly-summary". Routing policies can match on it.
customer_refYour end customer or tenant, as an id from your own system. A value that looks like an email address is stored as a keyed pseudonym (email~3f9a…), never as sent.
featureThe product feature the call belongs to. Routing policies can match on it.
teamThe team that owns the call.
environmente.g. "prod" or "staging".
projectThe client project the call is for, e.g. "acme-redesign". A project's project tag rule matches it.
member_refThe person who made the call: the email they sign in to TokenMeter with, so the per-person views count the call. Stored in lowercase; a value that is not an email address is dropped without an error. Only this field names a person: user and metadata.user_id are not read, and an API key never stands for one. Not yet recorded for /v1/batches items or Prefer: respond-async requests.
trace_idOptional. Groups the calls of one task or conversation. Without it the router groups each conversation itself, under an id that starts with auto:: by your session id, else by the conversation's opening messages and the model's first reply, so turns 2 onward of one conversation share a trace and a conversation's first turn, or a one-off request, is a trace of its own. Send a session id to have the first turn in it too. The router's own calls for a request (task classifier, embeddings, guardrail and shadow checks) are recorded under the same trace.

team, environment and project are stored in lowercase and must be 1 to 64 characters: letters, digits, _, ., : or -, starting with a letter or digit. A value that breaks this rule is dropped without an error, so the call arrives untagged.

TypeScript
import OpenAI from "openai";

const openai = new OpenAI({
  baseURL: "https://router.timewastevc.com/v1",
  apiKey: process.env.TOKEN_METER_KEY,
});

// Built as a variable first, so TypeScript accepts fields the OpenAI types don't list.
const body = {
  model: "auto",
  messages: [{ role: "user" as const, content: "Summarize this week's tickets." }],
  action: "weekly-summary",
  customer_ref: "acme",
  feature: "reports",
  team: "support",
  environment: "prod",
  project: "acme-redesign",
};
const completion = await openai.chat.completions.create(body);
console.log(completion.choices[0].message.content);

Other fields the router reads

These are optional. The router reads them and never forwards them to the provider.

FieldEffect
modelsUp to 5 models to try, in order, if model fails. Each is a bare name or provider/model (e.g. anthropic/claude-haiku-4-5), and each needs its own capability record. A request makes at most 3 attempts in total. Not allowed with auto (400 models_not_supported_with_auto), which picks its own fallbacks.
providerAn object that limits or orders where the request is served. See the next table.
session_idYour own name for the conversation. Routing keeps one conversation on its model instead of switching between turns. Also accepted as the x-tokenmeter-session-id header. Without it the router uses the rollout key, then trace_id, then the start of the conversation. Recall does not read it: Recall's session id goes inside recall.
allowed_modelsAuto only. Up to 20 patterns; auto picks only a matching model. A pattern is a model name or provider/model, with * as a wildcard (anthropic/*, gpt-4o*). See Auto routing.
excluded_modelsAuto only. Up to 20 patterns; auto never picks a matching model. Both lists can only narrow the workspace's own lists.
max_cost_usdRefuse the request (402 estimated_cost_exceeds_max_cost_usd) when its worst-case cost is above this many US dollars.
run_idGroups calls into one run with a shared budget. Requires max_cost_usd. Up to 200 characters.
run_budget_usdThe run's total budget in US dollars. The first call of a run must send it; later values are ignored. Only with run_id. A request that does not fit in what is left gets 402 run_budget_exceeded.
task_typeA hint about the kind of task, for automatic model choice. How far it is trusted is the Caller task hints setting under Router › Rules › Advanced › Request handling.
task_difficultyHow hard the request is: easy, medium or hard, or a whole number from 1 to 10. Automatic model choice starts on the model for that difficulty instead of guessing. Also accepted as the x-tokenmeter-task-difficulty header. Trusted as far as task_type is; other values are ignored.
data_classificationData classes you declare (a string or a list). Added to the ones the router detects and checked against governance policies that block data classes.
sensitivetrue keeps the request out of the caches.
cache_control"no-store" keeps the request out of the caches.
recallAgent Recall settings, with the session id inside: {"enabled": true, "session_id": "…"}. A top-level session_id does not reach Recall. See the API reference.

The provider object

KeyEffect
allow_fallbacksfalse tries the first model only, with no fallback at all.
zdrtrue sends the request only to endpoints with zero data retention. Set up such an endpoint first: until then the request fails with 400 no_endpoint_meets_provider_requirements:zdr.
data_collection"deny" sends it only to endpoints whose terms rule out training on your data. Default "allow".
regionA region ("eu-west-1") or a geography ("eu", "us", "ap").
orderUp to 5 endpoints to try first. Name each by its host (direct, bedrock, azure_openai, vertex) or by the endpoint's name as shown in x-tokenmeter-endpoint, e.g. ["OpenAI main"]. Case does not matter.
onlyUp to 5 endpoints the request is limited to, named the same way. A provider name such as "openai" is not a host kind and matches only an endpoint named exactly that; otherwise the request fails with 400 no_endpoint_meets_provider_requirements:only.
sort"price", "latency" or "throughput": a fixed order instead of the router's own.
preferred_max_latencySeconds to the first byte. Slower endpoints move to the back of the order.
preferred_min_throughputOutput tokens per second. Slower endpoints move to the back of the order.

Any other key is refused with 400 unsupported_provider_option:<key>. If no endpoint meets the requirements, the request fails with no_endpoint_meets_provider_requirements.

TypeScript
import OpenAI from "openai";

const openai = new OpenAI({
  baseURL: "https://router.timewastevc.com/v1",
  apiKey: process.env.TOKEN_METER_KEY,
});

const body = {
  model: "gpt-4o-mini",
  messages: [{ role: "user" as const, content: "Say hello in five words." }],
  // Tried in order if gpt-4o-mini fails. Each needs its own capability record.
  models: ["claude-haiku-4-5"],
  // Try the endpoint with the lowest latency first.
  provider: { sort: "latency" },
  max_cost_usd: 0.05,
};
const completion = await openai.chat.completions.create(body);
console.log(completion.choices[0].message.content);

Fields the router accepts

A field the router does not know is refused with 400 unsupported_request_field:<name>, so nothing that can raise cost reaches the provider unchecked. On /v1/chat/completions the router accepts messages, max_tokens, max_completion_tokens, temperature, top_p, tools, tool_choice, response_format, stop, user, parallel_tool_calls, stream, stream_options, seed, presence_penalty, frequency_penalty, logit_bias, logprobs, top_logprobs, reasoning_effort and prompt_cache_key, plus the router's own fields on this page. n and service_tier are refused. Sending both max_tokens and max_completion_tokens is refused with 400 max_tokens_and_max_completion_tokens_both_set. The /v1/messages list is in Anthropic Messages API.

Streaming works on both endpoints. The router always asks the provider for usage on a stream, so whatever you send in stream_options is replaced.

Request headers

HeaderEffect
X-TokenMeter-Rollout-KeyA stable key (up to 200 characters) that keeps one user or conversation on the same side of a partial policy rollout or experiment. Without it the router uses customer_ref, then user, then trace_id.
X-TokenMeter-Trace-IdThe trace this request is recorded under (up to 200 characters), when the body has no trace_id. It names the trace only: unlike trace_id in the body, it does not name the conversation, the rollout bucket or anything sent to the provider. A longer value is ignored.
X-TokenMeter-Session-IdSame as the session_id body field.
X-TokenMeter-Idempotency-KeyA UUID. A retry with the same key never makes a second provider call; see below. Any other value is refused with 400 invalid_idempotency_key.
X-TokenMeter-Task-DifficultySame as the task_difficulty body field. The header wins if both are sent.
X-TokenMeter-Speed: fastPrefer the endpoint with the fastest first byte, unless the request sets provider.order or provider.sort. With auto it is the same as auto:fast: reasoning effort is never raised, and the model choice is unchanged.
X-TokenMeter-Metadata: enabledAdds a tokenmeter_metadata object to the response body (on a stream, a final tokenmeter_metadata event) describing how the request was routed. For auto, its task_type_from says where the task type came from: request (the router labelled this request), conversation (a short follow-up kept the conversation's task) or caller (the request's own task_type was used).
X-TokenMeter-Max-Completion-Delay-MsHow long you could have waited for this answer, from 1000 to 86400000 milliseconds. It changes nothing about this request; it is recorded so Token Meter can point out work that could run at batch prices.
X-TokenMeter-Prompt-Experiment-IdWith -Variant-Id, -Revision and -Cohort-Key: ties a request to a prompt experiment. See Experiments.
Prefer: respond-asyncQueue the request through the provider's batch API at batch prices instead of answering now. Needs Run non-urgent requests as cheaper batch jobs (results within 24 hours) switched on in Router defaults (the Defaults link on Router › Rules).
Cache-Control: no-storeKeep this request out of the caches.

Reusing an idempotency key:

  • Same request, the first one finished, and Answer retries from the saved response (24 hours) switched on (Router › Caching › Advanced): the stored response comes back with x-tokenmeter-idempotent-replay: true and no second charge.
  • Same key, different request: 422 idempotency_key_reused_with_different_request.
  • First request still running: 409 idempotency_request_in_progress with Retry-After: 2.
  • Otherwise: 409 idempotency_key_already_used.

Responses

The body is the provider's normal answer. These response headers say what the router did:

HeaderWhenMeaning
x-tokenmeter-routing-decisionEvery routed responseThe decision id. Look it up with the route below.
x-tokenmeter-trace-idRouted responses with a traceThe trace the request is recorded under: the trace_id you sent (in the body, else the X-TokenMeter-Trace-Id header), else the router's auto: id for the conversation. Send outcomes against it.
x-tokenmeter-modelRequests for autoThe model that answered.
x-tokenmeter-routeRequests for autoauto:balanced, auto:cost or auto:quality (the goal used), or policy when a routing policy took the request. auto:fast is the default goal plus a speed hint, so it reads as that goal; see x-tokenmeter-speed.
x-tokenmeter-route-reasonRequests for autoWhy this model: assignment, ladder (a stronger model for a harder request), pinned_conversation, struggling, constraint_fallback, strongest, failover, policy_override or evaluation_canary.
x-tokenmeter-task-typeRequests for autoThe task type the router assigned.
x-tokenmeter-effortRequests for autoThe reasoning effort the router asked the model for, when it set one.
x-tokenmeter-speedRequests for auto that asked for speedfast: the request sent auto:fast or X-TokenMeter-Speed: fast, so reasoning effort was not raised and the fastest endpoint was tried first.
x-tokenmeter-quality-verifiedRequests for autofalse when the model was picked by task tier alone (instant mode, or a reasoning request on Sonnet), without judged quality checks behind it.
x-tokenmeter-escalationReasoning requests for auto that Opus answered after Sonnet failedWhy: the Sonnet call's outcome (such as provider_error, refused_answer or empty_answer), or session_struggling.
x-tokenmeter-endpointEvery answer a provider served (not cache hits)The name of the endpoint that answered, e.g. OpenAI main.
x-tokenmeter-attemptsMore than one attemptHow many attempts it took.
x-tokenmeter-cache-markersClaude answers to OpenAI-format requests, with Prompt caching on Claude onHow many prompt cache markers the router added (1 or 2).
x-tokenmeter-cacheWhen a cache is onhit (exact cache), semantic-hit, miss (the request could be cached but no stored answer matched), or ineligible:<reason>. See Cached answers.
x-tokenmeter-cache-similaritySemantic hitsHow close the cached question was, e.g. 0.991.
x-tokenmeter-guardrailAn input guardrail flagged older textredacted=<n>: that many earlier messages or tool results were replaced with a notice. The request went ahead.
x-tokenmeter-recall-archivedRequests that send recallHow many tool results Recall archived.
x-tokenmeter-idempotent-replayA replayed answertrue: this is the stored answer to an earlier request with the same idempotency key.
x-tokenmeter-route-skippedClaude Code requestsA policy tried to move a Claude Code request to a non-Claude model; the router kept the model Claude Code asked for.
x-tokenmeter-count/v1/messages/count_tokensexact (counted by Anthropic) or estimate.

GET /v1/routing-decisions/<decision id> (with the same key) returns that decision's status, selected_provider, selected_model, estimated_max_cost_usd, created_at and completed_at. A streamed response can finish just before its decision is marked completed, so poll again briefly if it still reads reserved.

A request with Prefer: respond-async gets 202 with the batch id, poll_url and items_url. Read progress at GET /v1/batches/<id> and the answers at GET /v1/batches/<id>/items. It is refused (400 request_not_eligible_for_batch_arbitrage) when it streams, sends tools or images, uses run_id, run_budget_usd or max_cost_usd, or is served by a provider other than OpenAI or Anthropic.

Cached answers

An Admin can switch on two caches under Router › Caching: Reuse identical answers (15 minutes) (the same request again) and Reuse answers to near-identical questions (a request that means the same thing). A cached answer costs nothing at the provider. The caches only answer requests that:

  • go to /v1/chat/completions (never /v1/messages),
  • do not stream,
  • set temperature to 0, or set no temperature when Requests that set no temperature (under Advanced on Router › Caching) is switched on,
  • send no tools, tool_choice, response_format or images,
  • and are not marked private: no sensitive: true, no cache_control: "no-store" or Cache-Control: no-store header, and no action containing a word such as auth, credential, secret, payment, health, medical, legal, hr, personnel, security or pii.

When a cache is on and a request does not qualify, the response says why in x-tokenmeter-cache: ineligible:<reason>:

ReasonWhat to change
anthropic_messages_endpointNothing: /v1/messages is never cached.
streamingSend stream: false.
temperature_not_zeroSend temperature: 0.
temperature_not_setSend temperature: 0, or switch on Requests that set no temperature.
toolsThe request sends tools.
tool_choiceThe request sends tool_choice.
response_formatThe request sends response_format.
imagesThe request includes an image.
sensitivesensitive: true, or a private-sounding action.
no_storeA Cache-Control: no-store header or cache_control: "no-store".

Monthly request limit

Each plan includes a number of routed requests a calendar month (UTC). Every request to /v1/chat/completions, /v1/messages and /v1/responses counts once, and so does each item of a batch sent to /v1/batches; the router's own calls (task classification, guardrail checks, sampled checks) do not. A batch that would go past the limit is refused whole.

PlanRouted requests a month
Free100,000
Growth2,500,000
Scale10,000,000
Enterprise40,000,000

At the limit the router answers 429 monthly_request_limit_reached until the 1st of the next month (UTC), before any provider is called. Batches are checked against an exact count. Single requests are checked against a count each router instance keeps up to date and re-reads every 30 seconds, so requests sent as the limit is reached can go a few past it.

Credits

When a workspace runs on Token Meter credits, every routed call is paid from its prepaid balance. $1 of credit pays for $1 of usage at the provider's list price. Before the provider is called, the router holds the request's worst case (its input, plus its full output cap, at list price) against the balance. When the answer arrives it charges what the call really cost and returns the rest. Buy credit, see the balance and the history under Settings › Credits (/billing/credits). A workspace not yet switched to credits sees its balance and the Credits page, but calls are not charged or refused.

On credits, every call except Claude Code traffic (unless auto picks its model) and async batches runs on Token Meter's provider keys, so you need no provider key of your own for it. A named model must be one Token Meter offers (otherwise 400 model_capability_not_configured). auto works on every plan with no monthly allowance: the balance is the limit.

When the worst case does not fit, the request is refused before any provider is called and nothing is charged:

JSON
{
  "error": {
    "message": "Not enough Token Meter credits for this request. balance_usd is what is left, required_usd what this request may cost at most. Add credits at top_up_url.",
    "type": "insufficient_quota",
    "code": "insufficient_credits"
  },
  "error_code": "insufficient_credits",
  "message": "Not enough Token Meter credits for this request. balance_usd is what is left, required_usd what this request may cost at most. Add credits at top_up_url.",
  "type": "error",
  "balance_usd": 0.42,
  "required_usd": 1.1,
  "top_up_url": "https://<your Token Meter address>/billing/credits"
}
StatusCodeWhenWhat to do
402insufficient_creditsThe worst case is more than the balance.Add credit at top_up_url, or send a lower max_tokens so the worst case fits.
402credits_negativeThe balance is below zero, after a call cost more than its estimate or a payment was charged back.Add credit at top_up_url.
402credits_frozenA payment on the workspace is disputed, so its credit is on hold. Carries frozen: true.Contact Token Meter support. Adding credit does not lift the hold.
503credits_unavailableThe router could not read the workspace's credit settings, or could not read or write its balance, so it refused rather than spend unchecked. Comes with Retry-After: 30.Retry after 30 seconds. Nothing was charged.

The three 402 codes carry balance_usd (what is left), required_usd (the worst case of this request) and top_up_url (where to add credit). Every call holds its own worst case, so many large calls at once can be refused while the balance would cover what they actually cost. Lower max_tokens to hold less.

Errors

A router error is a JSON body that an unmodified OpenAI or Anthropic SDK can read, with the code repeated at the top level:

JSON
{
  "error": {
    "message": "anthropic/claude-haiku-4-5 is not one of this workspace's models, so it cannot be called by name on your own provider key. On a paid plan, auto routing can use it on TokenMeter's keys: send model \"auto\". To call it by name, add it under Router > Providers > Advanced > Model capabilities.",
    "type": "invalid_request_error",
    "code": "model_capability_not_configured"
  },
  "error_code": "model_capability_not_configured",
  "message": "anthropic/claude-haiku-4-5 is not one of this workspace's models, so it cannot be called by name on your own provider key. On a paid plan, auto routing can use it on TokenMeter's keys: send model \"auto\". To call it by name, add it under Router > Providers > Advanced > Model capabilities.",
  "type": "error",
  "provider": "anthropic",
  "model": "claude-haiku-4-5"
}
  • Match on error_code (or error.code): the codes in the table below. message and error.message are the same sentence, written for a person. Do not match on them.
  • In an OpenAI SDK, e.message is the sentence and e.code is the code. In an Anthropic SDK, e.message is the sentence too.
  • Some errors add fields: provider and model on a capability error, violations on a governance refusal, scope, limit and retry_after_seconds on a rate limit.
  • On /v1/messages and /v1/messages/count_tokens, error.type uses Anthropic's names (overloaded_error, billing_error, …). error_code is the same.
  • An error from the provider for a model you named is passed through with the provider's status and body.
  • When the router chose the model (auto, or a policy or tier that picked it), a provider refusal of an unsupported parameter, or a provider saying the model is unavailable, moves the request to the next model instead. The decision shows on Routing activity (Router › Overview › Activity) as Backup model used, and an auto answer carries x-tokenmeter-route-reason: failover.

Older code that reads body.error

Before 14 November 2026, error was the code as a plain string. Code that compares body.error === "<code>" should read body.error_code instead.
StatusCodeMeaning
400model_requiredNo model in the body.
400invalid_json, invalid_requestThe body is not a JSON object.
400unsupported_request_field:<name>A field the router does not accept; see Other fields.
400model_capability_not_configuredThe model has no capability record. Add one, or, on a paid plan, send auto.
400model_does_not_support_tools, _structured_output, _visionThe model's capability record has that feature unticked.
400max_tokens_exceeds_model_capability, request_exceeds_model_context_capabilityThe request is larger than the model's record allows.
400max_tokens_and_max_completion_tokens_both_setSend one of the two.
400claude_tools_require_native_messages_apiTools, tool_choice or response_format to a Claude model on /v1/chat/completions. Use /v1/messages.
400anthropic_requires_string_message_contentA Claude model on /v1/chat/completions needs plain text message content.
400native_anthropic_cross_provider_routing_not_enabledA non-Anthropic model on /v1/messages.
400prompt_rejectedAn input guardrail flagged the newest user message. Flagged earlier messages or tool results are replaced instead (see x-tokenmeter-guardrail).
400response_rejectedAn output guardrail withheld the answer. Carries billed: false.
400model_blocked_by_governance_policy, request_blocked_by_governance_policyA governance policy refused the request. violations lists why.
400tiered_routing_not_configuredAn Automatic tiering policy has no model for this task type and nothing to fall back to. A policy made with the Add routing policy form has Tasks with no tier assignment set to Use the requested model, so it does not refuse; one created by approving a tiered-routing recommendation, or saved before that setting existed, refuses. A policy can't be edited: retire it and add a new one, or pin a model for the task. For auto, that is the model set in Savings measured against in Router defaults (the Defaults link on Router › Rules), and the request is refused only when none is set.
400unknown_auto_goalAn auto: suffix other than cheap, cost (the same as cheap), balanced, quality or fast. Carries allowed.
400auto_routing_disabledToken Meter has turned auto off for this workspace. Name a model, or contact Token Meter.
400auto_routing_no_allowed_model, auto_routing_no_model_in_listsNo model auto may use fits this request and its allow/exclude lists.
400model_lists_only_apply_to_auto, model_lists_lockedallowed_models or excluded_models on a named model, or the workspace does not let requests set them.
400models_not_supported_with_automodels cannot be combined with auto.
400invalid_models, invalid_provider_options, unsupported_provider_option:<key>, invalid_allowed_models, invalid_excluded_modelsA malformed models list, provider object or model list.
400no_endpoint_meets_provider_requirements:<why>No endpoint meets the provider object's or the workspace's data rules.
400max_cost_usd_required, invalid_max_cost_usd, invalid_run_budget_usd, run_id_required_for_budget_controls, run_id_too_longA problem with run_id, run_budget_usd or max_cost_usd. run_id needs max_cost_usd, and run_budget_usd needs run_id.
400run_budget_not_configuredThe run has no budget yet: no request of the run has sent run_budget_usd. Send it on the run's first call.
400invalid_idempotency_keyThe idempotency key is not a UUID.
400auto_routing_not_supported_for_batches, request_not_eligible_for_batch_arbitrageBatch-only refusals; see Batches.
400provider_rejected_requestOnly on Token Meter's keys (auto, or any call from a workspace on credits): the provider behind them refused the request as sent (a parameter, size or content limit of the model). The provider's own text is not passed on.
401invalid_keyThe key is unknown or missing. Use a tl_live_ key from Governance › API keys.
402org_max_request_cost_usd_exceeded, policy_max_request_cost_usd_exceeded, estimated_cost_exceeds_max_cost_usdThe worst-case cost is above a cap. Carries estimated_max_cost_usd and max_cost_usd.
402monthly_budget_exceededOver the workspace's monthly budget. Carries downgrade_available.
402run_budget_exceeded, run_budget_exceeds_org_maxThe run's budget is used up, or is above the workspace's ceiling.
402auto_monthly_limit_reachedAuto's monthly allowance is used up. Carries limit_usd, spent_usd (settled spend) and resets_at, and may carry held_usd (what calls in flight hold).
402platform_keys_require_paid_planAn auto request on the Free plan that no routing policy sends to your own key, from a workspace that does not pay from Token Meter credits. Auto routing on Token Meter's keys needs Growth or above. Add your provider key under Router › Providers and name a model, for example "model": "gpt-4o-mini", or upgrade under Settings › Plan. 429 in Claude Code.
402insufficient_credits, credits_negative, credits_frozenWorkspaces on Token Meter credits only: the request's worst-case cost (full output cap at list price) does not fit the credit balance, or the balance is below zero, or (credits_frozen, with frozen: true) the wallet is on hold while a payment dispute is open. Carries balance_usd, required_usd and top_up_url. Add credit, or lower max_tokens; a frozen wallet needs Token Meter support.
403key_revokedThe key was revoked or has expired. Create a new one.
403batch_arbitrage_not_enabledPrefer: respond-async while Run non-urgent requests as cheaper batch jobs (results within 24 hours) is off in Router defaults (the Defaults link on Router › Rules).
404not_foundNo such route, or no routing decision or batch with that id in this workspace.
409idempotency_key_already_used, idempotency_request_in_progressSee Request headers.
413request_too_largeThe body is over 32 MB on /v1/messages or 2 MB elsewhere.
415unsupported_content_encodingSend the body plain or with Content-Encoding gzip, deflate or br.
422idempotency_key_reused_with_different_requestSee Request headers.
424provider_not_configuredThe request names a model and the workspace has no key of its own for that model's provider. Carries provider. Add one under Router › Providers, or, on a paid plan, send auto.
429rate_limit_exceededOver a rate limit. Carries scope (org or key), limit (per_minute or concurrency) and a Retry-After header. Without limits of your own, each plan has defaults, for the workspace and for each key (Free 50 at once and 600 a minute, Growth 100 and 1,500, Scale 300 and 5,000, Enterprise 1,000 and 15,000).
429auto_spend_in_flightAuto only: the request fits what is left of the monthly allowance, but auto calls already in flight hold it (each holds its worst-case cost, full output cap at list price, until it settles). Carries limit_usd, spent_usd, held_usd and Retry-After. Retry shortly.
429monthly_request_limit_reachedThe workspace has used the routed requests its plan includes this month (see Monthly request limit). Upgrade under Settings › Plan, or wait for the reset on the 1st (UTC). Carries limit, used, resets_at and x-should-retry: false.
429provider_rate_limitedThe provider rate-limited the request. Retry shortly.
500internal_errorA router fault. Nothing was billed.
502provider_network_failureThe provider could not be reached, or its answer could not be read.
503provider_circuit_openThe provider has been failing, so the router is holding requests back. Comes with Retry-After: 30.
503governance_policies_unavailable, monthly_budget_unavailable, routing_settings_unavailable, platform_spend_unavailableThe router could not read a setting it must check (for platform_spend_unavailable: the plan or auto's spend), so it refused rather than skip the check. Retry shortly.
503credits_unavailableThe router could not read the workspace's credit settings, or could not read or write its balance, so it refused rather than spend unchecked. Comes with Retry-After: 30. Nothing was billed.
503provider_unavailableOnly on Token Meter's keys (auto, or any call from a workspace on credits): the provider behind them failed or is out of capacity, and no other model could take the request. Comes with Retry-After: 30. On auto, provider errors are never passed through as they came.

Batches

POST /v1/batches submits up to 1,000 requests to one named model as a single provider batch, at the provider's batch price. Save the body as batch.json:

batch.json
{
  "model": "gpt-4o-mini",
  "action": "nightly-summaries",
  "requests": [
    { "id": "item-1", "input": { "messages": [{ "role": "user", "content": "Summarize ..." }], "customer_ref": "acme" } }
  ]
}
Shell
curl https://router.timewastevc.com/v1/batches \
  -H "Authorization: Bearer $TOKEN_METER_KEY" \
  -H "Content-Type: application/json" \
  -d @batch.json
  • model must be a named model with a capability record. auto is refused with 400 auto_routing_not_supported_for_batches.
  • provider is optional: openai, anthropic or litellm. Gemini has no batch API.
  • action and feature at the top level pick the routing policy for the whole batch. Attribution fields go in each item's input.
  • Each item's id is your own and must be unique in the batch. Items cannot stream or send tools or images.
  • The whole batch is checked against the monthly request limit, rate limits, cost caps, budgets and governance policies before it is accepted.

An accepted batch returns 202:

JSON
{
  "id": "6f1c2a7e-3b9d-4c1e-9a55-0d2f7e8b1c44",
  "status": "queued",
  "provider": "openai",
  "model": "gpt-4o-mini",
  "item_count": 1,
  "policy_id": null
}

Poll it with GET /v1/batches/<id> and read the answers at GET /v1/batches/<id>/items. Send X-TokenMeter-Idempotency-Key to make a retried submission return the batch it already created: 200 with the same fields and idempotent_replay: true.

Coding tools

Coding agents can send their model calls through the router too:

  • Claude Code uses POST /v1/messages (passed through to Anthropic unchanged), POST /v1/messages/count_tokens and GET /v1/models. For Claude Code an open circuit is answered as Anthropic's 529, and a spend cap as a 429 it should not retry. Setup: Claude Code through the router.
  • Codex CLI uses POST /v1/responses (the OpenAI Responses API). Nothing is stored between turns: the whole conversation is sent each time, and previous_response_id is refused. Setup: Codex through the router.

Cline

  1. In Cline's settings, set API Provider to OpenAI Compatible.
  2. Set the base URL to https://router.timewastevc.com/v1.
  3. Paste your tl_live_… key as the API key.
  4. Set the model ID to auto, or to a model with a capability record.

Continue

Add a model to Continue's config.yaml, and put your key in Continue's secrets as TOKEN_METER_KEY:

config.yaml
models:
  - name: Token Meter auto
    provider: openai
    model: auto
    apiBase: https://router.timewastevc.com/v1
    apiKey: ${{ secrets.TOKEN_METER_KEY }}

Calls then show on the dashboard with exact tokens and cost. Cline and Continue do not send the attribution fields above, so these calls arrive without a customer, feature or team.

Count each call once

If you also send a tool's OpenTelemetry data or data events to Token Meter, the same calls count twice. Pick one route per tool.

SDK or router, not both

A call sent through the router and also made with a client wrapped by the Token Meter SDK is metered twice. Use one or the other for each call path.

Troubleshooting

What you seeWhat to do
401 invalid_keyCheck the key starts with tl_live_ and that the environment variable is set in the shell that runs your app. Create a key under Governance › API keys.
403 key_revokedThe key was revoked or expired. Create a new one under Governance › API keys.
404 not_foundWith the OpenAI SDK, the base URL must end in /v1. With the Anthropic SDK, it must not.
400 model_capability_not_configuredOn a paid plan, send auto, or add the model under Router › Providers › Advanced › Model capabilities.
400 model_does_not_support_toolsTick Tools on the model's capability record, or send the request to a model that has it.
424 provider_not_configuredA named model runs on your own provider key, and this workspace has none for that provider. Click Add provider key under Router › Providers, or, on a paid plan, send auto, which needs no key.
402 auto_monthly_limit_reachedAuto's allowance resets on the 1st of next month (UTC). Until then, name a model that runs on your own provider key.
402 platform_keys_require_paid_planThe workspace is on the Free plan, where auto does not run on Token Meter's keys. Add your provider key under Router › Providers and name a model, for example "model": "gpt-4o-mini", or upgrade under Settings › Plan.
429 monthly_request_limit_reachedThe plan's routed requests for this month are used. Upgrade under Settings › Plan, or wait for the reset on the 1st (UTC).
anthropic/gpt-4o-mini (a mismatched provider prefix) refusedSend the bare model name; the router works out the provider from it.
x-tokenmeter-cache: ineligible:temperature_not_setSend temperature: 0, or switch on Requests that set no temperature under Router › Caching › Advanced.
The same call is counted twiceThe call goes through the router and through a wrapped SDK client, or a coding tool also sends telemetry. Keep one route.