Examples
Same client you already use. Tokand sits on the base URL.
Point the client
import OpenAI from "openai"
const client = new OpenAI({
baseURL: "https://api.tokand.com/v1",
apiKey: process.env.TOKAND_KEY,
})
await client.chat.completions.create({
model: "gpt-4.1",
tier: "measured",
messages,
})Wrap the client
import { withTokand } from "@tokand/sdk"
const ai = withTokand(openai, {
apiKey: process.env.TOKAND_KEY,
bypassOnError: true,
})
await ai.chat.completions.create({ model, messages })Decide
A typed decision is its own call. Add tier to shrink the state first. The three choices are documented on Decide.
await ai.decide({
using: "sava",
state: { messages },
questions,
})
await ai.decide({
using: "your-model",
model: "gpt-4.1",
tier: "measured",
state: { messages },
questions,
})
await ai.decide({
using: "tokand-model",
model: "tokand/qwen",
state: { messages },
questions,
})One call
Tokand sees { messages, tools } and shrinks it, then calls your sender with the shrunk version. Tokand never calls the model here — your sender does.
import { tokand } from "@tokand/sdk"
const res = await tokand(
{ messages, tools },
(req) => provider.complete(req),
{ apiKey: process.env.TOKAND_KEY }
)