Vanuit TypeScript
Zelfde OpenAI-compatible endpoint, zelfde SDK, één regel config.
Installeer
npm install openai
Richt het op 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: 'Leg monads uit in simpele taal.' }],
});
console.log(resp.choices[0].message.content);
console.log('routed naar:', resp.model);
Streaming
const stream = await client.chat.completions.create({
model: 'auto',
messages: [{ role: 'user', content: 'Schrijf een haiku over routers.' }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}
Gebruik een specifieke agent persona
const resp = await client.chat.completions.create({
model: 'auto',
messages: [{ role: 'user', content: 'Review deze code' }],
// @ts-expect-error custom veld op Soriku
x_agent_id: 'code-reviewer',
});