Skip to content

OpenRouterLanguageModel

The OpenRouterLanguageModel module provides the OpenRouter implementation of Effect AI's LanguageModel service. It translates provider-neutral prompts, tools, files, structured output requests, reasoning metadata, cache-control hints, and provider options into OpenRouter chat completion requests, records GenAI telemetry around those calls, and converts normal or streaming results back into Effect AI response content and metadata.

7 exports Added in v4.0.0 Source

Configuration

Provides config overrides for OpenRouter language model operations.

When to use

Use to apply OpenRouter request configuration to one effect without changing the model's default configuration.

Details

The overrides are merged with any existing Config service for the duration of the supplied effect. Fields in overrides take precedence over existing config, and the helper supports both pipe form and withConfigOverride(effect, overrides).

See

  • Config for available OpenRouter request configuration fields

Signature

declare const withConfigOverride: {
(overrides: {
readonly cache_control?: {
readonly ttl?: "5m" | "1h";
readonly type: "ephemeral";
};
readonly debug?: {
readonly echo_upstream_body?: boolean;
};
readonly frequency_penalty?: number | null;
readonly image_config?: ReadonlySide<{}, "Encoded">;
readonly logit_bias?: {
[key: string]: number;
} | null;
readonly logprobs?: boolean | null;
readonly max_completion_tokens?: number | null;
readonly max_tokens?: number | null;
readonly metadata?: ReadonlySide<{}, "Encoded">;
readonly min_p?: number | null;
readonly modalities?: readonly Array<"text" | "audio" | "image">;
readonly model?: string;
readonly models?: readonly Array<string>;
readonly parallel_tool_calls?: boolean | null;
readonly plugins?: readonly Array<{
readonly allowed_models?: readonly Array<string>;
readonly cost_quality_tradeoff?: number;
readonly enabled?: boolean;
readonly id: "auto-router";
readonly pin_model?: boolean;
} | {
readonly allowed_models?: readonly Array<string>;
readonly cost_quality_tradeoff?: number;
readonly enabled?: boolean;
readonly id: "auto-beta-router";
} | ReadonlySide<{
readonly id: Literal<"moderation">;
}, "Encoded"> | {
readonly enabled?: boolean;
readonly engine?: "native" | "exa" | "firecrawl" | "parallel" | "perplexity";
readonly exclude_domains?: readonly Array<string>;
readonly id: "web";
readonly include_domains?: readonly Array<string>;
readonly max_results?: number;
readonly max_uses?: number;
readonly search_prompt?: string;
readonly user_location?: {
[key: string]: Json;
readonly city?: string | null;
readonly country?: string | null;
readonly region?: string | null;
readonly timezone?: string | null;
readonly type: "approximate";
};
} | {
readonly allowed_domains?: readonly Array<string>;
readonly blocked_domains?: readonly Array<string>;
readonly id: "web-fetch";
readonly max_content_tokens?: number;
readonly max_uses?: number;
} | {
readonly enabled?: boolean;
readonly id: "file-parser";
readonly pdf?: {
readonly engine?: "native" | "mistral-ocr" | "cloudflare-ai" | "pdf-text";
};
} | {
readonly enabled?: boolean;
readonly id: "response-healing";
} | {
readonly enabled?: boolean;
readonly engine?: "middle-out";
readonly id: "context-compression";
} | {
readonly enabled?: boolean;
readonly id: "pareto-router";
readonly max_price?: number;
readonly min_coding_score?: number;
readonly price_source?: "prompt" | "weighted_avg";
} | {
readonly analysis_models?: readonly Array<string>;
readonly enabled?: boolean;
readonly id: "fusion";
readonly max_tool_calls?: number;
readonly model?: string;
readonly preset?: "general-high" | "general-budget" | "general-fast";
readonly tools?: readonly Array<{
readonly parameters?: ReadonlySide<..., ...>;
readonly type: string;
}>;
}>;
readonly prediction?: {
[key: string]: Json;
readonly content: string | readonly Array<ReadonlySide<{
readonly text: String;
readonly type: Literal<"text">;
}, "Encoded">>;
readonly type: "content";
} | null;
readonly presence_penalty?: number | null;
readonly prompt_cache_key?: string | null;
readonly prompt_cache_options?: {
[key: string]: Json;
readonly mode: "explicit";
readonly ttl?: string | null;
} | null;
readonly provider?: {
readonly allow_fallbacks?: boolean | null;
readonly data_collection?: "deny" | "allow" | null;
readonly enforce_distillable_text?: boolean | null;
readonly ignore?: readonly Array<string> | null;
readonly max_price?: {
readonly audio?: string;
readonly completion?: string;
readonly image?: string;
readonly prompt?: string;
readonly request?: string;
};
readonly only?: readonly Array<string> | null;
readonly order?: readonly Array<string> | null;
readonly preferred_max_latency?: number | {
readonly p50?: number | null;
readonly p75?: number | null;
readonly p90?: number | null;
readonly p99?: number | null;
} | null;
readonly preferred_min_throughput?: number | {
readonly p50?: number | null;
readonly p75?: number | null;
readonly p90?: number | null;
readonly p99?: number | null;
} | null;
readonly quantizations?: readonly Array<"unknown" | "int4" | "int8" | "fp4" | "fp6" | "fp8" | "fp16" | "bf16" | "fp32"> | null;
readonly require_parameters?: boolean | null;
readonly sort?: "price" | "throughput" | "latency" | "exacto" | {
readonly by?: "price" | "throughput" | "latency" | "exacto" | null;
readonly partition?: "model" | "none" | null;
} | null;
readonly zdr?: boolean | null;
} | null;
readonly reasoning?: {
readonly effort?: "low" | "high" | "none" | "max" | "xhigh" | "medium" | "minimal" | null;
readonly summary?: "auto" | "concise" | "detailed" | null;
};
readonly reasoning_effort?: "low" | "high" | "none" | "max" | "xhigh" | "medium" | "minimal" | null;
readonly repetition_penalty?: number | null;
readonly route?: "sort" | "fallback" | null;
readonly seed?: number | null;
readonly service_tier?: "auto" | "default" | "flex" | "priority" | "scale" | null;
readonly session_id?: string;
readonly stop?: string | readonly Array<string> | null;
readonly stop_server_tools_when?: readonly Array<ReadonlySide<{
readonly step_count: Number;
readonly type: Literal<"step_count_is">;
}, "Encoded"> | ReadonlySide<{
readonly tool_name: String;
readonly type: Literal<"has_tool_call">;
}, "Encoded"> | ReadonlySide<{
readonly max_tokens: Number;
readonly type: Literal<"max_tokens_used">;
}, "Encoded"> | ReadonlySide<{
readonly max_cost_in_dollars: Number;
readonly type: Literal<"max_cost">;
}, "Encoded"> | ReadonlySide<{
readonly reason: String;
readonly type: Literal<"finish_reason_is">;
}, "Encoded">>;
readonly strictJsonSchema?: boolean;
readonly temperature?: number | null;
readonly top_a?: number | null;
readonly top_k?: number | null;
readonly top_logprobs?: number | null;
readonly top_p?: number | null;
readonly trace?: {
readonly generation_name?: string;
readonly parent_span_id?: string;
readonly span_name?: string;
readonly trace_id?: string;
readonly trace_name?: string;
};
readonly user?: string;
}): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, Exclude<R, Config>>;
<A, E, R>(self: Effect<A, E, R>, overrides: {
readonly cache_control?: {
readonly ttl?: "5m" | "1h";
readonly type: "ephemeral";
};
readonly debug?: {
readonly echo_upstream_body?: boolean;
};
readonly frequency_penalty?: number | null;
readonly image_config?: ReadonlySide<{}, "Encoded">;
readonly logit_bias?: {
[key: string]: number;
} | null;
readonly logprobs?: boolean | null;
readonly max_completion_tokens?: number | null;
readonly max_tokens?: number | null;
readonly metadata?: ReadonlySide<{}, "Encoded">;
readonly min_p?: number | null;
readonly modalities?: readonly Array<"text" | "audio" | "image">;
readonly model?: string;
readonly models?: readonly Array<string>;
readonly parallel_tool_calls?: boolean | null;
readonly plugins?: readonly Array<{
readonly allowed_models?: readonly Array<string>;
readonly cost_quality_tradeoff?: number;
readonly enabled?: boolean;
readonly id: "auto-router";
readonly pin_model?: boolean;
} | {
readonly allowed_models?: readonly Array<string>;
readonly cost_quality_tradeoff?: number;
readonly enabled?: boolean;
readonly id: "auto-beta-router";
} | ReadonlySide<{
readonly id: Literal<"moderation">;
}, "Encoded"> | {
readonly enabled?: boolean;
readonly engine?: "native" | "exa" | "firecrawl" | "parallel" | "perplexity";
readonly exclude_domains?: readonly Array<string>;
readonly id: "web";
readonly include_domains?: readonly Array<string>;
readonly max_results?: number;
readonly max_uses?: number;
readonly search_prompt?: string;
readonly user_location?: {
[key: string]: Json;
readonly city?: string | null;
readonly country?: string | null;
readonly region?: string | null;
readonly timezone?: string | null;
readonly type: "approximate";
};
} | {
readonly allowed_domains?: readonly Array<string>;
readonly blocked_domains?: readonly Array<string>;
readonly id: "web-fetch";
readonly max_content_tokens?: number;
readonly max_uses?: number;
} | {
readonly enabled?: boolean;
readonly id: "file-parser";
readonly pdf?: {
readonly engine?: "native" | "mistral-ocr" | "cloudflare-ai" | "pdf-text";
};
} | {
readonly enabled?: boolean;
readonly id: "response-healing";
} | {
readonly enabled?: boolean;
readonly engine?: "middle-out";
readonly id: "context-compression";
} | {
readonly enabled?: boolean;
readonly id: "pareto-router";
readonly max_price?: number;
readonly min_coding_score?: number;
readonly price_source?: "prompt" | "weighted_avg";
} | {
readonly analysis_models?: readonly Array<string>;
readonly enabled?: boolean;
readonly id: "fusion";
readonly max_tool_calls?: number;
readonly model?: string;
readonly preset?: "general-high" | "general-budget" | "general-fast";
readonly tools?: readonly Array<{
readonly parameters?: ReadonlySide<..., ...>;
readonly type: string;
}>;
}>;
readonly prediction?: {
[key: string]: Json;
readonly content: string | readonly Array<ReadonlySide<{
readonly text: String;
readonly type: Literal<"text">;
}, "Encoded">>;
readonly type: "content";
} | null;
readonly presence_penalty?: number | null;
readonly prompt_cache_key?: string | null;
readonly prompt_cache_options?: {
[key: string]: Json;
readonly mode: "explicit";
readonly ttl?: string | null;
} | null;
readonly provider?: {
readonly allow_fallbacks?: boolean | null;
readonly data_collection?: "deny" | "allow" | null;
readonly enforce_distillable_text?: boolean | null;
readonly ignore?: readonly Array<string> | null;
readonly max_price?: {
readonly audio?: string;
readonly completion?: string;
readonly image?: string;
readonly prompt?: string;
readonly request?: string;
};
readonly only?: readonly Array<string> | null;
readonly order?: readonly Array<string> | null;
readonly preferred_max_latency?: number | {
readonly p50?: number | null;
readonly p75?: number | null;
readonly p90?: number | null;
readonly p99?: number | null;
} | null;
readonly preferred_min_throughput?: number | {
readonly p50?: number | null;
readonly p75?: number | null;
readonly p90?: number | null;
readonly p99?: number | null;
} | null;
readonly quantizations?: readonly Array<"unknown" | "int4" | "int8" | "fp4" | "fp6" | "fp8" | "fp16" | "bf16" | "fp32"> | null;
readonly require_parameters?: boolean | null;
readonly sort?: "price" | "throughput" | "latency" | "exacto" | {
readonly by?: "price" | "throughput" | "latency" | "exacto" | null;
readonly partition?: "model" | "none" | null;
} | null;
readonly zdr?: boolean | null;
} | null;
readonly reasoning?: {
readonly effort?: "low" | "high" | "none" | "max" | "xhigh" | "medium" | "minimal" | null;
readonly summary?: "auto" | "concise" | "detailed" | null;
};
readonly reasoning_effort?: "low" | "high" | "none" | "max" | "xhigh" | "medium" | "minimal" | null;
readonly repetition_penalty?: number | null;
readonly route?: "sort" | "fallback" | null;
readonly seed?: number | null;
readonly service_tier?: "auto" | "default" | "flex" | "priority" | "scale" | null;
readonly session_id?: string;
readonly stop?: string | readonly Array<string> | null;
readonly stop_server_tools_when?: readonly Array<ReadonlySide<{
readonly step_count: Number;
readonly type: Literal<"step_count_is">;
}, "Encoded"> | ReadonlySide<{
readonly tool_name: String;
readonly type: Literal<"has_tool_call">;
}, "Encoded"> | ReadonlySide<{
readonly max_tokens: Number;
readonly type: Literal<"max_tokens_used">;
}, "Encoded"> | ReadonlySide<{
readonly max_cost_in_dollars: Number;
readonly type: Literal<"max_cost">;
}, "Encoded"> | ReadonlySide<{
readonly reason: String;
readonly type: Literal<"finish_reason_is">;
}, "Encoded">>;
readonly strictJsonSchema?: boolean;
readonly temperature?: number | null;
readonly top_a?: number | null;
readonly top_k?: number | null;
readonly top_logprobs?: number | null;
readonly top_p?: number | null;
readonly trace?: {
readonly generation_name?: string;
readonly parent_span_id?: string;
readonly span_name?: string;
readonly trace_id?: string;
readonly trace_name?: string;
};
readonly user?: string;
}): Effect<A, E, Exclude<R, Config>>;
}

