Non-streaming

import { RouterBrain } from "@routerbrain/sdk";

const client = new RouterBrain({
  apiKey: process.env.ROUTERBRAIN_API_KEY!,
  baseURL: "https://51kik.com/v1",
});

const result = await client.chat.send({
  chatRequest: {
    model: "YOUR_MODEL_ID",
    messages: [{ role: "user", content: "Hello" }],
  },
});

console.log(result.choices[0]?.message?.content);

Equivalent curl: First request.

Streaming

const stream = await client.chat.send({
  chatRequest: {
    model: "YOUR_MODEL_ID",
    stream: true,
    messages: [{ role: "user", content: "Write a short poem" }],
  },
});

for await (const chunk of stream) {
  const delta = chunk.choices?.[0]?.delta?.content;
  if (delta) process.stdout.write(delta);
}

Returns an EventStream of chat.completion.chunk. Failures throw GatewaySseError.

PDF plugin (optional)

await client.chat.send({
  chatRequest: {
    model: "YOUR_MODEL_ID",
    messages: [/* ... */],
    plugins: {
      pdf: { engine: "ocr", max_pages: 10 },
    },
  },
});

The SDK maps plugins.pdf to pdf_preprocess on the wire.

Tools

Pass OpenAI-shaped tools and tool_choice on chatRequest — same as Create chat completion.

Node message helpers

// @routerbrain/sdk/node only — do not bundle for browser
const messages = await client.chat.messages.fromFile({
  model: "YOUR_MODEL_ID",
  path: "./doc.pdf",
  userText: "Summarize",
});

See Limitations.

Related

Streaming · Errors