zidane/ providers/ openrouter
The OpenRouter provider, one API key for models from many vendors.
import { … } from 'zidane/providers/openrouter'src/providers/openrouter.ts
Use openrouter() to reach models from several vendors through one account. It reads OPENROUTER_API_KEY when you pass no key. It sends prompt-cache breakpoints, which the Anthropic and Gemini routes honor. Set promptCacheKey (for example 'session') to send a cache-affinity key. Model ids use the vendor/model form, and normalizeOpenRouterModelId() maps legacy ids to their current slugs.
import { createAgent } from 'zidane'
import { openrouter } from 'zidane/providers/openrouter'
const agent = createAgent({ provider: openrouter({ defaultModel: 'anthropic/claude-fable-5.1' }) })
const stats = await agent.run({ prompt: 'Summarize README.md in three bullets.' })
console.log(stats.turns)Functions#
normalizeOpenRouterModelIdFunction#
Maps legacy OpenRouter model ids to their current slugs and returns other ids unchanged.
function normalizeOpenRouterModelId(modelId: string): stringParameters
| Name | Type | Description |
|---|---|---|
| modelId | string | Model id as stored or requested. |
Returns
stringopenrouterFunction#
OpenRouter provider.
Thin wrapper around openaiCompat with OpenRouter-specific defaults
(base URL, default model) and required attribution headers.
function openrouter(params?: OpenRouterParams): ProviderParameters
| Name | Type | Description |
|---|---|---|
| params? | OpenRouterParams | API key, default model, capabilities, PDF engine and prompt-cache key settings. |
Returns
Example
import { createAgent } from 'zidane'
import { openrouter } from 'zidane/providers/openrouter'
const agent = createAgent({
provider: openrouter({ apiKey: process.env.OPENROUTER_API_KEY }),
})
await agent.run({ prompt: 'Say hello.' })Constants#
OPENROUTER_DEFAULT_MODELConstant#
Model the OpenRouter provider uses when none is configured.
const OPENROUTER_DEFAULT_MODEL = 'anthropic/claude-opus-5.5'Interfaces#
OpenRouterParamsInterface#
Options for openrouter.
interface OpenRouterParamsProperties
| Name | Type | Default | Description |
|---|---|---|---|
| apiKey? | string | API key. Falls back to the | |
| capabilities? | ProviderCapabilities | Provider capability flags. OpenRouter itself is a router — whether vision,
native image-in-tool-result, or document/PDF input are supported depends on
the downstream model. Default: Override when routing to a known-text-only model (e.g. | |
| defaultModel? | string | 'anthropic/claude-opus-5.5' | Model used when a request does not set one. |
| pdfEngine? | 'native' | 'pdf-text' | 'mistral-ocr' | PDF-parsing engine for OpenRouter's | |
| promptCacheKey? | PromptCacheKeyOption | Prompt-cache affinity key, sent as OpenRouter reads this field as its sticky-routing key, so enabling it pins a
session's turns to the provider endpoint that already holds its cache —
complementing the automatic stickiness it applies after a cached request.
| |
| promptCacheKeyHeader? | string | Additionally send the affinity key as this HTTP header, for gateways in front of OpenRouter that route on a header rather than a body field. |