Constructors

make

Added in v4.0.0 Source

Creates an OpenRouter LanguageModel service from a model identifier and optional request defaults.

When to use

Use when you need to construct a LanguageModel.Service value backed by OpenRouterClient inside an Effect.

Details

The returned effect requires OpenRouterClient. Request defaults from the config option are merged with any Config service in the context, with context values taking precedence. The service supports both generateText and streamText.

Gotchas

Provider-defined tools are not supported by this provider integration; requests that include them fail with an InvalidUserInputError.

See

  • layer for providing the service as a Layer
  • model for creating a model descriptor for Effect.provide
  • withConfigOverride for scoping request defaults around operations

Signature

declare const make: (...args: [{
readonly config?: Omit<{
readonly cache_control?: {
readonly ttl?: "5m" | "1h";
readonly type: "ephemeral";
};
readonly debug?: {
readonly echo_upstream_body?: boolean;
};
readonly frequency_penalty?: number | null;
readonly image_config?: ReadonlySide<{}, "Encoded">;
readonly logit_bias?: {
[key: string]: number;
} | null;
readonly logprobs?: boolean | null;
readonly max_completion_tokens?: number | null;
readonly max_tokens?: number | null;
readonly metadata?: ReadonlySide<{}, "Encoded">;
readonly min_p?: number | null;
readonly modalities?: readonly Array<"text" | "audio" | "image">;
readonly model?: string;
readonly models?: readonly Array<string>;
readonly parallel_tool_calls?: boolean | null;
readonly plugins?: readonly Array<{
readonly allowed_models?: ... | ...;
readonly cost_quality_tradeoff?: ... | ...;
readonly enabled?: ... | ... | ...;
readonly id: "auto-router";
readonly pin_model?: ... | ... | ...;
} | {
readonly allowed_models?: ... | ...;
readonly cost_quality_tradeoff?: ... | ...;
readonly enabled?: ... | ... | ...;
readonly id: "auto-beta-router";
} | ReadonlySide<{
readonly id: ...;
}, "Encoded"> | {
readonly enabled?: ... | ... | ...;
readonly engine?: ... | ... | ... | ... | ... | ...;
readonly exclude_domains?: ... | ...;
readonly id: "web";
readonly include_domains?: ... | ...;
readonly max_results?: ... | ...;
readonly max_uses?: ... | ...;
readonly search_prompt?: ... | ...;
readonly user_location?: ... | ...;
} | {
readonly allowed_domains?: ... | ...;
readonly blocked_domains?: ... | ...;
readonly id: "web-fetch";
readonly max_content_tokens?: ... | ...;
readonly max_uses?: ... | ...;
} | {
readonly enabled?: ... | ... | ...;
readonly id: "file-parser";
readonly pdf?: ... | ...;
} | {
readonly enabled?: ... | ... | ...;
readonly id: "response-healing";
} | {
readonly enabled?: ... | ... | ...;
readonly engine?: ... | ...;
readonly id: "context-compression";
} | {
readonly enabled?: ... | ... | ...;
readonly id: "pareto-router";
readonly max_price?: ... | ...;
readonly min_coding_score?: ... | ...;
readonly price_source?: ... | ... | ...;
} | {
readonly analysis_models?: ... | ...;
readonly enabled?: ... | ... | ...;
readonly id: "fusion";
readonly max_tool_calls?: ... | ...;
readonly model?: ... | ...;
readonly preset?: ... | ... | ... | ...;
readonly tools?: ... | ...;
}>;
readonly prediction?: {
[key: string]: Json;
readonly content: string | readonly Array<ReadonlySide<..., ...>>;
readonly type: "content";
} | null;
readonly presence_penalty?: number | null;
readonly prompt_cache_key?: string | null;
readonly prompt_cache_options?: {
[key: string]: Json;
readonly mode: "explicit";
readonly ttl?: string | null;
} | null;
readonly provider?: {
readonly allow_fallbacks?: boolean | null;
readonly data_collection?: "deny" | "allow" | null;
readonly enforce_distillable_text?: boolean | null;
readonly ignore?: readonly Array<string> | null;
readonly max_price?: {
readonly audio?: ... | ...;
readonly completion?: ... | ...;
readonly image?: ... | ...;
readonly prompt?: ... | ...;
readonly request?: ... | ...;
};
readonly only?: readonly Array<string> | null;
readonly order?: readonly Array<string> | null;
readonly preferred_max_latency?: number | {
readonly p50?: ... | ... | ...;
readonly p75?: ... | ... | ...;
readonly p90?: ... | ... | ...;
readonly p99?: ... | ... | ...;
} | null;
readonly preferred_min_throughput?: number | {
readonly p50?: ... | ... | ...;
readonly p75?: ... | ... | ...;
readonly p90?: ... | ... | ...;
readonly p99?: ... | ... | ...;
} | null;
readonly quantizations?: readonly Array<... | ... | ... | ... | ... | ... | ... | ... | ...> | null;
readonly require_parameters?: boolean | null;
readonly sort?: "price" | "throughput" | "latency" | "exacto" | {
readonly by?: ... | ... | ... | ... | ... | ...;
readonly partition?: ... | ... | ... | ...;
} | null;
readonly zdr?: boolean | null;
} | null;
readonly reasoning?: {
readonly effort?: "low" | "high" | "none" | "max" | "xhigh" | "medium" | "minimal" | null;
readonly summary?: "auto" | "concise" | "detailed" | null;
};
readonly reasoning_effort?: "low" | "high" | "none" | "max" | "xhigh" | "medium" | "minimal" | null;
readonly repetition_penalty?: number | null;
readonly route?: "sort" | "fallback" | null;
readonly seed?: number | null;
readonly service_tier?: "auto" | "default" | "flex" | "priority" | "scale" | null;
readonly session_id?: string;
readonly stop?: string | readonly Array<string> | null;
readonly stop_server_tools_when?: readonly Array<ReadonlySide<{
readonly step_count: ...;
readonly type: ...;
}, "Encoded"> | ReadonlySide<{
readonly tool_name: ...;
readonly type: ...;
}, "Encoded"> | ReadonlySide<{
readonly max_tokens: ...;
readonly type: ...;
}, "Encoded"> | ReadonlySide<{
readonly max_cost_in_dollars: ...;
readonly type: ...;
}, "Encoded"> | ReadonlySide<{
readonly reason: ...;
readonly type: ...;
}, "Encoded">>;
readonly strictJsonSchema?: boolean;
readonly temperature?: number | null;
readonly top_a?: number | null;
readonly top_k?: number | null;
readonly top_logprobs?: number | null;
readonly top_p?: number | null;
readonly trace?: {
readonly generation_name?: string;
readonly parent_span_id?: string;
readonly span_name?: string;
readonly trace_id?: string;
readonly trace_name?: string;
};
readonly user?: string;
}, "model">;
readonly model: string;
}]) => Effect<Service, never, OpenRouterClient>

