Skip to main content

Function: openrouter()

openrouter(modelId, config?): ModelConfig

Defined in: packages/core/src/providers/factories.ts:355

Configure OpenRouter (https://openrouter.ai) provider explicitly.

OpenRouter is a unified gateway over many model vendors. Model IDs use vendor/model form (e.g. anthropic/claude-sonnet-4, openai/gpt-4o, google/gemini-2.5-pro). Because slash-form IDs are ambiguous with other providers, OpenRouter is not auto-detected — you must use this factory or the explicit openrouter: prefix.

Multimedia: images, video frames, and PDF/file inputs flow through the existing multimodal translator and are accepted by OpenRouter on the subset of upstream models that support them (Claude 3+, GPT-4o, Gemini, etc.). Audio input is only supported on a small set of OpenRouter models (notably openai/gpt-4o-audio-preview and Gemini variants).

Parameters

modelId

string

OpenRouter model ID, e.g. 'anthropic/claude-sonnet-4'

config?

ProviderConfig & object

Optional configuration (provider settings, app attribution, provider routing, reasoning).

Returns

ModelConfig

Examples

const bot = new Baleybot({
model: openrouter('anthropic/claude-sonnet-4')
});
const bot = new Baleybot({
model: openrouter('openai/gpt-4o', {
app: { httpReferer: 'https://myapp.com', appTitle: 'My App' },
})
});
const bot = new Baleybot({
model: openrouter('meta-llama/llama-3.1-70b-instruct', {
providerRouting: { order: ['Together', 'Fireworks'], allow_fallbacks: false },
})
});
const bot = new Baleybot({
model: openrouter('anthropic/claude-sonnet-4', {
reasoning: { effort: 'high' }
})
});