@ottervoice/provider-openrouter
Documentation / @ottervoice/provider-openrouter
@ottervoice/provider-openrouter
Section titled “@ottervoice/provider-openrouter”OpenRouter providers for OtterVoice: text LLM, audio LLM, speech-to-text, and text-to-speech through OpenAI-compatible APIs.
Install
Section titled “Install”npm install @ottervoice/core @ottervoice/provider-openrouterBrowser / app (recommended)
Section titled “Browser / app (recommended)”import { createOpenRouterGatewayVoiceTurn } from '@ottervoice/provider-openrouter';
const voice = createOpenRouterGatewayVoiceTurn({ baseUrl: '/api/voice/asr-llm-tts', prepareAudio,});Pair this with server-side createOpenRouterGateway(). The server owns the
model, system prompt, voice, temperature, token ceiling, reasoning policy,
authorization, and budget. The browser sends only user content and transport
data.
import { createOpenRouterGateway } from '@ottervoice/provider-openrouter';
const handleVoice = createOpenRouterGateway({ apiKey: process.env.OPENROUTER_API_KEY, policy: { asr: { model: 'qwen/qwen3-asr-flash-2026-02-10' }, llm: { model: 'openai/gpt-4o-mini', systemPrompt: process.env.OTTERVOICE_SYSTEM_PROMPT ?? 'Be concise.', maxTokens: 256, }, tts: { model: 'minimax/speech-2.8-turbo', voice: 'alloy', responseFormat: 'mp3', }, }, authorize: async ({ request, profile }) => validateUserConversationAndProfile(request, profile),});Mount handleVoice at /api/voice/*. The composite
asr-llm-tts/chat/completions route accepts one audio turn, runs all three
stages on the server, and returns text plus sentence-sized MP3 segments over
one SSE response. Apps use this route or the native audio-llm route through
the same AudioLLMProvider contract. The standalone asr route remains
available only for optional captions; there are no standalone client LLM/TTS
profiles.
Direct createOpenRouterLLM() and createOpenRouterTTS() factories remain as
trusted-server building blocks for composite audio-turn implementations. Do not return a broad OpenRouter bearer token to a
browser: hiding a long-lived key is insufficient if the client can still select
models or generation parameters.
License
Section titled “License”MIT
Interfaces
Section titled “Interfaces”ChatBody
Section titled “ChatBody”Defined in: provider-openrouter/src/chat.ts:7
OpenAI-compatible chat-completions request body fields used by the adapter.
Properties
Section titled “Properties”ChatCompletion
Section titled “ChatCompletion”Defined in: provider-openrouter/src/chat.ts:104
Minimal chat-completion payload accepted by the text extraction helpers.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
choices? |
{ delta?: { content?: string; }; message?: { content?: string; }; }[] |
Completion choices containing either a final message or streamed delta. | provider-openrouter/src/chat.ts:106 |
usage? |
RawUsage |
Optional OpenAI-compatible token accounting. | provider-openrouter/src/chat.ts:108 |
HeaderOptions
Section titled “HeaderOptions”Defined in: provider-openrouter/src/chat.ts:57
Optional OpenRouter attribution and header overrides.
Extended by
Section titled “Extended by”Properties
Section titled “Properties”OpenRouterASROptions
Section titled “OpenRouterASROptions”Defined in: provider-openrouter/src/audio.ts:26
Options for direct OpenRouter HTTP transcription in trusted server/CLI
runtimes. Browser/app integrations should use OpenRouterGatewayASROptions.
Extends
Section titled “Extends”Properties
Section titled “Properties”| Property | Type | Description | Overrides | Inherited from | Defined in |
|---|---|---|---|---|---|
apiKey? |
string |
A long-lived key (server-side only — never ship to clients). | - | CredentialOptions.apiKey |
provider-utils/dist/credential.d.ts:37 |
baseUrl? |
string |
API root; defaults to OpenRouter’s chat-compatible base URL. | - | - | provider-openrouter/src/audio.ts:44 |
emptyPartialBackoffMs? |
number |
Delay the next rolling request after an empty provisional transcript. Defaults to the greater of 3x partialIntervalMs and 3 seconds. |
- | - | provider-openrouter/src/audio.ts:40 |
fetch? |
FetchLike |
Custom fetch implementation (tests / React Native polyfills). |
- | CredentialOptions.fetch |
provider-utils/dist/credential.d.ts:50 |
format? |
"opus" | "webm" | "wav" | "mp3" |
Browser MediaRecorder defaults to WebM. | - | - | provider-openrouter/src/audio.ts:30 |
headers? |
Record<string, string> |
Extra headers merged last (override defaults carefully). | - | HeaderOptions.headers |
provider-openrouter/src/chat.ts:63 |
language? |
string |
BCP-47 language hint sent to the transcription API when supported. Keep server-owned in standard mode. | - | - | provider-openrouter/src/audio.ts:42 |
model |
string |
OpenRouter / OpenAI-compatible transcription model id. Keep server-owned. | - | - | provider-openrouter/src/audio.ts:28 |
now? |
() => number |
Test hook for partial-result scheduling. | CredentialOptions.now |
- | provider-openrouter/src/audio.ts:48 |
partialIntervalMs? |
number |
Re-transcribe the accumulated live PCM at this interval to provide best-effort partial results before the turn ends. Omit for batch-only ASR. | - | - | provider-openrouter/src/audio.ts:35 |
referer? |
string |
Sent as HTTP-Referer for OpenRouter rankings / allowlists. |
- | HeaderOptions.referer |
provider-openrouter/src/chat.ts:59 |
requestStage? |
"gateway" | "provider" |
Classify HTTP failures as gateway/provider errors. Defaults from whether baseUrl is customized. |
- | - | provider-openrouter/src/audio.ts:46 |
serverManaged? |
boolean |
Omit provider policy fields because a trusted gateway reconstructs the request. | - | - | provider-openrouter/src/audio.ts:50 |
title? |
string |
Sent as X-Title (app name shown on OpenRouter). |
- | HeaderOptions.title |
provider-openrouter/src/chat.ts:61 |
tokenBrokerCredentials? |
RequestCredentials |
Browser credential mode for the broker request. Use include for a cross-origin cookie session. |
- | CredentialOptions.tokenBrokerCredentials |
provider-utils/dist/credential.d.ts:48 |
tokenBrokerHeaders? |
Readonly<Record<string, string>> |
Application-authentication headers sent only to the token broker, such as a short-lived user session bearer token. Use browser-compatible characters. | - | CredentialOptions.tokenBrokerHeaders |
provider-utils/dist/credential.d.ts:44 |
tokenBrokerSessionId? |
string |
Application voice-session id sent to the broker for ownership checks, audit, and quotas. | - | CredentialOptions.tokenBrokerSessionId |
provider-utils/dist/credential.d.ts:46 |
tokenBrokerUrl? |
string |
Endpoint that mints short-lived, least-privilege tokens; broad provider bearer tokens are not client-safe. | - | CredentialOptions.tokenBrokerUrl |
provider-utils/dist/credential.d.ts:39 |
OpenRouterAudioLLMOptions
Section titled “OpenRouterAudioLLMOptions”Defined in: provider-openrouter/src/audio-llm.ts:83
Options for the direct OpenRouter Audio LLM adapter in trusted server/CLI
runtimes. Browser/app integrations should use
OpenRouterGatewayAudioLLMOptions.
Extends
Section titled “Extends”Properties
Section titled “Properties”| Property | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|
apiKey? |
string |
A long-lived key (server-side only — never ship to clients). | CredentialOptions.apiKey |
provider-utils/dist/credential.d.ts:37 |
baseUrl? |
string |
API root; defaults to OpenRouter’s public …/api/v1. |
- | provider-openrouter/src/audio-llm.ts:89 |
defaultTemperature? |
number |
Default sampling temperature when the session does not override. Keep server-owned. | - | provider-openrouter/src/audio-llm.ts:96 |
fetch? |
FetchLike |
Custom fetch implementation (tests / React Native polyfills). |
CredentialOptions.fetch |
provider-utils/dist/credential.d.ts:50 |
headers? |
Record<string, string> |
Extra headers merged last (override defaults carefully). | HeaderOptions.headers |
provider-openrouter/src/chat.ts:63 |
model |
string |
Audio-capable chat model id. Keep server-owned in standard mode. | - | provider-openrouter/src/audio-llm.ts:85 |
now? |
() => number |
Clock override for deterministic expiry checks in tests. | CredentialOptions.now |
provider-utils/dist/credential.d.ts:52 |
prepareAudio? |
(audio, format) => Promise<PreparedAudioInput> |
OpenAI audio chat accepts WAV/MP3, while browsers normally record WebM. Supply a runtime-specific decoder when WebM/Opus input is possible. | - | provider-openrouter/src/audio-llm.ts:101 |
referer? |
string |
Sent as HTTP-Referer for OpenRouter rankings / allowlists. |
HeaderOptions.referer |
provider-openrouter/src/chat.ts:59 |
requestStage? |
"gateway" | "provider" |
Classify HTTP failures as direct provider or same-origin gateway errors. Defaults to gateway when baseUrl is customized, otherwise provider. |
- | provider-openrouter/src/audio-llm.ts:94 |
requireDoneSentinel? |
boolean |
Require the SSE response to end with an explicit [DONE] sentinel. Disabled by default for compatibility with gateways that close a complete stream cleanly. |
- | provider-openrouter/src/audio-llm.ts:109 |
serverManaged? |
boolean |
Omit model, system prompt, voice, temperature, and token limits because a trusted gateway reconstructs them. Prefer createOpenRouterGatewayAudioLLM. |
- | provider-openrouter/src/audio-llm.ts:114 |
title? |
string |
Sent as X-Title (app name shown on OpenRouter). |
HeaderOptions.title |
provider-openrouter/src/chat.ts:61 |
tokenBrokerCredentials? |
RequestCredentials |
Browser credential mode for the broker request. Use include for a cross-origin cookie session. |
CredentialOptions.tokenBrokerCredentials |
provider-utils/dist/credential.d.ts:48 |
tokenBrokerHeaders? |
Readonly<Record<string, string>> |
Application-authentication headers sent only to the token broker, such as a short-lived user session bearer token. Use browser-compatible characters. | CredentialOptions.tokenBrokerHeaders |
provider-utils/dist/credential.d.ts:44 |
tokenBrokerSessionId? |
string |
Application voice-session id sent to the broker for ownership checks, audit, and quotas. | CredentialOptions.tokenBrokerSessionId |
provider-utils/dist/credential.d.ts:46 |
tokenBrokerUrl? |
string |
Endpoint that mints short-lived, least-privilege tokens; broad provider bearer tokens are not client-safe. | CredentialOptions.tokenBrokerUrl |
provider-utils/dist/credential.d.ts:39 |
voice? |
| "alloy" | "ash" | "ballad" | "coral" | "echo" | "fable" | "nova" | "onyx" | "sage" | "shimmer" | "verse" |
Output voice when the model returns spoken audio. Keep server-owned. | - | provider-openrouter/src/audio-llm.ts:87 |
OpenRouterGatewayASRPolicy
Section titled “OpenRouterGatewayASRPolicy”Defined in: provider-openrouter/src/gateway-server.ts:20
Locked server policy for speech recognition requests.
Properties
Section titled “Properties”OpenRouterGatewayAudioLLMOptions
Section titled “OpenRouterGatewayAudioLLMOptions”Defined in: provider-openrouter/src/index.ts:170
Client-safe Audio LLM gateway options. Model, prompt, voice, and generation limits stay on the server.
Extends
Section titled “Extends”Properties
Section titled “Properties”| Property | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|
baseUrl |
string |
Profile-specific application base URL, such as /api/voice/llm. |
OpenRouterGatewayClientOptions.baseUrl |
provider-openrouter/src/index.ts:154 |
fetch? |
FetchLike |
Custom fetch implementation, commonly Expo’s fetch adapter. | OpenRouterGatewayClientOptions.fetch |
provider-openrouter/src/index.ts:158 |
headers? |
Record<string, string> |
Application-gateway headers, for example a short-lived session token. | OpenRouterGatewayClientOptions.headers |
provider-openrouter/src/index.ts:156 |
prepareAudio? |
(audio, format) => Promise<PreparedAudioInput> |
Runtime conversion from browser/native capture to WAV or MP3. | - | provider-openrouter/src/index.ts:172 |
requireDoneSentinel? |
boolean |
Require the server SSE response to end with [DONE]. |
- | provider-openrouter/src/index.ts:174 |
OpenRouterGatewayAudioLLMPolicy
Section titled “OpenRouterGatewayAudioLLMPolicy”Defined in: provider-openrouter/src/gateway-server.ts:81
Locked server policy for native Audio LLM requests.
Properties
Section titled “Properties”OpenRouterGatewayAuthorizationContext
Section titled “OpenRouterGatewayAuthorizationContext”Defined in: provider-openrouter/src/gateway-server.ts:110
Context passed to the application-owned gateway authorization hook.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
profile |
OpenRouterGatewayProfile |
Server profile selected by the explicit route. | provider-openrouter/src/gateway-server.ts:116 |
request |
Request |
Original application request. | provider-openrouter/src/gateway-server.ts:112 |
url |
URL |
Parsed request URL. | provider-openrouter/src/gateway-server.ts:114 |
OpenRouterGatewayClientOptions
Section titled “OpenRouterGatewayClientOptions”Defined in: provider-openrouter/src/index.ts:152
Shared browser/app options for a server-managed OpenRouter gateway profile.
Extended by
Section titled “Extended by”Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
baseUrl |
string |
Profile-specific application base URL, such as /api/voice/llm. |
provider-openrouter/src/index.ts:154 |
fetch? |
FetchLike |
Custom fetch implementation, commonly Expo’s fetch adapter. | provider-openrouter/src/index.ts:158 |
headers? |
Record<string, string> |
Application-gateway headers, for example a short-lived session token. | provider-openrouter/src/index.ts:156 |
OpenRouterGatewayLLMPolicy
Section titled “OpenRouterGatewayLLMPolicy”Defined in: provider-openrouter/src/gateway-server.ts:28
Locked server policy for text LLM requests.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
maxTokens |
number |
Hard server-selected output-token ceiling. | provider-openrouter/src/gateway-server.ts:36 |
model |
string |
Provider model id. Never read this value from an untrusted client. | provider-openrouter/src/gateway-server.ts:30 |
provider? |
OpenRouterGatewayProviderRoutingPolicy |
Server-selected OpenRouter endpoint routing preferences. See OpenRouterGatewayProviderRoutingPolicy. | provider-openrouter/src/gateway-server.ts:45 |
reasoningEnabled? |
boolean |
Server-selected OpenRouter reasoning behavior. | provider-openrouter/src/gateway-server.ts:38 |
responseFormat? |
"text" | "json" |
Server-selected response shape. Defaults to text. | provider-openrouter/src/gateway-server.ts:40 |
systemPrompt |
string |
Trusted system instruction injected before client conversation history. | provider-openrouter/src/gateway-server.ts:32 |
temperature? |
number |
Server-selected sampling temperature. | provider-openrouter/src/gateway-server.ts:34 |
OpenRouterGatewayOptions
Section titled “OpenRouterGatewayOptions”Defined in: provider-openrouter/src/gateway-server.ts:129
Options for createOpenRouterGateway.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
apiKey? |
string |
Long-lived OpenRouter key read only in the trusted server runtime. | provider-openrouter/src/gateway-server.ts:131 |
authorize |
(context) => OpenRouterGatewayAuthorizationResult |
Application authorization and session-ownership check. This hook is mandatory so production integrations cannot accidentally omit the trust boundary. | provider-openrouter/src/gateway-server.ts:138 |
fetch? |
FetchLike |
Server-side fetch override for tests or custom runtimes. | provider-openrouter/src/gateway-server.ts:160 |
gatewayPrefix? |
string |
Browser-facing prefix. Defaults to /api/voice. |
provider-openrouter/src/gateway-server.ts:142 |
maxMessages? |
number |
Maximum conversation messages accepted from a client. Defaults to 32. | provider-openrouter/src/gateway-server.ts:148 |
maxRequestBodyBytes? |
number |
Maximum encoded request size. Defaults to 6 MiB. | provider-openrouter/src/gateway-server.ts:146 |
maxTextCharacters? |
number |
Maximum cumulative client-controlled text characters. Defaults to 32,000. | provider-openrouter/src/gateway-server.ts:150 |
policy |
OpenRouterGatewayPolicy |
Locked model, prompt, voice, and generation policy. | provider-openrouter/src/gateway-server.ts:133 |
referer? |
string |
Server-owned HTTP Referer sent upstream. | provider-openrouter/src/gateway-server.ts:156 |
title? |
string |
Server-owned application title sent upstream. | provider-openrouter/src/gateway-server.ts:158 |
ttsCacheEntries? |
number |
Maximum in-memory TTS cache entries. Defaults to zero (disabled). | provider-openrouter/src/gateway-server.ts:154 |
upstreamBaseUrl? |
string |
Provider API root. Defaults to OpenRouter’s public v1 endpoint. | provider-openrouter/src/gateway-server.ts:144 |
upstreamTimeoutMs? |
number |
Total upstream response timeout in milliseconds. Defaults to 60 seconds. | provider-openrouter/src/gateway-server.ts:152 |
OpenRouterGatewayPolicy
Section titled “OpenRouterGatewayPolicy”Defined in: provider-openrouter/src/gateway-server.ts:98
Server-owned provider policy. Omit a profile to disable its route entirely. The gateway never accepts these values from a browser or app request body.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
asr? |
OpenRouterGatewayASRPolicy |
Policy for standalone ASR and the ASR stage of the composite voice route. | provider-openrouter/src/gateway-server.ts:100 |
audioLlm? |
OpenRouterGatewayAudioLLMPolicy |
Policy for /audio-llm/chat/completions. |
provider-openrouter/src/gateway-server.ts:106 |
llm? |
OpenRouterGatewayLLMPolicy |
Policy for the LLM stage of the composite voice route. | provider-openrouter/src/gateway-server.ts:102 |
tts? |
OpenRouterGatewayTTSPolicy |
Policy for the TTS stage of the composite voice route. | provider-openrouter/src/gateway-server.ts:104 |
OpenRouterGatewayProviderRoutingPolicy
Section titled “OpenRouterGatewayProviderRoutingPolicy”Defined in: provider-openrouter/src/gateway-server.ts:49
Locked OpenRouter endpoint-routing preferences for text LLM requests.
Properties
Section titled “Properties”OpenRouterGatewayTTSPolicy
Section titled “OpenRouterGatewayTTSPolicy”Defined in: provider-openrouter/src/gateway-server.ts:69
Locked server policy for speech synthesis requests.
Properties
Section titled “Properties”OpenRouterGatewayVoiceTurnOptions
Section titled “OpenRouterGatewayVoiceTurnOptions”Defined in: provider-openrouter/src/voice-turn.ts:24
Client options for the server-orchestrated ASR → LLM → TTS voice-turn route.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
baseUrl |
string |
Application route prefix, such as /api/voice/asr-llm-tts. |
provider-openrouter/src/voice-turn.ts:26 |
fetch? |
FetchLike |
Custom Fetch implementation for browser, native, or test runtimes. | provider-openrouter/src/voice-turn.ts:30 |
headers? |
Record<string, string> |
Application-gateway headers, for example a short-lived session token. | provider-openrouter/src/voice-turn.ts:28 |
prepareAudio? |
(audio, format) => Promise<PreparedAudioInput> |
Runtime conversion from browser/native capture to WAV or MP3. | provider-openrouter/src/voice-turn.ts:32 |
requireDoneSentinel? |
boolean |
Require the composite SSE response to end with [DONE]. |
provider-openrouter/src/voice-turn.ts:37 |
OpenRouterOptions
Section titled “OpenRouterOptions”Defined in: provider-openrouter/src/index.ts:43
Options for createOpenRouterLLM. Use this direct provider only as a trusted-server building block for a composite audio-turn backend.
Extends
Section titled “Extends”Properties
Section titled “Properties”| Property | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|
apiKey? |
string |
A long-lived key (server-side only — never ship to clients). | CredentialOptions.apiKey |
provider-utils/dist/credential.d.ts:37 |
baseUrl? |
string |
API base, default https://openrouter.ai/api/v1. |
- | provider-openrouter/src/index.ts:47 |
defaultTemperature? |
number |
Applied when a request does not specify its own temperature. | - | provider-openrouter/src/index.ts:51 |
fetch? |
FetchLike |
Custom fetch implementation (tests / React Native polyfills). |
CredentialOptions.fetch |
provider-utils/dist/credential.d.ts:50 |
headers? |
Record<string, string> |
Extra headers merged last (override defaults carefully). | HeaderOptions.headers |
provider-openrouter/src/chat.ts:63 |
model |
string |
OpenRouter model id, e.g. openai/gpt-4o-mini. |
- | provider-openrouter/src/index.ts:45 |
now? |
() => number |
Clock override for deterministic expiry checks in tests. | CredentialOptions.now |
provider-utils/dist/credential.d.ts:52 |
reasoningEnabled? |
boolean |
Explicitly enable/disable reasoning tokens on compatible models. | - | provider-openrouter/src/index.ts:53 |
referer? |
string |
Sent as HTTP-Referer for OpenRouter rankings / allowlists. |
HeaderOptions.referer |
provider-openrouter/src/chat.ts:59 |
requestStage? |
"gateway" | "provider" |
Classify HTTP failures as gateway/provider errors. Defaults from whether baseUrl is customized. |
- | provider-openrouter/src/index.ts:49 |
title? |
string |
Sent as X-Title (app name shown on OpenRouter). |
HeaderOptions.title |
provider-openrouter/src/chat.ts:61 |
tokenBrokerCredentials? |
RequestCredentials |
Browser credential mode for the broker request. Use include for a cross-origin cookie session. |
CredentialOptions.tokenBrokerCredentials |
provider-utils/dist/credential.d.ts:48 |
tokenBrokerHeaders? |
Readonly<Record<string, string>> |
Application-authentication headers sent only to the token broker, such as a short-lived user session bearer token. Use browser-compatible characters. | CredentialOptions.tokenBrokerHeaders |
provider-utils/dist/credential.d.ts:44 |
tokenBrokerSessionId? |
string |
Application voice-session id sent to the broker for ownership checks, audit, and quotas. | CredentialOptions.tokenBrokerSessionId |
provider-utils/dist/credential.d.ts:46 |
tokenBrokerUrl? |
string |
Endpoint that mints short-lived, least-privilege tokens; broad provider bearer tokens are not client-safe. | CredentialOptions.tokenBrokerUrl |
provider-utils/dist/credential.d.ts:39 |
OpenRouterTTSOptions
Section titled “OpenRouterTTSOptions”Defined in: provider-openrouter/src/audio.ts:57
Options for direct OpenRouter HTTP speech synthesis in trusted server/CLI runtimes. Use it for the TTS stage of a composite audio-turn backend.
Extends
Section titled “Extends”Properties
Section titled “Properties”| Property | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|
apiKey? |
string |
A long-lived key (server-side only — never ship to clients). | CredentialOptions.apiKey |
provider-utils/dist/credential.d.ts:37 |
baseUrl? |
string |
API root; defaults to OpenRouter’s chat-compatible base URL. | - | provider-openrouter/src/audio.ts:63 |
fetch? |
FetchLike |
Custom fetch implementation (tests / React Native polyfills). |
CredentialOptions.fetch |
provider-utils/dist/credential.d.ts:50 |
headers? |
Record<string, string> |
Extra headers merged last (override defaults carefully). | HeaderOptions.headers |
provider-openrouter/src/chat.ts:63 |
model |
string |
OpenRouter / OpenAI-compatible TTS model id. Keep server-owned. | - | provider-openrouter/src/audio.ts:59 |
now? |
() => number |
Clock override for deterministic expiry checks in tests. | CredentialOptions.now |
provider-utils/dist/credential.d.ts:52 |
referer? |
string |
Sent as HTTP-Referer for OpenRouter rankings / allowlists. |
HeaderOptions.referer |
provider-openrouter/src/chat.ts:59 |
requestStage? |
"gateway" | "provider" |
Classify HTTP failures as gateway/provider errors. Defaults from whether baseUrl is customized. |
- | provider-openrouter/src/audio.ts:65 |
speed? |
number |
Speaking rate multiplier when the upstream model supports it. Keep server-owned. | - | provider-openrouter/src/audio.ts:67 |
title? |
string |
Sent as X-Title (app name shown on OpenRouter). |
HeaderOptions.title |
provider-openrouter/src/chat.ts:61 |
tokenBrokerCredentials? |
RequestCredentials |
Browser credential mode for the broker request. Use include for a cross-origin cookie session. |
CredentialOptions.tokenBrokerCredentials |
provider-utils/dist/credential.d.ts:48 |
tokenBrokerHeaders? |
Readonly<Record<string, string>> |
Application-authentication headers sent only to the token broker, such as a short-lived user session bearer token. Use browser-compatible characters. | CredentialOptions.tokenBrokerHeaders |
provider-utils/dist/credential.d.ts:44 |
tokenBrokerSessionId? |
string |
Application voice-session id sent to the broker for ownership checks, audit, and quotas. | CredentialOptions.tokenBrokerSessionId |
provider-utils/dist/credential.d.ts:46 |
tokenBrokerUrl? |
string |
Endpoint that mints short-lived, least-privilege tokens; broad provider bearer tokens are not client-safe. | CredentialOptions.tokenBrokerUrl |
provider-utils/dist/credential.d.ts:39 |
voice |
string |
Voice name accepted by the selected model. Keep server-owned. | - | provider-openrouter/src/audio.ts:61 |
PreparedAudioInput
Section titled “PreparedAudioInput”Defined in: provider-openrouter/src/audio-llm.ts:71
WAV/MP3 bytes ready for OpenAI-compatible audio chat.
Properties
Section titled “Properties”RawUsage
Section titled “RawUsage”Defined in: provider-openrouter/src/chat.ts:84
OpenAI-compatible token counters accepted by mapUsage.
Properties
Section titled “Properties”Type Aliases
Section titled “Type Aliases”OpenRouterGatewayASROptions
Section titled “OpenRouterGatewayASROptions”type OpenRouterGatewayASROptions = OpenRouterGatewayClientOptions & Pick<OpenRouterASROptions, "format" | "partialIntervalMs" | "emptyPartialBackoffMs" | "now">;Defined in: provider-openrouter/src/index.ts:164
Client-safe ASR gateway options. Provider model and language policy stay on the server.
OpenRouterGatewayAuthorizationResult
Section titled “OpenRouterGatewayAuthorizationResult”type OpenRouterGatewayAuthorizationResult = boolean | Response | Promise<boolean | Response>;Defined in: provider-openrouter/src/gateway-server.ts:123
Authorization result for an OpenRouter policy gateway.
Return true to continue, false to reject, or a custom response.
OpenRouterGatewayProfile
Section titled “OpenRouterGatewayProfile”type OpenRouterGatewayProfile = "asr" | "audio_llm" | "asr_llm_tts";Defined in: provider-openrouter/src/gateway-server.ts:14
Server-owned gateway profile selected by an explicit application route.
Variables
Section titled “Variables”DEFAULT_BASE_URL
Section titled “DEFAULT_BASE_URL”const DEFAULT_BASE_URL: "https://openrouter.ai/api/v1" = 'https://openrouter.ai/api/v1';Defined in: provider-openrouter/src/chat.ts:4
Default OpenRouter OpenAI-compatible API root.
Functions
Section titled “Functions”buildChatBody()
Section titled “buildChatBody()”function buildChatBody( model, input, defaults?, openRouter?): ChatBody;Defined in: provider-openrouter/src/chat.ts:32
Build the OpenAI-compatible chat-completions request body.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
model |
string |
OpenRouter model id. |
input |
LLMGenerateInput |
Core LLMGenerateInput messages and knobs. |
defaults |
{ stream?: boolean; temperature?: number; } |
Adapter-level temperature / stream defaults. |
defaults.stream? |
boolean |
- |
defaults.temperature? |
number |
- |
openRouter |
{ reasoningEnabled?: boolean; } |
OpenRouter-specific extras (e.g. reasoning). |
openRouter.reasoningEnabled? |
boolean |
- |
Returns
Section titled “Returns”buildHeaders()
Section titled “buildHeaders()”function buildHeaders(token, options): Record<string, string>;Defined in: provider-openrouter/src/chat.ts:72
Assemble request headers, including OpenRouter’s optional attribution.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
token |
string |
Bearer token from apiKey or token broker. |
options |
HeaderOptions |
Attribution and header overrides. |
Returns
Section titled “Returns”Record<string, string>
bytesToBase64()
Section titled “bytesToBase64()”function bytesToBase64(bytes): string;Defined in: provider-openrouter/src/audio.ts:161
Browser- and Node-safe base64 without relying on Buffer.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
bytes |
Uint8Array |
Returns
Section titled “Returns”string
createOpenRouterASR()
Section titled “createOpenRouterASR()”function createOpenRouterASR(options): ASRProvider;Defined in: provider-openrouter/src/audio.ts:187
Direct transcription through OpenRouter’s /audio/transcriptions endpoint
for trusted server/CLI runtimes.
The default remains one request at turn end. Setting partialIntervalMs
adds rolling, best-effort snapshots for low-latency partial text while the
final request still covers the complete turn.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
OpenRouterASROptions |
Model, credentials, and optional rolling-partial interval. |
Returns
Section titled “Returns”An ASRProvider for a session’s caption/transcription provider slot.
createOpenRouterAudioLLM()
Section titled “createOpenRouterAudioLLM()”function createOpenRouterAudioLLM(options): AudioLLMProvider;Defined in: provider-openrouter/src/audio-llm.ts:231
Direct OpenRouter native Audio LLM provider for trusted server/CLI runtimes. Use the gateway factory in browser/app integrations.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
OpenRouterAudioLLMOptions |
Model, voice, credentials, and optional WebM→WAV preparer. |
Returns
Section titled “Returns”An AudioLLMProvider for unified voice sessions.
createOpenRouterGateway()
Section titled “createOpenRouterGateway()”function createOpenRouterGateway(options): (request) => Promise<Response>;Defined in: provider-openrouter/src/gateway-server.ts:361
Create a server-side OpenRouter gateway that reconstructs every upstream request from a locked policy. Browser-supplied model, system/developer messages, voice, temperature, token limits, reasoning options, and unknown fields are never forwarded.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
OpenRouterGatewayOptions |
Server credentials, locked policy, authorization hook, and limits. |
Returns
Section titled “Returns”A Fetch-compatible request handler for standalone and composite profile routes.
(request) => Promise<Response>
createOpenRouterGatewayASR()
Section titled “createOpenRouterGatewayASR()”function createOpenRouterGatewayASR(options): ASRProvider;Defined in: provider-openrouter/src/index.ts:185
Create an ASR provider for a server-managed application gateway.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
OpenRouterGatewayASROptions |
Profile URL plus client-side capture/partial-result behavior. |
Returns
Section titled “Returns”An ASR provider that sends only audio input and no provider policy fields.
createOpenRouterGatewayAudioLLM()
Section titled “createOpenRouterGatewayAudioLLM()”function createOpenRouterGatewayAudioLLM(options): AudioLLMProvider;Defined in: provider-openrouter/src/index.ts:203
Create an Audio LLM provider for a server-managed application gateway.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
OpenRouterGatewayAudioLLMOptions |
Profile URL plus runtime audio conversion/stream validation. |
Returns
Section titled “Returns”An Audio LLM provider that sends audio/history without business policy fields.
createOpenRouterGatewayVoiceTurn()
Section titled “createOpenRouterGatewayVoiceTurn()”function createOpenRouterGatewayVoiceTurn(options): AudioLLMProvider;Defined in: provider-openrouter/src/voice-turn.ts:91
Create a client-safe voice-turn provider backed by one server-orchestrated ASR → LLM → MP3 TTS SSE request.
Use this for cascaded voice applications that should expose the same client lifecycle as a native audio model while keeping every vendor call and model policy on the server.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
OpenRouterGatewayVoiceTurnOptions |
Composite route, audio preparation, and transport options. |
Returns
Section titled “Returns”An AudioLLMProvider that also supplies the input transcript.
createOpenRouterLLM()
Section titled “createOpenRouterLLM()”function createOpenRouterLLM(options): LLMProvider;Defined in: provider-openrouter/src/index.ts:65
LLM provider backed by OpenRouter’s OpenAI-compatible HTTP API. A direct client credential is safe only when it is short-lived and tightly scoped; broad OpenRouter credentials require a policy-enforcing server gateway.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
OpenRouterOptions |
Model id plus CredentialOptions / header overrides. |
Returns
Section titled “Returns”createOpenRouterTTS()
Section titled “createOpenRouterTTS()”function createOpenRouterTTS(options): TTSProvider;Defined in: provider-openrouter/src/audio.ts:464
Direct OpenRouter TTS for trusted server/CLI runtimes through the
OpenAI-compatible /audio/speech endpoint.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
OpenRouterTTSOptions |
Model, voice, credentials, and optional speed. |
Returns
Section titled “Returns”A TTSProvider for trusted-server audio-turn composition.
extractDelta()
Section titled “extractDelta()”function extractDelta(json): string;Defined in: provider-openrouter/src/chat.ts:117
Extract the incremental text from a streamed chunk.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
json |
ChatCompletion |
Returns
Section titled “Returns”string
extractText()
Section titled “extractText()”function extractText(json): string;Defined in: provider-openrouter/src/chat.ts:112
Extract the assistant text from a non-streamed completion.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
json |
ChatCompletion |
Returns
Section titled “Returns”string
mapUsage()
Section titled “mapUsage()”function mapUsage(usage): | LLMUsage | undefined;Defined in: provider-openrouter/src/chat.ts:94
Map an OpenAI-style usage object to the core LLMUsage shape.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
usage |
| RawUsage | null | undefined |
Returns
Section titled “Returns”| LLMUsage
| undefined
pcm16ToWav()
Section titled “pcm16ToWav()”function pcm16ToWav(pcm, sampleRate?): ArrayBuffer;Defined in: provider-openrouter/src/audio-llm.ts:201
Wrap OpenAI’s 24 kHz mono PCM16 stream so browser audio elements can play it.
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
pcm |
Uint8Array |
undefined |
Interleaved little-endian PCM16 bytes. |
sampleRate |
number |
24_000 |
Sample rate in Hz (OpenAI audio chat defaults to 24_000). |
Returns
Section titled “Returns”ArrayBuffer
A standard WAV container buffer.