Gateway
OpenAI and Anthropic SDKs
The gateway speaks OpenAI’s and Anthropic’s APIs, so their official SDKs work with a base URL and a key.
Conifer Gateway is an OpenAI-compatible API and an Anthropic-compatible one: the official SDKs of both work once you change their base URL and key. Each reads the key from CONIFER_API_KEY here.
| SDK | Base URL | Key |
|---|---|---|
| OpenAI, Python and TypeScript | https://gateway-api.conifer.build/v1 | Sent as Authorization: Bearer |
| Anthropic, Python and TypeScript | https://gateway-api.conifer.build | Sent as x-api-key |
The TypeScript samples use await at the top level, which needs an ES module: a .mts file, or a package whose package.json says "type": "module".
OpenAI’s SDK
pip install openai
npm install openaiPython
import os
from openai import OpenAI
client = OpenAI(
base_url="https://gateway-api.conifer.build/v1",
api_key=os.environ["CONIFER_API_KEY"],
)
reply = client.chat.completions.create(
model="claude-haiku-5-5",
messages=[
{"role": "user", "content": "Hi"},
],
)
print(reply.model, reply.choices[0].message.content)TypeScript
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://gateway-api.conifer.build/v1",
apiKey: process.env.CONIFER_API_KEY,
});
const reply = await client.chat.completions.create({
model: "claude-haiku-5-5",
messages: [{ role: "user", content: "Hi" }],
});
console.log(reply.model, reply.choices[0].message.content);The gateway is tested with OpenAI’s SDKs for Chat Completions, Responses, embeddings, images, tools, the model list, the cost on each answer, and errors. Any model in the catalog answers through it, and a router’s name works for all but embeddings and images, which take a model’s.
Anthropic’s SDK
pip install anthropic
npm install @anthropic-ai/sdkPython
import os
from anthropic import Anthropic
client = Anthropic(
base_url="https://gateway-api.conifer.build",
api_key=os.environ["CONIFER_API_KEY"],
)
message = client.messages.create(
model="claude-haiku-5-5",
max_tokens=1024,
messages=[
{"role": "user", "content": "Hi"},
],
)
print(message.model, message.content[0].text)TypeScript
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://gateway-api.conifer.build",
apiKey: process.env.CONIFER_API_KEY,
});
const message = await client.messages.create({
model: "claude-haiku-5-5",
max_tokens: 1024,
messages: [{ role: "user", content: "Hi" }],
});
const block = message.content[0];
if (block.type === "text") console.log(message.model, block.text);The gateway is tested with Anthropic’s SDKs for Messages, thinking, counting tokens, the model and request id on each answer, and errors. The base URL has no /v1: the SDK adds /v1/messages.
What every answer adds
An answer through either SDK is the model’s own, in its usual shape, its model the model as its provider names it. The gateway adds a router field to the body, whose served.model is the model’s catalog id, and headers such as x-conifer-model and x-conifer-cost-nanousd, which the API reference lists. Both SDKs send a 409, a 429 or a 5xx again by themselves and obey the gateway’s x-should-retry: false.
Read the cost
An SDK hands back the body, so a header takes one more step: each SDK’s own way to the raw response. With the client made as above, each of these prints the cost in nanodollars, then the answer. The header is on a whole answer; a stream carries the cost in its last event’s router object instead.
OpenAI, Python
raw = client.chat.completions.with_raw_response.create(
model="claude-haiku-5-5",
messages=[
{"role": "user", "content": "Hi"},
],
)
print(raw.headers.get("x-conifer-cost-nanousd"))
reply = raw.parse()
print(reply.choices[0].message.content)OpenAI, TypeScript
const { data: reply, response } = await client.chat.completions
.create({
model: "claude-haiku-5-5",
messages: [{ role: "user", content: "Hi" }],
})
.withResponse();
console.log(response.headers.get("x-conifer-cost-nanousd"));
console.log(reply.choices[0].message.content);Anthropic, Python
raw = client.messages.with_raw_response.create(
model="claude-haiku-5-5",
max_tokens=1024,
messages=[
{"role": "user", "content": "Hi"},
],
)
print(raw.headers.get("x-conifer-cost-nanousd"))
message = raw.parse()
print(message.content[0].text)Anthropic, TypeScript
const { data: message, response } = await client.messages
.create({
model: "claude-haiku-5-5",
max_tokens: 1024,
messages: [{ role: "user", content: "Hi" }],
})
.withResponse();
console.log(response.headers.get("x-conifer-cost-nanousd"));
const block = message.content[0];
if (block.type === "text") console.log(block.text);Other clients
Editors, coding agents and chat apps that let you set an OpenAI-compatible base URL and an API key may work the same way: Cursor, VS Code, Zed, Aider, opencode, Open WebUI, Pi and others like them. Conifer has not tested them. Any of them needs two settings:
- its OpenAI-compatible base URL, set to
https://gateway-api.conifer.build/v1; - its API key, set to your
sk-cg-key.
Then give it a model id from the catalog, or a router’s name. Claude Code and Codex are tested, and have pages of their own.