跳转到内容

@ottervoice/provider-openrouter

Documentation


Documentation / @ottervoice/provider-openrouter

OpenRouter providers for OtterVoice: text LLM, audio LLM, speech-to-text, and text-to-speech through OpenAI-compatible APIs.

Terminal window
npm install @ottervoice/core @ottervoice/provider-openrouter
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.

Documentation · GitHub

MIT

Defined in: provider-openrouter/src/chat.ts:7

OpenAI-compatible chat-completions request body fields used by the adapter.

Property Type Description Defined in
max_tokens? number Max completion tokens. provider-openrouter/src/chat.ts:15
messages { content: string; role: string; }[] Chat messages in OpenAI role/content shape. provider-openrouter/src/chat.ts:11
model string Model id on OpenRouter. provider-openrouter/src/chat.ts:9
reasoning? { enabled: boolean; } OpenRouter reasoning toggle when the model supports it. provider-openrouter/src/chat.ts:21
reasoning.enabled boolean - provider-openrouter/src/chat.ts:21
response_format? { type: "json_object"; } Force JSON-object responses when supported. provider-openrouter/src/chat.ts:19
response_format.type "json_object" - provider-openrouter/src/chat.ts:19
stream? boolean When true, request SSE streaming. provider-openrouter/src/chat.ts:17
temperature? number Sampling temperature. provider-openrouter/src/chat.ts:13

Defined in: provider-openrouter/src/chat.ts:104

Minimal chat-completion payload accepted by the text extraction helpers.

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

Defined in: provider-openrouter/src/chat.ts:57

Optional OpenRouter attribution and header overrides.

Property Type Description Defined in
headers? Record<string, string> Extra headers merged last (override defaults carefully). provider-openrouter/src/chat.ts:63
referer? string Sent as HTTP-Referer for OpenRouter rankings / allowlists. provider-openrouter/src/chat.ts:59
title? string Sent as X-Title (app name shown on OpenRouter). provider-openrouter/src/chat.ts:61

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.

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

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.

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

Defined in: provider-openrouter/src/gateway-server.ts:20

Locked server policy for speech recognition requests.

Property Type Description Defined in
language? string Optional fixed recognition language. Omit to let the provider detect it. provider-openrouter/src/gateway-server.ts:24
model string Provider model id. Never read this value from an untrusted client. provider-openrouter/src/gateway-server.ts:22

Defined in: provider-openrouter/src/index.ts:170

Client-safe Audio LLM gateway options. Model, prompt, voice, and generation limits stay on the server.

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

Defined in: provider-openrouter/src/gateway-server.ts:81

Locked server policy for native Audio LLM requests.

Property Type Description Defined in
maxTokens number Hard server-selected output-token ceiling. provider-openrouter/src/gateway-server.ts:91
model string Provider model id. Never read this value from an untrusted client. provider-openrouter/src/gateway-server.ts:83
systemPrompt string Trusted system instruction injected before client conversation history. provider-openrouter/src/gateway-server.ts:85
temperature? number Server-selected sampling temperature. provider-openrouter/src/gateway-server.ts:89
voice string Server-selected output voice. provider-openrouter/src/gateway-server.ts:87

Defined in: provider-openrouter/src/gateway-server.ts:110

Context passed to the application-owned gateway authorization hook.

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

Defined in: provider-openrouter/src/index.ts:152

Shared browser/app options for a server-managed OpenRouter gateway profile.

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

Defined in: provider-openrouter/src/gateway-server.ts:28

Locked server policy for text LLM requests.

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

Defined in: provider-openrouter/src/gateway-server.ts:129

Options for createOpenRouterGateway.

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

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.

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

Defined in: provider-openrouter/src/gateway-server.ts:49

Locked OpenRouter endpoint-routing preferences for text LLM requests.

Property Type Description Defined in
preferredMaxLatency? { p50?: number; p75?: number; p90?: number; p99?: number; } Preferred maximum time-to-first-token latency in seconds. Endpoints above these rolling percentile thresholds are deprioritized, not excluded. provider-openrouter/src/gateway-server.ts:56
preferredMaxLatency.p50? number Preferred maximum median latency in seconds. provider-openrouter/src/gateway-server.ts:58
preferredMaxLatency.p75? number Preferred maximum p75 latency in seconds. provider-openrouter/src/gateway-server.ts:60
preferredMaxLatency.p90? number Preferred maximum p90 latency in seconds. provider-openrouter/src/gateway-server.ts:62
preferredMaxLatency.p99? number Preferred maximum p99 latency in seconds. provider-openrouter/src/gateway-server.ts:64
sort? "price" | "throughput" | "latency" Attribute used to order eligible provider endpoints. provider-openrouter/src/gateway-server.ts:51

Defined in: provider-openrouter/src/gateway-server.ts:69

Locked server policy for speech synthesis requests.

