@brainrouter/js
v1.0.5
Published
TypeScript/JavaScript SDK for BrainRouter API
Readme
@brainrouter/js
The official TypeScript/JavaScript SDK for BrainRouter, an intelligent AI model gateway and routing engine.
Installation
npm install @brainrouter/jsQuick Start
import { BrainRouter } from '@brainrouter/js';
const br = new BrainRouter({
apiKey: 'br_live_...',
});
// Sync chat
const completion = await br.chat.completions.create({
messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(completion.choices[0].message.content);
// Streaming chat
const stream = br.chat.completions.stream({
messages: [{ role: 'user', content: 'Tell me a story' }],
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0].delta.content || '');
}Features
- Intelligent Routing: Use policies to automatically select the best model for your task.
- Model Recommendation: Get recommendations for which model to use based on your prompt.
- Unified API: One interface for dozens of models across providers.
- Conversation Management: Easily manage conversation history and messages.
Configuration
| Option | Type | Default | Description |
| --- | --- | --- | --- |
| apiKey | string | process.env.BRAINROUTER_API_KEY | Your BrainRouter API Key |
| baseURL | string | https://api.brainrouter.app | API Base URL |
| timeout | number | 60000 | Request timeout in ms |
License
MIT
