namzu.aidocs

OpenRouter Provider

Configure @namzu/openrouter for multi-vendor model access through OpenRouter.

@namzu/openrouter gives Namzu access to OpenRouter's multi-vendor model catalog through a single provider package. It is useful when vendor flexibility matters more than binding directly to one model API.

1. When to Use It

Choose this package when you want to switch among vendors or models without changing the Namzu runtime wiring.

2. When Not to Use It

Choose another provider when:

  • you already know the runtime is tied to one vendor and want the smallest translation layer
  • you only need a generic OpenAI-compatible endpoint and do not need OpenRouter-specific behavior

3. Install

pnpm add @namzu/sdk @namzu/openrouter

4. Register and Create the Provider

import { ProviderRegistry } from '@namzu/sdk'
import { registerOpenRouter } from '@namzu/openrouter'
 
registerOpenRouter()
 
const { provider, capabilities } = ProviderRegistry.create({
  type: 'openrouter',
  apiKey: process.env.OPENROUTER_API_KEY!,
  siteUrl: 'https://myapp.example',
  siteName: 'My App',
})

5. Sanity-Check With a Direct Provider Call

const response = await provider.chat({
  model: 'anthropic/claude-sonnet-4',
  messages: [{ role: 'user', content: 'Say hello in one sentence.' }],
})
 
console.log(response.message.content)

6. Configuration

FieldRequiredDescription
apiKeyYesOpenRouter API key
baseUrlNoOverride the default OpenRouter API base URL
siteUrlNoOptional site URL for OpenRouter analytics
siteNameNoOptional site name for OpenRouter analytics
timeoutNoRequest timeout in milliseconds

7. Capability Snapshot

The package exports OPENROUTER_CAPABILITIES:

{
  supportsTools: true,
  supportsStreaming: true,
  supportsFunctionCalling: true,
}

Actual tool quality still depends on the chosen upstream model.

8. Operational Notes

  • Model identifiers typically use the vendor/model-name form.
  • This package is fetch-based and keeps runtime dependencies small.
  • If you do not need OpenRouter-specific behavior and only need a generic OpenAI-compatible client, @namzu/http is the lighter conceptual fit.
  • OPENROUTER_BASE_URL can override the default base URL process-wide.
  • siteUrl and siteName are useful when you want OpenRouter-side attribution or analytics context.
  • The provider also implements listModels() and healthCheck().

9. Common Errors

ErrorMeaningFix
Unsupported provider type: openrouterregistration never happenedcall registerOpenRouter() first
missing API key errorno apiKey passedset OPENROUTER_API_KEY and pass it into config
model not foundincorrect vendor/model identifierverify the model name in OpenRouter's catalog

On this page