Search and list models
Use rb.models() to discover available models, search by keywords, or filter by modality.
import { RouterBrain } from '@router-brain/sdk';
const rb = new RouterBrain('sk-your-api-key');
// List all models
const all = await rb.models();
console.log(all.data.length, 'models available');
// Search by keyword
const models = await rb.models({ q: 'gpt-4' });
for (const m of models.data) {
console.log(m.id, m.pricing.prompt, '/', m.pricing.completion);
}
// Filter by modality + paginate
const result = await rb.models({
outputModalities: ['image'],
inputModalities: ['text'],
limit: 5,
sort: 'newest',
});
console.log(result.has_more ? 'more available' : 'last page');
Query options
| Parameter | Type | What it does |
|---|---|---|
q | string | Search by model name or description |
inputModalities | string[] | Filter by input types (e.g. ['text', 'image']) |
outputModalities | string[] | Filter by output types |
limit | number | Results per page |
offset | number | Items to skip |
sort | 'newest' | 'name' | Sort order |
Get model details
Use rb.modelEndpoint(code) to check pricing and available routes for a specific model.
const detail = await rb.modelEndpoint('gpt-4o');
console.log(detail.name); // Display name
console.log(detail.pricing.prompt); // Prompt token price
// Per-endpoint details
for (const ep of detail.endpoints) {
console.log(ep.provider_name); // Provider
console.log(ep.latency_30m); // Avg latency in ms
console.log(ep.uptime_5m); // Recent availability
}
Rerank documents
Use rb.rerank() to rank documents by how relevant they are to a query — useful for RAG and search.
const result = await rb.rerank({
model: 'rerank-model-name',
query: 'Applications of quantum computing',
documents: [
'Quantum computing has important applications in cryptography',
'Classical computers use binary bits (0 or 1)',
'Qubits use superposition to represent 0 and 1 simultaneously',
"Shor's algorithm efficiently factors large integers on quantum computers",
],
top_n: 2,
});
for (const item of result.results) {
console.log(`#${item.index} score: ${item.relevance_score}`);
}
// Return original documents alongside scores
const result2 = await rb.rerank({
model: 'rerank-model-name',
query: 'RAG retrieval-augmented generation',
documents: docs,
return_documents: true,
});
Options
| Parameter | Type | Required | What it does |
|---|---|---|---|
model | string | Yes | Rerank model ID |
query | string | Yes | The query to rank against |
documents | (string | { text: string })[] | Yes | Documents to rank |
top_n | number | null | No | Return only top N results |
return_documents | boolean | No | Include original document text in response |
max_tokens_per_doc | number | null | No | Max tokens to read per document |
instructions | string | No | Guidance for ranking |