model

Added in v4.0.0 Source

Creates an OpenRouter model descriptor that can be provided with Effect.provide.

When to use

Use when you want an OpenRouter language model value that carries provider and model metadata and can be supplied directly to an Effect program.

Details

The returned model requires OpenRouterClient and provides LanguageModel.LanguageModel.

See

  • layer for creating a LanguageModel.LanguageModel layer directly
  • make for constructing the language model service effectfully
  • withConfigOverride for scoping OpenRouter request overrides

Signature

declare function model(model: string, config?: Omit<{
readonly cache_control?: {
readonly ttl?: "5m" | "1h";
readonly type: "ephemeral";
};
readonly debug?: {
readonly echo_upstream_body?: boolean;
};
readonly frequency_penalty?: number | null;
readonly image_config?: ReadonlySide<{}, "Encoded">;
readonly logit_bias?: {
[key: string]: number;
} | null;
readonly logprobs?: boolean | null;
readonly max_completion_tokens?: number | null;
readonly max_tokens?: number | null;
readonly metadata?: ReadonlySide<{}, "Encoded">;
readonly min_p?: number | null;
readonly modalities?: readonly Array<"text" | "audio" | "image">;
readonly model?: string;
readonly models?: readonly Array<string>;
readonly parallel_tool_calls?: boolean | null;
readonly plugins?: readonly Array<{
readonly allowed_models?: readonly Array<string>;
readonly cost_quality_tradeoff?: number;
readonly enabled?: boolean;
readonly id: "auto-router";
readonly pin_model?: boolean;
} | {
readonly allowed_models?: readonly Array<string>;
readonly cost_quality_tradeoff?: number;
readonly enabled?: boolean;
readonly id: "auto-beta-router";
} | ReadonlySide<{
readonly id: Literal<"moderation">;
}, "Encoded"> | {
readonly enabled?: boolean;
readonly engine?: "native" | "exa" | "firecrawl" | "parallel" | "perplexity";
readonly exclude_domains?: readonly Array<string>;
readonly id: "web";
readonly include_domains?: readonly Array<string>;
readonly max_results?: number;
readonly max_uses?: number;
readonly search_prompt?: string;
readonly user_location?: {
[key: string]: Json;
readonly city?: string | null;
readonly country?: string | null;
readonly region?: string | null;
readonly timezone?: string | null;
readonly type: "approximate";
};
} | {
readonly allowed_domains?: readonly Array<string>;
readonly blocked_domains?: readonly Array<string>;
readonly id: "web-fetch";
readonly max_content_tokens?: number;
readonly max_uses?: number;
} | {
readonly enabled?: boolean;
readonly id: "file-parser";
readonly pdf?: {
readonly engine?: "native" | "mistral-ocr" | "cloudflare-ai" | "pdf-text";
};
} | {
readonly enabled?: boolean;
readonly id: "response-healing";
} | {
readonly enabled?: boolean;
readonly engine?: "middle-out";
readonly id: "context-compression";
} | {
readonly enabled?: boolean;
readonly id: "pareto-router";
readonly max_price?: number;
readonly min_coding_score?: number;
readonly price_source?: "prompt" | "weighted_avg";
} | {
readonly analysis_models?: readonly Array<string>;
readonly enabled?: boolean;
readonly id: "fusion";
readonly max_tool_calls?: number;
readonly model?: string;
readonly preset?: "general-high" | "general-budget" | "general-fast";
readonly tools?: readonly Array<{
readonly parameters?: ... | ...;
readonly type: string;
}>;
}>;
readonly prediction?: {
[key: string]: Json;
readonly content: string | readonly Array<ReadonlySide<{
readonly text: String;
readonly type: Literal<"text">;
}, "Encoded">>;
readonly type: "content";
} | null;
readonly presence_penalty?: number | null;
readonly prompt_cache_key?: string | null;
readonly prompt_cache_options?: {
[key: string]: Json;
readonly mode: "explicit";
readonly ttl?: string | null;
} | null;
readonly provider?: {
readonly allow_fallbacks?: boolean | null;
readonly data_collection?: "deny" | "allow" | null;
readonly enforce_distillable_text?: boolean | null;
readonly ignore?: readonly Array<string> | null;
readonly max_price?: {
readonly audio?: string;
readonly completion?: string;
readonly image?: string;
readonly prompt?: string;
readonly request?: string;
};
readonly only?: readonly Array<string> | null;
readonly order?: readonly Array<string> | null;
readonly preferred_max_latency?: number | {
readonly p50?: number | null;
readonly p75?: number | null;
readonly p90?: number | null;
readonly p99?: number | null;
} | null;
readonly preferred_min_throughput?: number | {
readonly p50?: number | null;
readonly p75?: number | null;
readonly p90?: number | null;
readonly p99?: number | null;
} | null;
readonly quantizations?: readonly Array<"unknown" | "int4" | "int8" | "fp4" | "fp6" | "fp8" | "fp16" | "bf16" | "fp32"> | null;
readonly require_parameters?: boolean | null;
readonly sort?: "price" | "throughput" | "latency" | "exacto" | {
readonly by?: "price" | "throughput" | "latency" | "exacto" | null;
readonly partition?: "model" | "none" | null;
} | null;
readonly zdr?: boolean | null;
} | null;
readonly reasoning?: {
readonly effort?: "low" | "high" | "none" | "max" | "xhigh" | "medium" | "minimal" | null;
readonly summary?: "auto" | "concise" | "detailed" | null;
};
readonly reasoning_effort?: "low" | "high" | "none" | "max" | "xhigh" | "medium" | "minimal" | null;
readonly repetition_penalty?: number | null;
readonly route?: "sort" | "fallback" | null;
readonly seed?: number | null;
readonly service_tier?: "auto" | "default" | "flex" | "priority" | "scale" | null;
readonly session_id?: string;
readonly stop?: string | readonly Array<string> | null;
readonly stop_server_tools_when?: readonly Array<ReadonlySide<{
readonly step_count: Number;
readonly type: Literal<"step_count_is">;
}, "Encoded"> | ReadonlySide<{
readonly tool_name: String;
readonly type: Literal<"has_tool_call">;
}, "Encoded"> | ReadonlySide<{
readonly max_tokens: Number;
readonly type: Literal<"max_tokens_used">;
}, "Encoded"> | ReadonlySide<{
readonly max_cost_in_dollars: Number;
readonly type: Literal<"max_cost">;
}, "Encoded"> | ReadonlySide<{
readonly reason: String;
readonly type: Literal<"finish_reason_is">;
}, "Encoded">>;
readonly strictJsonSchema?: boolean;
readonly temperature?: number | null;
readonly top_a?: number | null;
readonly top_k?: number | null;
readonly top_logprobs?: number | null;
readonly top_p?: number | null;
readonly trace?: {
readonly generation_name?: string;
readonly parent_span_id?: string;
readonly span_name?: string;
readonly trace_id?: string;
readonly trace_name?: string;
};
readonly user?: string;
}, "model">): Model<"openai", LanguageModel, OpenRouterClient>

