Polyweave

@polyweave/openrouter (1.0.4)

Published 2026-07-10 18:16:56 +00:00 by Dvorak

Installation

@polyweave:registry=https://hub.kl1.tenere.ai/api/packages/Polyweave/npm/
npm install @polyweave/openrouter@1.0.4
"@polyweave/openrouter": "1.0.4"

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
Details
npm
2026-07-10 18:16:56 +00:00
4
John Dvorak
SEE LICENSE IN LICENSE
21 KiB
Assets (1)
Versions (5) View all
1.0.9 2026-07-11
1.0.6 2026-07-11
1.0.5 2026-07-10
1.0.4 2026-07-10
1.0.3 2026-07-10