Property Type Description Defined in
model string Provider model id. Never read this value from an untrusted client. provider-openrouter/src/gateway-server.ts:71
responseFormat? "mp3" | "pcm" Server-selected one-shot output encoding. Streaming requests force PCM. provider-openrouter/src/gateway-server.ts:77
speed? number Server-selected speaking-rate multiplier. provider-openrouter/src/gateway-server.ts:75
voice string Server-selected voice id. provider-openrouter/src/gateway-server.ts:73

Defined in: provider-openrouter/src/voice-turn.ts:24

Client options for the server-orchestrated ASR → LLM → TTS voice-turn route.

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

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.

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

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.

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

Defined in: provider-openrouter/src/audio-llm.ts:71

WAV/MP3 bytes ready for OpenAI-compatible audio chat.

Property Type Description Defined in
audio ArrayBuffer Encoded audio body. provider-openrouter/src/audio-llm.ts:73
format "wav" | "mp3" Container accepted by the audio chat API. provider-openrouter/src/audio-llm.ts:75

Defined in: provider-openrouter/src/chat.ts:84

OpenAI-compatible token counters accepted by mapUsage.

Property Type Description Defined in
completion_tokens? number Tokens generated by the completion. provider-openrouter/src/chat.ts:88
prompt_tokens? number Tokens consumed by prompts/messages. provider-openrouter/src/chat.ts:86
total_tokens? number Combined prompt and completion tokens. provider-openrouter/src/chat.ts:90
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.


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.


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.

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.

function buildChatBody(
model,
input,
defaults?,
openRouter?): ChatBody;

Defined in: provider-openrouter/src/chat.ts:32

Build the OpenAI-compatible chat-completions request body.

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 -

ChatBody


function buildHeaders(token, options): Record<string, string>;

Defined in: provider-openrouter/src/chat.ts:72

Assemble request headers, including OpenRouter’s optional attribution.

Parameter Type Description
token string Bearer token from apiKey or token broker.
options HeaderOptions Attribution and header overrides.

Record<string, string>


function bytesToBase64(bytes): string;

Defined in: provider-openrouter/src/audio.ts:161

Browser- and Node-safe base64 without relying on Buffer.

Parameter Type
bytes Uint8Array

string


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.

Parameter Type Description
options OpenRouterASROptions Model, credentials, and optional rolling-partial interval.

ASRProvider

An ASRProvider for a session’s caption/transcription provider slot.


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.

Parameter Type Description
options OpenRouterAudioLLMOptions Model, voice, credentials, and optional WebM→WAV preparer.

AudioLLMProvider

An AudioLLMProvider for unified voice sessions.


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.

Parameter Type Description
options OpenRouterGatewayOptions Server credentials, locked policy, authorization hook, and limits.

A Fetch-compatible request handler for standalone and composite profile routes.

(request) => Promise<Response>


function createOpenRouterGatewayASR(options): ASRProvider;

Defined in: provider-openrouter/src/index.ts:185

Create an ASR provider for a server-managed application gateway.

Parameter Type Description
options OpenRouterGatewayASROptions Profile URL plus client-side capture/partial-result behavior.

ASRProvider

An ASR provider that sends only audio input and no provider policy fields.


function createOpenRouterGatewayAudioLLM(options): AudioLLMProvider;

Defined in: provider-openrouter/src/index.ts:203

Create an Audio LLM provider for a server-managed application gateway.

Parameter Type Description
options OpenRouterGatewayAudioLLMOptions Profile URL plus runtime audio conversion/stream validation.

AudioLLMProvider

An Audio LLM provider that sends audio/history without business policy fields.


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.

Parameter Type Description
options OpenRouterGatewayVoiceTurnOptions Composite route, audio preparation, and transport options.

AudioLLMProvider

An AudioLLMProvider that also supplies the input transcript.


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.

Parameter Type Description
options OpenRouterOptions Model id plus CredentialOptions / header overrides.

LLMProvider


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.

Parameter Type Description
options OpenRouterTTSOptions Model, voice, credentials, and optional speed.

TTSProvider

A TTSProvider for trusted-server audio-turn composition.


function extractDelta(json): string;

Defined in: provider-openrouter/src/chat.ts:117

Extract the incremental text from a streamed chunk.

Parameter Type
json ChatCompletion

string


function extractText(json): string;

Defined in: provider-openrouter/src/chat.ts:112

Extract the assistant text from a non-streamed completion.

Parameter Type
json ChatCompletion

string


function mapUsage(usage):
| LLMUsage
| undefined;

Defined in: provider-openrouter/src/chat.ts:94

Map an OpenAI-style usage object to the core LLMUsage shape.

Parameter Type
usage | RawUsage | null | undefined

| LLMUsage | undefined


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.

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).

ArrayBuffer

A standard WAV container buffer.