Layers

layer

Added in v4.0.0 Source

Creates a layer for the OpenRouter language model.

When to use

Use when composing application layers and you want OpenRouter to satisfy LanguageModel.LanguageModel while supplying OpenRouterClient from another layer.

See

  • make for constructing the language model service effectfully
  • model for creating a model descriptor for Effect.provide

Signature

declare function layer(options: {
readonly config?: Omit<{
readonly cache_control?: {
readonly ttl?: "5m" | "1h";
readonly type: "ephemeral";
};
readonly debug?: {
readonly echo_upstream_body?: boolean;
};
readonly frequency_penalty?: number | null;
readonly image_config?: ReadonlySide<{}, "Encoded">;
readonly logit_bias?: {
[key: string]: number;
} | null;
readonly logprobs?: boolean | null;
readonly max_completion_tokens?: number | null;
readonly max_tokens?: number | null;
readonly metadata?: ReadonlySide<{}, "Encoded">;
readonly min_p?: number | null;
readonly modalities?: readonly Array<"text" | "audio" | "image">;
readonly model?: string;
readonly models?: readonly Array<string>;
readonly parallel_tool_calls?: boolean | null;
readonly plugins?: readonly Array<{
readonly allowed_models?: readonly Array<string>;
readonly cost_quality_tradeoff?: number;
readonly enabled?: boolean;
readonly id: "auto-router";
readonly pin_model?: boolean;
} | {
readonly allowed_models?: readonly Array<string>;
readonly cost_quality_tradeoff?: number;
readonly enabled?: boolean;
readonly id: "auto-beta-router";
} | ReadonlySide<{
readonly id: Literal<"moderation">;
}, "Encoded"> | {
readonly enabled?: boolean;
readonly engine?: "native" | "exa" | "firecrawl" | "parallel" | "perplexity";
readonly exclude_domains?: readonly Array<string>;
readonly id: "web";
readonly include_domains?: readonly Array<string>;
readonly max_results?: number;
readonly max_uses?: number;
readonly search_prompt?: string;
readonly user_location?: {
[key: string]: Json;
readonly city?: ... | ... | ...;
readonly country?: ... | ... | ...;
readonly region?: ... | ... | ...;
readonly timezone?: ... | ... | ...;
readonly type: "approximate";
};
} | {
readonly allowed_domains?: readonly Array<string>;
readonly blocked_domains?: readonly Array<string>;
readonly id: "web-fetch";
readonly max_content_tokens?: number;
readonly max_uses?: number;
} | {
readonly enabled?: boolean;
readonly id: "file-parser";
readonly pdf?: {
readonly engine?: ... | ... | ... | ... | ...;
};
} | {
readonly enabled?: boolean;
readonly id: "response-healing";
} | {
readonly enabled?: boolean;
readonly engine?: "middle-out";
readonly id: "context-compression";
} | {
readonly enabled?: boolean;
readonly id: "pareto-router";
readonly max_price?: number;
readonly min_coding_score?: number;
readonly price_source?: "prompt" | "weighted_avg";
} | {
readonly analysis_models?: readonly Array<string>;
readonly enabled?: boolean;
readonly id: "fusion";
readonly max_tool_calls?: number;
readonly model?: string;
readonly preset?: "general-high" | "general-budget" | "general-fast";
readonly tools?: readonly Array<{
readonly parameters?: ...;
readonly type: ...;
}>;
}>;
readonly prediction?: {
[key: string]: Json;
readonly content: string | readonly Array<ReadonlySide<{
readonly text: String;
readonly type: Literal<...>;
}, "Encoded">>;
readonly type: "content";
} | null;
readonly presence_penalty?: number | null;
readonly prompt_cache_key?: string | null;
readonly prompt_cache_options?: {
[key: string]: Json;
readonly mode: "explicit";
readonly ttl?: string | null;
} | null;
readonly provider?: {
readonly allow_fallbacks?: boolean | null;
readonly data_collection?: "deny" | "allow" | null;
readonly enforce_distillable_text?: boolean | null;
readonly ignore?: readonly Array<string> | null;
readonly max_price?: {
readonly audio?: string;
readonly completion?: string;
readonly image?: string;
readonly prompt?: string;
readonly request?: string;
};
readonly only?: readonly Array<string> | null;
readonly order?: readonly Array<string> | null;
readonly preferred_max_latency?: number | {
readonly p50?: number | null;
readonly p75?: number | null;
readonly p90?: number | null;
readonly p99?: number | null;
} | null;
readonly preferred_min_throughput?: number | {
readonly p50?: number | null;
readonly p75?: number | null;
readonly p90?: number | null;
readonly p99?: number | null;
} | null;
readonly quantizations?: readonly Array<"unknown" | "int4" | "int8" | "fp4" | "fp6" | "fp8" | "fp16" | "bf16" | "fp32"> | null;
readonly require_parameters?: boolean | null;
readonly sort?: "price" | "throughput" | "latency" | "exacto" | {
readonly by?: "price" | "throughput" | "latency" | "exacto" | null;
readonly partition?: "model" | "none" | null;
} | null;
readonly zdr?: boolean | null;
} | null;
readonly reasoning?: {
readonly effort?: "low" | "high" | "none" | "max" | "xhigh" | "medium" | "minimal" | null;
readonly summary?: "auto" | "concise" | "detailed" | null;
};
readonly reasoning_effort?: "low" | "high" | "none" | "max" | "xhigh" | "medium" | "minimal" | null;
readonly repetition_penalty?: number | null;
readonly route?: "sort" | "fallback" | null;
readonly seed?: number | null;
readonly service_tier?: "auto" | "default" | "flex" | "priority" | "scale" | null;
readonly session_id?: string;
readonly stop?: string | readonly Array<string> | null;
readonly stop_server_tools_when?: readonly Array<ReadonlySide<{
readonly step_count: Number;
readonly type: Literal<"step_count_is">;
}, "Encoded"> | ReadonlySide<{
readonly tool_name: String;
readonly type: Literal<"has_tool_call">;
}, "Encoded"> | ReadonlySide<{
readonly max_tokens: Number;
readonly type: Literal<"max_tokens_used">;
}, "Encoded"> | ReadonlySide<{
readonly max_cost_in_dollars: Number;
readonly type: Literal<"max_cost">;
}, "Encoded"> | ReadonlySide<{
readonly reason: String;
readonly type: Literal<"finish_reason_is">;
}, "Encoded">>;
readonly strictJsonSchema?: boolean;
readonly temperature?: number | null;
readonly top_a?: number | null;
readonly top_k?: number | null;
readonly top_logprobs?: number | null;
readonly top_p?: number | null;
readonly trace?: {
readonly generation_name?: string;
readonly parent_span_id?: string;
readonly span_name?: string;
readonly trace_id?: string;
readonly trace_name?: string;
};
readonly user?: string;
}, "model">;
readonly model: string;
}): Layer<LanguageModel, never, OpenRouterClient>

