For AI agents, the documentation index lists all pages. Append .md to a documentation URL for Markdown, or request text/markdown.

Skip to Content
spare inference

Cost routing

Keep your Claude or OpenAI model for the hard turns and route the rest to cheaper open models, with the CLI's auto router running on your machine.

2 min readEdit this page

Cost routing moves workloads off an expensive frontier model and onto an open model, without changing your agent. The CLI's auto router, which runs on your machine, decides request by request whether a turn needs your strong model or whether an open model handles it just as well. You give it two models, a strong one and an economy one, and point your agent at it.

RoleExampleBilled by
StrongYour Claude or OpenAI model, through your key or subscriptionYour provider or subscription
Economydeepseek-v4.1-flash on SpareSpare, at the live price

Routing itself is free. The Spare API doesn't route between models on its own: a request to https://api.spareinference.ai runs the model it names. To change what runs behind a name without the CLI, use a routing preset.

Set up

  1. Connect both models to the CLI: your strong model with a key or subscription, and Spare with your SPARE_API_KEY. Check that both appear in spare models.

  2. Bind the auto router to the two routes, using the provider:model ids that spare models prints:

    spare policy init auto --router auto \
      --strong <provider>:<your-strong-model> \
      --economy <provider>:deepseek-v4.1-flash
    spare policy check
  3. Start the CLI and send requests to the model spare/auto:

    spare start
    spare claude --model spare/auto    # or: spare codex --model spare/auto

Any OpenAI- or Anthropic-format client can use it too: point it at the CLI's local address and send "model": "spare/auto". Naming a specific model instead skips the Router for that request.

How it decides

The policy file policy-lock.yaml that spare policy init writes maps kinds of requests to the strong or the economy tier. A request that matches no rule goes to the default tier. Edit the policy and run spare policy check before reloading.

Routing picks a model for a request that would succeed. It is separate from fallbacks, which replace a request that failed.

See where each turn went

spare requests --limit 25

Each row shows the model you asked for, the model and provider that served it, its tokens, cost and status. Turns served by Spare also appear in the console's Activity page, with their settlement.

Your data

The Router runs on your machine. Turns it sends to your strong model go straight from the CLI to your provider and never pass through Spare. Turns sent to Spare are recorded without their prompt or response content.

How is this guide?