skip to content
Install and verify

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

  1. 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.

    terminal
    export 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.

  2. 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/sdk or pip install anthropic instead.

    terminal
    npm install openai

    The 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.

    terminal
    npm i conifer-sdk
  3. Point 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.

    terminal
    export OPENAI_BASE_URL=https://api.conifer.build/v1
    export OPENAI_API_KEY=$CONIFER_API_KEY
  4. Make 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.ts
    import 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.
    terminal
    curl -s https://api.conifer.build/v1/catalog
    GET /v1/models is 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.

mcp.json
{
  "mcpServers": {
    "conifer": {
      "command": "npx",
      "args": ["-y", "conifer-sdk", "conifer-mcp"],
      "env": { "CONIFER_API_KEY": "sk-conifer-…" }
    }
  }
}

Claude Code

terminal
claude mcp add conifer --env CONIFER_API_KEY=sk-conifer--- npx -y conifer-sdk conifer-mcp

Claude 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.

claude_desktop_config.json
{
  "mcpServers": {
    "conifer": {
      "command": "/absolute/path/to/npx",
      "args": ["-y", "conifer-sdk", "conifer-mcp"],
      "env": { "CONIFER_API_KEY": "sk-conifer-…" }
    }
  }
}

Codex

~/.codex/config.toml
[mcp_servers.conifer]
command = "npx"
args = ["-y", "conifer-sdk", "conifer-mcp"]
env = { "CONIFER_API_KEY" = "sk-conifer-…" }

Cursor

.cursor/mcp.json
{
  "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.

.vscode/mcp.json
{
  "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

ToolWhat it does
conifer_completeAsk any model a question or hand it a conversation. The answer carries its cost. Takes max_cost_nanousd.
conifer_compareRun the same prompt across two to five models at once. Each answer is listed beside its cost, cheapest first.
conifer_list_modelsThe catalog this key can call, with capabilities, context windows and prices.
conifer_choose_modelThe cheapest model that has the capabilities you name.
conifer_embedEmbed one string or a batch and report the vector count, dimensions and cost. Takes max_cost_nanousd.
conifer_balanceRemaining 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.