Models

FileAnnotation type

Added in v4.0.0 Source

File annotations emitted on OpenRouter assistant messages and exposed in finish metadata.

Signature

type FileAnnotation = Extract<
NonNullable<typeof Generated.ChatAssistantMessage.fields.annotations.Type>[number],
{
type: "file";
}
>;

ReasoningDetails type

Added in v4.0.0 Source

OpenRouter assistant reasoning detail blocks preserved for multi-turn conversations.

Signature

type ReasoningDetails = Exclude<
(typeof Generated.ChatAssistantMessage.Encoded)["reasoning_details"],
undefined
>;

Services

Config

Added in v4.0.0 Source

Context service for OpenRouter language model configuration.

When to use

Use to provide scoped OpenRouter chat completion defaults or per-operation overrides for an OpenRouter language model service.

See

Signature

declare class Config extends Shape<"@effect/ai-openrouter/OpenRouterLanguageModel/Config", {
readonly cache_control?: {
readonly ttl?: "5m" | "1h";
readonly type: "ephemeral";
};
readonly debug?: {
readonly echo_upstream_body?: boolean;
};
readonly frequency_penalty?: number | null;
readonly image_config?: ReadonlySide<{}, "Encoded">;
readonly logit_bias?: {
[key: string]: number;
} | null;
readonly logprobs?: boolean | null;
readonly max_completion_tokens?: number | null;
readonly max_tokens?: number | null;
readonly metadata?: ReadonlySide<{}, "Encoded">;
readonly min_p?: number | null;
readonly modalities?: readonly Array<"text" | "audio" | "image">;
readonly model?: string;
readonly models?: readonly Array<string>;
readonly parallel_tool_calls?: boolean | null;
readonly plugins?: readonly Array<{
readonly allowed_models?: readonly Array<string>;
readonly cost_quality_tradeoff?: number;
readonly enabled?: boolean;
readonly id: "auto-router";
readonly pin_model?: boolean;
} | {
readonly allowed_models?: readonly Array<string>;
readonly cost_quality_tradeoff?: number;
readonly enabled?: boolean;
readonly id: "auto-beta-router";
} | ReadonlySide<{
readonly id: Literal<"moderation">;
}, "Encoded"> | {
readonly enabled?: boolean;
readonly engine?: "native" | "exa" | "firecrawl" | "parallel" | "perplexity";
readonly exclude_domains?: readonly Array<string>;
readonly id: "web";
readonly include_domains?: readonly Array<string>;
readonly max_results?: number;
readonly max_uses?: number;
readonly search_prompt?: string;
readonly user_location?: {
[key: string]: Json;
readonly city?: string | null;
readonly country?: string | null;
readonly region?: string | null;
readonly timezone?: string | null;
readonly type: "approximate";
};
} | {
readonly allowed_domains?: readonly Array<string>;
readonly blocked_domains?: readonly Array<string>;
readonly id: "web-fetch";
readonly max_content_tokens?: number;
readonly max_uses?: number;
} | {
readonly enabled?: boolean;
readonly id: "file-parser";
readonly pdf?: {
readonly engine?: "native" | "mistral-ocr" | "cloudflare-ai" | "pdf-text";
};
} | {
readonly enabled?: boolean;
readonly id: "response-healing";
} | {
readonly enabled?: boolean;
readonly engine?: "middle-out";
readonly id: "context-compression";
} | {
readonly enabled?: boolean;
readonly id: "pareto-router";
readonly max_price?: number;
readonly min_coding_score?: number;
readonly price_source?: "prompt" | "weighted_avg";
} | {
readonly analysis_models?: readonly Array<string>;
readonly enabled?: boolean;
readonly id: "fusion";
readonly max_tool_calls?: number;
readonly model?: string;
readonly preset?: "general-high" | "general-budget" | "general-fast";
readonly tools?: readonly Array<{
readonly parameters?: ... | ...;
readonly type: string;
}>;
}>;
readonly prediction?: {
[key: string]: Json;
readonly content: string | readonly Array<ReadonlySide<{
readonly text: String;
readonly type: Literal<"text">;
}, "Encoded">>;
readonly type: "content";
} | null;
readonly presence_penalty?: number | null;
readonly prompt_cache_key?: string | null;
readonly prompt_cache_options?: {
[key: string]: Json;
readonly mode: "explicit";
readonly ttl?: string | null;
} | null;
readonly provider?: {
readonly allow_fallbacks?: boolean | null;
readonly data_collection?: "deny" | "allow" | null;
readonly enforce_distillable_text?: boolean | null;
readonly ignore?: readonly Array<string> | null;
readonly max_price?: {
readonly audio?: string;
readonly completion?: string;
readonly image?: string;
readonly prompt?: string;
readonly request?: string;
};
readonly only?: readonly Array<string> | null;
readonly order?: readonly Array<string> | null;
readonly preferred_max_latency?: number | {
readonly p50?: number | null;
readonly p75?: number | null;
readonly p90?: number | null;
readonly p99?: number | null;
} | null;
readonly preferred_min_throughput?: number | {
readonly p50?: number | null;
readonly p75?: number | null;
readonly p90?: number | null;
readonly p99?: number | null;
} | null;
readonly quantizations?: readonly Array<"unknown" | "int4" | "int8" | "fp4" | "fp6" | "fp8" | "fp16" | "bf16" | "fp32"> | null;
readonly require_parameters?: boolean | null;
readonly sort?: "price" | "throughput" | "latency" | "exacto" | {
readonly by?: "price" | "throughput" | "latency" | "exacto" | null;
readonly partition?: "model" | "none" | null;
} | null;
readonly zdr?: boolean | null;
} | null;
readonly reasoning?: {
readonly effort?: "low" | "high" | "none" | "max" | "xhigh" | "medium" | "minimal" | null;
readonly summary?: "auto" | "concise" | "detailed" | null;
};
readonly reasoning_effort?: "low" | "high" | "none" | "max" | "xhigh" | "medium" | "minimal" | null;
readonly repetition_penalty?: number | null;
readonly route?: "sort" | "fallback" | null;
readonly seed?: number | null;
readonly service_tier?: "auto" | "default" | "flex" | "priority" | "scale" | null;
readonly session_id?: string;
readonly stop?: string | readonly Array<string> | null;
readonly stop_server_tools_when?: readonly Array<ReadonlySide<{
readonly step_count: Number;
readonly type: Literal<"step_count_is">;
}, "Encoded"> | ReadonlySide<{
readonly tool_name: String;
readonly type: Literal<"has_tool_call">;
}, "Encoded"> | ReadonlySide<{
readonly max_tokens: Number;
readonly type: Literal<"max_tokens_used">;
}, "Encoded"> | ReadonlySide<{
readonly max_cost_in_dollars: Number;
readonly type: Literal<"max_cost">;
}, "Encoded"> | ReadonlySide<{
readonly reason: String;
readonly type: Literal<"finish_reason_is">;
}, "Encoded">>;
readonly strictJsonSchema?: boolean;
readonly temperature?: number | null;
readonly top_a?: number | null;
readonly top_k?: number | null;
readonly top_logprobs?: number | null;
readonly top_p?: number | null;
readonly trace?: {
readonly generation_name?: string;
readonly parent_span_id?: string;
readonly span_name?: string;
readonly trace_id?: string;
readonly trace_name?: string;
};
readonly user?: string;
}, this> {
constructor(_: never);
}