@namzu/openrouter
v3.0.3
Published
OpenRouter LLM provider for @namzu/sdk. Access to 200+ models (Claude, GPT-4, Llama, Mixtral) via OpenRouter's unified API.
Readme
The OpenRouter model driver for Namzu.
Install · Usage · Documentation
Implements the kernel's LLMProvider interface over OpenRouter, which
fronts many vendors behind one key and one wire format. Installed only if
you use it — the kernel has no preferred vendor and no driver is a
dependency of it.
Install
pnpm add @namzu/sdk @namzu/openrouter@namzu/sdk is a peer dependency. Install both.
Usage
import { ProviderRegistry } from '@namzu/sdk'
import { registerOpenRouter } from '@namzu/openrouter'
registerOpenRouter() // once, at startup
const { provider } = ProviderRegistry.create({
type: 'openrouter',
apiKey: process.env.OPENROUTER_API_KEY ?? '',
siteUrl: 'https://example.com', // optional
siteName: 'Example', // optional
})
for await (const chunk of provider.chatStream({
model: 'anthropic/claude-opus-5',
messages: [{ role: 'user', content: 'Hello' }],
})) {
if (chunk.delta.content) process.stdout.write(chunk.delta.content)
}chatStream is the only model entry point; a non-streaming call is that
stream collected. In practice the kernel's turn loop calls it and hands you
events.
Reasoning
The driver carries the SDK's thinking controls and returns what the model thinks:
import { registerOpenRouter, OpenRouterProvider } from '@namzu/openrouter'
registerOpenRouter()
const provider = new OpenRouterProvider({ apiKey: 'sk-example' })
for await (const chunk of provider.chatStream({
model: 'nvidia/nemotron-3.5-lightning:free',
messages: [{ role: 'user', content: 'What is 17 times 3?' }],
thinking: { type: 'enabled', budgetTokens: 4_096 },
})) {
if (chunk.delta.reasoning?.text) process.stderr.write(chunk.delta.reasoning.text)
if (chunk.delta.content) process.stdout.write(chunk.delta.content)
}thinking: { type: 'enabled', budgetTokens } is sent as reasoning: { enabled: true,
max_tokens }, adaptive as { enabled: true }, disabled as { enabled: false }, and
effort as { effort }. effort: 'max' and 'ultra' are refused rather than sent — this
wire cannot carry those levels. Reasoning arrives on the kernel's reasoning channel with an
index per block and a done marker when output starts, and usage.reasoningTokens reports
the thinking share of the completion tokens OpenRouter already bills as output. OpenRouter
sends each fragment twice (a flat reasoning string and the indexed reasoning_details);
the driver emits it once.
Documentation
License
FSL-1.1-MIT, converting to MIT two years after each release.
