docs / guides / use-from-typescript

Use from TypeScript

Same OpenAI-compatible endpoint, same SDK, one line of config.

Install

npm install openai

Point it at Soriku

import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'http://localhost:8765/api/v1',
apiKey: 'soriku-local',
});
const resp = await client.chat.completions.create({
model: 'auto',
messages: [{ role: 'user', content: 'Explain monads in plain English.' }],
});
console.log(resp.choices[0].message.content);
console.log('routed to:', resp.model);

Streaming

const stream = await client.chat.completions.create({
model: 'auto',
messages: [{ role: 'user', content: 'Write a haiku about routers.' }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}

Use a specific agent persona

const resp = await client.chat.completions.create({
model: 'auto',
messages: [{ role: 'user', content: 'Review this code' }],
// @ts-expect-error custom field on Soriku
x_agent_id: 'code-reviewer',
});