SDKs and frameworks
OpenAI Node SDK
Point the OpenAI Node / TypeScript SDK at TokRouter with baseURL, including streaming and a security note.
npm install openaiimport OpenAI from 'openai'
const client = new OpenAI({
apiKey: process.env.TOKROUTER_API_KEY!,
baseURL: 'https://api.tokrouter.dev/v1',
})
const resp = await client.chat.completions.create({
model: 'gpt-5.4-mini',
messages: [{ role: 'user', content: 'Explain SSE in one sentence' }],
})
console.log(resp.choices[0].message.content)Streaming
const stream = await client.chat.completions.create({
model: 'claude-sonnet-5',
messages: [{ role: 'user', content: 'Write a four-line poem' }],
stream: true,
})
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? '')
}Do not use the key in the browser
dangerouslyAllowBrowser is fine for local experiments only: a key bundled into the frontend lets any
visitor spend your balance. In production, hold the key on your backend and proxy the request.