@polyweave/openrouter (1.0.5)
Published 2026-07-10 18:31:24 +00:00 by Dvorak
Installation
@polyweave:registry=https://hub.kl1.tenere.ai/api/packages/Polyweave/npm/npm install @polyweave/openrouter@1.0.5"@polyweave/openrouter": "1.0.5"About this package
@polyweave/openrouter
OpenRouter adapter for Polyweave - unified access to 300+ AI models from multiple providers. Supports text generation, vision/multimodal, image generation, SSE streaming, tool calling, automatic fallbacks/routing, and lazy cost estimation with API pricing lookup.
Synopsis
import { createOpenRouterAdapter } from '@polyweave/openrouter';
const adapter = createOpenRouterAdapter({ apiKey: 'YOUR_API_KEY' });
adapter.source.pipe(someSink);
adapter.sink.write({ type: 'PARAM', content: { key: 'model', value: 'openai/gpt-4o' } });
adapter.sink.write({ type: 'TEXT', content: { text: 'Hello!' } });
Install
npm install @polyweave/openrouter
API
createOpenRouterAdapter(config)
Returns an IFrameDuplex stream adapter. Configuration options:
| Option | Type | Default | Description |
|---|---|---|---|
apiKey |
string | process.env.OPENROUTER_API_KEY |
OpenRouter API key |
baseURL |
string | 'https://openrouter.ai/api/v1' |
API base URL |
timeout |
number | 60000 |
Request timeout in ms |
maxRetries |
number | 2 |
Max retry count |
Frame Types
- Input:
TEXT,IMAGE,TOOL_RESULT,PARAM,COST_CHECK,START,END - Output:
TEXT,IMAGE,TOOL_CALL,RECEIPT,ERROR,COST,END
Tasks
Default: chat completion with full tool calling, streaming (SSE), vision support, and automatic model fallbacks. Image generation routed via Gemini-compatible endpoints when model supports it. Cost estimation uses lazy API pricing lookup for accurate per-model estimates.
Tests
npm test
Requirements
- Node.js >= 18.0.0
@polyweave/core(peer)@polyweave/errors(peer)
License
MIT
Dependencies
Development Dependencies
| ID | Version |
|---|---|
| @rigor/core | * |
Peer Dependencies
| ID | Version |
|---|---|
| @polyweave/core | * |
| @polyweave/costs | * |
| @polyweave/errors | * |
Keywords
polyweave
openrouter
llm
ai
adapter