SDK
Install and verify
Four steps from nothing to a first completion.
This page takes you from a key to a first chat completion. You are done when a completion comes back with text in it. Pick TypeScript or Python. The CLI is not required for any of this.
Four steps
Get an API key
Open conifer.build/console#/keys and mint a key. You can do this before entering a card. A key is free to hold and spends nothing until it is used. The key is shown once, so save it now.
terminalexport CONIFER_API_KEY='sk-conifer-…'Your first call needs a balance on the account. Set up pay as you go at Account & billing. Each model is priced per token as published in the catalog.
Install a client
There are two supported choices. If you are unsure, take the first. The official OpenAI package is the ordinary client from npm or PyPI, the same package you would install to call OpenAI directly. Conifer speaks the OpenAI wire, so the package works unmodified. For the Anthropic wire, install
npm install @anthropic-ai/sdkorpip install anthropicinstead.terminalnpm install openaiThe second choice is our own open-source client at ConiferKit/use-conifer. It gives you the exact cost of every call and a hard spend ceiling. It has one unscoped name on both registries. Keep the
[tls]extra on macOS. See The Conifer SDK.terminalnpm i conifer-sdkPoint the client at Conifer
Either pass the base URL and key in code, or set the two variables the OpenAI client already reads and leave the source unchanged.
terminalexport OPENAI_BASE_URL=https://api.conifer.build/v1 export OPENAI_API_KEY=$CONIFER_API_KEYMake one call
The TypeScript sample is an App Router handler. Paste it into
app/api/verify/route.ts. The Python sample is a script you run directly.app/api/verify/route.tsimport OpenAI from "openai"; export function conifer() { const apiKey = process.env.CONIFER_API_KEY; if (!apiKey) { throw new Error("CONIFER_API_KEY is missing. Set it before calling the gateway."); } return new OpenAI({ baseURL: "https://api.conifer.build/v1", apiKey, }); } export async function POST(req: Request) { const res = await conifer().chat.completions.create({ model: "claude-haiku-4-5", max_tokens: 64, messages: [{ role: "user", content: "Say hello from Conifer and nothing else." }], }); return Response.json({ content: res.choices[0].message.content }); }
If it did not work
- 401,
invalid_api_key. The key is missing, mistyped, or revoked. Check that the variable reached the process. - 402,
insufficient_quota. The key is valid but the account has no balance. Set up billing. Nothing was charged. - 404,
model_not_found. That id is not in the catalog. The catalog is public and needs no key.terminalcurl -s https://api.conifer.build/v1/catalogGET /v1/modelsis the same list scoped to your key. See the catalog.
Every error name is on Errors.
Optional: the MCP server
The SDK package also ships an MCP server. With it, an agent that is already driving your editor can ask any model in the catalog mid-task and see what every call cost. There is no build step. The package is conifer-sdk, unscoped.
{
"mcpServers": {
"conifer": {
"command": "npx",
"args": ["-y", "conifer-sdk", "conifer-mcp"],
"env": { "CONIFER_API_KEY": "sk-conifer-…" }
}
}
}Claude Code
claude mcp add conifer --env CONIFER_API_KEY=sk-conifer-… -- npx -y conifer-sdk conifer-mcpClaude Desktop
Claude Desktop is a different program from Claude Code, with a different config file. Open Settings, then Developer, then Edit Config to open claude_desktop_config.json. Afterwards quit, not just close the window, and reopen.
{
"mcpServers": {
"conifer": {
"command": "/absolute/path/to/npx",
"args": ["-y", "conifer-sdk", "conifer-mcp"],
"env": { "CONIFER_API_KEY": "sk-conifer-…" }
}
}
}Codex
[mcp_servers.conifer]
command = "npx"
args = ["-y", "conifer-sdk", "conifer-mcp"]
env = { "CONIFER_API_KEY" = "sk-conifer-…" }Cursor
{
"mcpServers": {
"conifer": {
"command": "npx",
"args": ["-y", "conifer-sdk", "conifer-mcp"],
"env": { "CONIFER_API_KEY": "sk-conifer-…" }
}
}
}VS Code
The inputs block makes VS Code prompt for the key instead of committing it.
{
"inputs": [
{
"type": "promptString",
"id": "conifer-key",
"description": "Conifer API key",
"password": true
}
],
"servers": {
"conifer": {
"type": "stdio",
"command": "npx",
"args": ["-y", "conifer-sdk", "conifer-mcp"],
"env": { "CONIFER_API_KEY": "${input:conifer-key}" }
}
}
}What the agent gets
| Tool | What it does |
|---|---|
conifer_complete | Ask any model a question or hand it a conversation. The answer carries its cost. Takes max_cost_nanousd. |
conifer_compare | Run the same prompt across two to five models at once. Each answer is listed beside its cost, cheapest first. |
conifer_list_models | The catalog this key can call, with capabilities, context windows and prices. |
conifer_choose_model | The cheapest model that has the capabilities you name. |
conifer_embed | Embed one string or a batch and report the vector count, dimensions and cost. Takes max_cost_nanousd. |
conifer_balance | Remaining credit on the account behind the key. Read only. |
Each model’s call in a comparison is its own billed turn. max_cost_nanousd caps each turn, not the total.