Overview
Set up Claude Code, Codex, OpenCode and the OpenAI and Anthropic SDKs to use Spare Inference.
Spare speaks the OpenAI Chat Completions, OpenAI Responses and Anthropic Messages APIs, so most tools only need a new base URL, your Spare key and a model id. These guides give the exact setup for each one.
Coding agents
Claude Code
Run it on DeepSeek V4.1 Flash, or keep Claude with the Router.
Codex CLI
Add Spare as a model provider in config.toml.
OpenCode
Add Spare as a custom provider in opencode.json.
Each agent guide has a Copy setup prompt button: paste the prompt into the agent and it does the setup itself, following the guide.
SDKs
OpenAI SDK
Chat Completions and Responses, in Python and TypeScript.
Anthropic SDK
Messages, in Python and TypeScript.
Two ways to connect
Every guide offers both:
| Run on DeepSeek V4.1 Flash | Keep your model, add the Router | |
|---|---|---|
| Model id | deepseek-v4.1-flash | spare/auto |
| Talks to | The Spare API | The CLI's Cost routing on your machine |
| What you need | A Spare key | A Spare key, the CLI, and your provider key or subscription |
| What changes | Every request goes to Spare | Only the turns your routing policy sends to the economy model |
| Billed by | Spare, at the live price | Spare for routed turns; your provider for the rest |
| Best for | Lowest cost, new projects | Cutting the bill without changing models |
Provider failures are handled for you either way: a request moves to the next provider serving the model. To fall back to a different model, see Model fallbacks.
Not listed?
Anything that lets you set a base URL works:
| Your tool speaks | Base URL | Key header |
|---|---|---|
| OpenAI Chat Completions or Responses | https://api.spareinference.ai/v1 | Authorization: Bearer |
| Anthropic Messages | https://api.spareinference.ai | x-api-key or Authorization: Bearer |
Use the model id deepseek-v4.1-flash. If the tool asks for limits, the context window is 1M tokens
and the maximum output 384K.
How is this guide?