Skip to content

OpenRouterClient

The OpenRouterClient module provides an Effect service for calling OpenRouter's chat completions API. It wraps the generated OpenRouter HTTP client with Effect-native constructors, layers, authentication and optional site ranking headers, typed errors, and streaming support.

7 exports Added in v4.0.0 Source

Constructors

make

Added in v4.0.0 Source

Creates an OpenRouter client service from explicit options.

When to use

Use when you need the OpenRouter client service value inside an effect.

Details

The returned service uses the current HttpClient, prepends apiUrl or https://openrouter.ai/api/v1, adds the bearer token and optional HTTP-Referer and X-Title headers, accepts JSON responses, and applies transformClient when provided.

Gotchas

Scoped OpenRouterConfig.withClientTransform applies to generated client request methods. Streaming chat completion requests are sent directly by this module and do not read that scoped transform.

See

  • layer for providing this client from explicit options
  • layerConfig for loading client settings from Config

Signature

declare const make: (...args: [options: Options]) => Effect<Service, never, HttpClient>;

Layers

layer

Added in v4.0.0 Source

Creates a layer for the OpenRouter client with the given options.

When to use

Use when you already have the OpenRouter client options in code and want to provide OpenRouterClient as a layer.

See

  • make for constructing the client service effectfully
  • layerConfig for loading client settings from Config

Signature

declare function layer(options: Options): Layer<OpenRouterClient, never, HttpClient>;

layerConfig

Added in v4.0.0 Source

Creates a layer for the OpenRouter client from provided Config values.

When to use

Use when you need client settings for OpenRouter to be read from Effect Config values while providing OpenRouterClient as a layer.

Details

Only config values supplied in options are loaded. Omitted fields are passed to make as undefined, and transformClient is forwarded as a plain option.

See

  • make for constructing the client service effectfully
  • layer for providing the client from already-resolved options

Signature

declare function layerConfig(options?: {
  readonly apiKey?: Config<Redacted<string> | undefined>;
  readonly apiUrl?: Config<string>;
  readonly siteReferrer?: Config<string>;
  readonly siteTitle?: Config<string>;
  readonly transformClient?: (client: HttpClient) => HttpClient;
}): Layer<OpenRouterClient, ConfigError, HttpClient>;

Models

Decoded data payload from an OpenRouter chat completion streaming chunk.

Details

The payload contains streamed choices, model metadata, optional usage, and may include an OpenRouter error object for a streamed response.

Signature

type ChatStreamingResponseChunkData = typeof Generated.ChatStreamingResponse.fields.data.Type;

Options

Options type

Added in v4.0.0 Source

Configuration for creating an OpenRouter client.

Signature

type Options = {
  readonly apiKey?: Redacted.Redacted<string>;
  readonly apiUrl?: string;
  readonly siteReferrer?: string;
  readonly siteTitle?: string;
  readonly transformClient?: (client: HttpClient.HttpClient) => HttpClient.HttpClient;
};

Services

Service tag for the OpenRouter client.

When to use

Use when accessing or providing the OpenRouter client service through Effect's context.

See

  • make for constructing an OpenRouter client effectfully
  • layer for providing a client from explicit options
  • layerConfig for providing a client from Config

Signature

declare class OpenRouterClient extends Shape<
  "@effect/ai-openrouter/OpenRouterClient",
  Service,
  this
> {
  constructor(_: never);
}

Service interface

Added in v4.0.0 Source

The OpenRouter client service interface.

Details

Provides methods for interacting with OpenRouter's Chat Completions API, including both synchronous and streaming message creation.

Signature

interface Service {
  readonly client: OpenRouterClient;
  readonly createChatCompletion: (options: {
    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 messages: readonly Array<{
      readonly content: string | readonly Array<{
        readonly cache_control?: {
          readonly ttl?: ... | ... | ...;
          readonly type: "ephemeral";
        };
        readonly prompt_cache_breakpoint?: {
          [key: string]: Json;
          readonly mode: "explicit";
        } | null;
        readonly text: string;
        readonly type: "text";
      }>;
      readonly name?: string;
      readonly role: "system";
    } | {
      readonly content: string | readonly Array<{
        readonly cache_control?: {
          readonly ttl?: ...;
          readonly type: ...;
        };
        readonly prompt_cache_breakpoint?: {
          [key: ...]: ...;
          readonly mode: ...;
        } | null;
        readonly text: string;
        readonly type: "text";
      } | ReadonlySide<{
        readonly image_url: Struct<...>;
        readonly type: Literal<...>;
      }, "Encoded"> | ReadonlySide<{
        readonly input_audio: Struct<...>;
        readonly type: Literal<...>;
      }, "Encoded"> | ReadonlySide<{
        readonly type: Literal<...>;
        readonly video_url: Struct<...>;
      }, "Encoded"> | ReadonlySide<{
        readonly type: Literal<...>;
        readonly video_url: Struct<...>;
      }, "Encoded"> | ReadonlySide<{
        readonly file: Struct<...>;
        readonly type: Literal<...>;
      }, "Encoded">>;
      readonly name?: string;
      readonly role: "user";
    } | {
      readonly content: string | readonly Array<{
        readonly cache_control?: {
          readonly ttl?: ... | ... | ...;
          readonly type: "ephemeral";
        };
        readonly prompt_cache_breakpoint?: {
          [key: string]: Json;
          readonly mode: "explicit";
        } | null;
        readonly text: string;
        readonly type: "text";
      }>;
      readonly name?: string;
      readonly role: "developer";
    } | {
      readonly annotations?: readonly Array<ReadonlySide<{
        readonly type: Literal<...>;
        readonly url_citation: Struct<...>;
      }, "Encoded"> | ReadonlySide<{
        readonly file_annotation: Struct<...>;
        readonly type: Literal<...>;
      }, "Encoded"> | ReadonlySide<{
        readonly file: Struct<...>;
        readonly type: Literal<...>;
      }, "Encoded">> | null;
      readonly audio?: {
        readonly data?: string;
        readonly expires_at?: number;
        readonly id?: string;
        readonly transcript?: string;
      };
      readonly content?: string | readonly Array<{
        readonly cache_control?: {
          readonly ttl?: ...;
          readonly type: ...;
        };
        readonly prompt_cache_breakpoint?: {
          [key: ...]: ...;
          readonly mode: ...;
        } | null;
        readonly text: string;
        readonly type: "text";
      } | ReadonlySide<{
        readonly image_url: Struct<...>;
        readonly type: Literal<...>;
      }, "Encoded"> | ReadonlySide<{
        readonly input_audio: Struct<...>;
        readonly type: Literal<...>;
      }, "Encoded"> | ReadonlySide<{
        readonly type: Literal<...>;
        readonly video_url: Struct<...>;
      }, "Encoded"> | ReadonlySide<{
        readonly type: Literal<...>;
        readonly video_url: Struct<...>;
      }, "Encoded"> | ReadonlySide<{
        readonly file: Struct<...>;
        readonly type: Literal<...>;
      }, "Encoded">> | null;
      readonly images?: readonly Array<ReadonlySide<{
        readonly image_url: Struct<{
          readonly url: ...;
        }>;
        readonly type: Literal<"image_url">;
      }, "Encoded">> | null;
      readonly model?: string;
      readonly name?: string;
      readonly reasoning?: string | null;
      readonly reasoning_details?: readonly Array<{
        readonly format?: "unknown" | "openai-responses-v1" | "azure-openai-responses-v1" | "xai-responses-v1" | "meta-responses-v1" | "anthropic-claude-v1" | "google-gemini-v1" | null;
        readonly id?: string | null;
        readonly index?: number;
        readonly summary: string;
        readonly type: "reasoning.summary";
      } | {
        readonly data: string;
        readonly format?: "unknown" | "openai-responses-v1" | "azure-openai-responses-v1" | "xai-responses-v1" | "meta-responses-v1" | "anthropic-claude-v1" | "google-gemini-v1" | null;
        readonly id?: string | null;
        readonly index?: number;
        readonly type: "reasoning.encrypted";
      } | {
        readonly format?: "unknown" | "openai-responses-v1" | "azure-openai-responses-v1" | "xai-responses-v1" | "meta-responses-v1" | "anthropic-claude-v1" | "google-gemini-v1" | null;
        readonly id?: string | null;
        readonly index?: number;
        readonly signature?: string | null;
        readonly text?: string | null;
        readonly type: "reasoning.text";
      } | {
        readonly arguments: string;
        readonly format?: "unknown" | "openai-responses-v1" | "azure-openai-responses-v1" | "xai-responses-v1" | "meta-responses-v1" | "anthropic-claude-v1" | "google-gemini-v1" | null;
        readonly id?: string | null;
        readonly index?: number;
        readonly result: string;
        readonly tool_call_id?: string | null;
        readonly tool_name: string;
        readonly type: "reasoning.server_tool_call";
      }>;
      readonly refusal?: string | null;
      readonly role: "assistant";
      readonly tool_calls?: readonly Array<ReadonlySide<{
        readonly function: Struct<{
          readonly arguments: ...;
          readonly name: ...;
        }>;
        readonly id: String;
        readonly type: Literal<"function">;
      }, "Encoded">>;
    } | ReadonlySide<{
      readonly content: Union<readonly [String, $Array<Union<readonly [..., ..., ..., ..., ..., ...]>>]>;
      readonly role: Literal<"tool">;
      readonly tool_call_id: String;
    }, "Encoded">>;
    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 response_format?: ReadonlySide<{
      readonly type: Literal<"text">;
    }, "Encoded"> | ReadonlySide<{
      readonly type: Literal<"json_object">;
    }, "Encoded"> | ReadonlySide<{
      readonly json_schema: Struct<{
        readonly description: optionalKey<String>;
        readonly name: String;
        readonly schema: optionalKey<Struct<{}>>;
        readonly strict: optionalKey<Union<readonly [Boolean, Null]>>;
      }>;
      readonly type: Literal<"json_schema">;
    }, "Encoded"> | ReadonlySide<{
      readonly grammar: String;
      readonly type: Literal<"grammar">;
    }, "Encoded"> | ReadonlySide<{
      readonly type: Literal<"python">;
    }, "Encoded">;
    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 stream?: boolean;
    readonly stream_options?: {
      [key: string]: Json;
      readonly include_usage?: boolean;
    } | null;
    readonly temperature?: number | null;
    readonly tool_choice?: "required" | "auto" | "none" | ReadonlySide<{
      readonly function: Struct<{
        readonly name: String;
      }>;
      readonly type: Literal<"function">;
    }, "Encoded"> | ReadonlySide<{
      readonly type: String;
    }, "Encoded">;
    readonly tools?: readonly Array<{
      readonly cache_control?: {
        readonly ttl?: "5m" | "1h";
        readonly type: "ephemeral";
      };
      readonly function: {
        readonly description?: string;
        readonly name: string;
        readonly parameters?: ReadonlySide<{}, "Encoded">;
        readonly strict?: boolean | null;
      };
      readonly type: "function";
    } | {
      readonly parameters?: {
        readonly forward_transcript?: boolean;
        readonly instructions?: string;
        readonly max_completion_tokens?: number;
        readonly max_tool_calls?: number;
        readonly model?: string;
        readonly name?: string;
        readonly reasoning?: {
          readonly effort?: ... | ... | ... | ... | ... | ... | ... | ...;
          readonly max_tokens?: ... | ...;
        };
        readonly stream?: boolean;
        readonly temperature?: number;
        readonly tools?: readonly Array<{
          readonly parameters?: ...;
          readonly type: ...;
        }>;
      };
      readonly type: "openrouter:advisor";
    } | {
      readonly parameters?: {
        readonly engine?: "auto" | "native" | "openrouter";
        readonly environment?: ReadonlySide<{
          readonly type: ...;
        }, "Encoded"> | ReadonlySide<{
          readonly container_id: ...;
          readonly type: ...;
        }, "Encoded">;
        readonly sleep_after_seconds?: number;
      };
      readonly type: "openrouter:bash";
    } | {
      readonly parameters?: {
        readonly timezone?: string;
      };
      readonly type: "openrouter:datetime";
    } | {
      readonly parameters?: ReadonlySide<{}, "Encoded">;
      readonly type: "openrouter:files";
    } | {
      readonly parameters?: {
        readonly analysis_models?: readonly Array<string>;
        readonly cache_control?: {
          readonly ttl?: ... | ... | ...;
          readonly type: "ephemeral";
        };
        readonly max_completion_tokens?: number;
        readonly max_tool_calls?: number;
        readonly model?: string;
        readonly reasoning?: {
          readonly effort?: ... | ... | ... | ... | ... | ... | ... | ...;
          readonly max_tokens?: ... | ...;
        };
        readonly temperature?: number;
        readonly tools?: readonly Array<{
          readonly parameters?: ...;
          readonly type: ...;
        }>;
      };
      readonly type: "openrouter:fusion";
    } | {
      readonly parameters?: {
        readonly model?: string;
      };
      readonly type: "openrouter:image_generation";
    } | {
      readonly parameters?: {
        readonly max_results?: number;
      };
      readonly type: "openrouter:experimental__search_models";
    } | {
      readonly parameters?: {
        readonly instructions?: string;
        readonly max_completion_tokens?: number;
        readonly max_tool_calls?: number;
        readonly model?: string;
        readonly name?: string;
        readonly reasoning?: {
          readonly effort?: ... | ... | ... | ... | ... | ... | ... | ...;
          readonly max_tokens?: ... | ...;
        };
        readonly temperature?: number;
        readonly tools?: readonly Array<{
          readonly parameters?: ...;
          readonly type: ...;
        }>;
      };
      readonly type: "openrouter:subagent";
    } | {
      readonly parameters?: {
        readonly allowed_domains?: readonly Array<string>;
        readonly blocked_domains?: readonly Array<string>;
        readonly engine?: "auto" | "native" | "exa" | "firecrawl" | "parallel" | "openrouter";
        readonly max_content_tokens?: number;
        readonly max_uses?: number;
      };
      readonly type: "openrouter:web_fetch";
    } | {
      readonly parameters?: {
        readonly allowed_domains?: readonly Array<string>;
        readonly engine?: "auto" | "native" | "exa" | "firecrawl" | "parallel" | "perplexity";
        readonly excluded_domains?: readonly Array<string>;
        readonly max_characters?: number;
        readonly max_results?: number;
        readonly max_total_results?: number;
        readonly search_context_size?: "low" | "high" | "medium";
        readonly user_location?: {
          readonly city?: ... | ... | ...;
          readonly country?: ... | ... | ...;
          readonly region?: ... | ... | ...;
          readonly timezone?: ... | ... | ...;
          readonly type?: ... | ...;
        };
      };
      readonly type: "openrouter:web_search";
    } | {
      readonly allowed_domains?: readonly Array<string>;
      readonly engine?: "auto" | "native" | "exa" | "firecrawl" | "parallel" | "perplexity";
      readonly excluded_domains?: readonly Array<string>;
      readonly max_characters?: number;
      readonly max_results?: number;
      readonly max_total_results?: number;
      readonly parameters?: {
        readonly allowed_domains?: readonly Array<string>;
        readonly engine?: "auto" | "native" | "exa" | "firecrawl" | "parallel" | "perplexity";
        readonly excluded_domains?: readonly Array<string>;
        readonly max_characters?: number;
        readonly max_results?: number;
        readonly max_total_results?: number;
        readonly search_context_size?: "low" | "high" | "medium";
        readonly user_location?: {
          readonly city?: ... | ... | ...;
          readonly country?: ... | ... | ...;
          readonly region?: ... | ... | ...;
          readonly timezone?: ... | ... | ...;
          readonly type?: ... | ...;
        };
      };
      readonly search_context_size?: "low" | "high" | "medium";
      readonly type: "web_search" | "web_search_preview" | "web_search_preview_2025_03_11" | "web_search_2025_08_26";
      readonly user_location?: {
        readonly city?: string | null;
        readonly country?: string | null;
        readonly region?: string | null;
        readonly timezone?: string | null;
        readonly type?: "approximate";
      };
    }>;
    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<[body: {
    readonly choices: readonly Array<{
      readonly finish_reason: "length" | "tool_calls" | "stop" | "content_filter" | "error" | null;
      readonly index: number;
      readonly logprobs?: {
        [key: string]: Json;
        readonly content: readonly Array<ReadonlySide<..., ...>> | null;
        readonly refusal?: readonly Array<ReadonlySide<..., ...>> | null;
      } | null;
      readonly message: {
        readonly annotations?: readonly Array<ReadonlySide<..., ...> | ReadonlySide<..., ...> | ReadonlySide<..., ...>> | null;
        readonly audio?: {
          readonly data?: string;
          readonly expires_at?: number;
          readonly id?: string;
          readonly transcript?: string;
        };
        readonly content?: string | readonly Array<{
          readonly cache_control?: ...;
          readonly prompt_cache_breakpoint?: ...;
          readonly text: ...;
          readonly type: ...;
        } | ReadonlySide<..., ...> | ReadonlySide<..., ...> | ReadonlySide<..., ...> | ReadonlySide<..., ...> | ReadonlySide<..., ...>> | null;
        readonly images?: readonly Array<ReadonlySide<{
          readonly image_url: ...;
          readonly type: ...;
        }, "Type">> | null;
        readonly model?: string;
        readonly name?: string;
        readonly reasoning?: string | null;
        readonly reasoning_details?: readonly Array<{
          readonly format?: ...;
          readonly id?: ...;
          readonly index?: ...;
          readonly summary: ...;
          readonly type: ...;
        } | {
          readonly data: ...;
          readonly format?: ...;
          readonly id?: ...;
          readonly index?: ...;
          readonly type: ...;
        } | {
          readonly format?: ...;
          readonly id?: ...;
          readonly index?: ...;
          readonly signature?: ...;
          readonly text?: ...;
          readonly type: ...;
        } | {
          readonly arguments: ...;
          readonly format?: ...;
          readonly id?: ...;
          readonly index?: ...;
          readonly result: ...;
          readonly tool_call_id?: ...;
          readonly tool_name: ...;
          readonly type: ...;
        }>;
        readonly refusal?: string | null;
        readonly role: "assistant";
        readonly tool_calls?: readonly Array<ReadonlySide<{
          readonly function: ...;
          readonly id: ...;
          readonly type: ...;
        }, "Type">>;
      };
    }>;
    readonly created: number;
    readonly id: string;
    readonly model: string;
    readonly object: "chat.completion";
    readonly openrouter_metadata?: {
      readonly attempt: number;
      readonly attempts?: readonly Array<ReadonlySide<{
        readonly model: String;
        readonly provider: String;
        readonly status: Number;
      }, "Type">>;
      readonly endpoints: ReadonlySide<{
        readonly available: $Array<Struct<{
          readonly model: ...;
          readonly provider: ...;
          readonly selected: ...;
        }>>;
        readonly total: Number;
      }, "Type">;
      readonly is_byok: boolean;
      readonly params?: {
        readonly quality_floor?: number;
        readonly throughput_floor?: number;
        readonly version_group?: string;
      };
      readonly pipeline?: readonly Array<{
        readonly cost_usd?: number | null;
        readonly data?: ReadonlySide<..., ...>;
        readonly guardrail_id?: string;
        readonly guardrail_scope?: string;
        readonly name: string;
        readonly summary?: string;
        readonly type: "guardrail" | "plugin" | "server_tools" | "response_healing" | "context_compression";
      }>;
      readonly region: string | null;
      readonly requested: string;
      readonly strategy: "auto" | "fusion" | "fallback" | "direct" | "free" | "latest" | "alias" | "pareto" | "bodybuilder";
      readonly summary: string;
    };
    readonly service_tier?: string | null;
    readonly system_fingerprint: string | null;
    readonly usage?: {
      readonly completion_tokens: number;
      readonly completion_tokens_details?: {
        [key: string]: Json;
        readonly accepted_prediction_tokens?: number | null;
        readonly audio_tokens?: number | null;
        readonly reasoning_tokens?: number | null;
        readonly rejected_prediction_tokens?: number | null;
      } | null;
      readonly cost?: number | null;
      readonly cost_details?: {
        [key: string]: Json;
        readonly upstream_inference_completions_cost: number;
        readonly upstream_inference_cost?: number | null;
        readonly upstream_inference_prompt_cost: number;
      } | null;
      readonly is_byok?: boolean;
      readonly prompt_tokens: number;
      readonly prompt_tokens_details?: {
        [key: string]: Json;
        readonly audio_tokens?: number;
        readonly cache_write_tokens?: number;
        readonly cached_tokens?: number;
        readonly video_tokens?: number;
      } | null;
      readonly server_tool_use_details?: {
        [key: string]: Json;
        readonly tool_calls_executed?: number | null;
        readonly tool_calls_requested?: number | null;
        readonly web_search_requests?: number | null;
      } | null;
      readonly total_tokens: number;
    };
  }, response: HttpClientResponse], AiError>;
  readonly createChatCompletionStream: (options: Omit<typeof Generated.ChatRequest.Encoded, "stream" | "stream_options">) => Effect<[response: HttpClientResponse, stream: Stream<{
    readonly choices: readonly Array<{
      readonly delta: {
        readonly annotations?: readonly Array<... | ... | ...> | null;
        readonly audio?: ChatAudioOutput;
        readonly content?: string | null;
        readonly images?: readonly Array<ReadonlySide<..., ...>> | null;
        readonly reasoning?: string | null;
        readonly reasoning_details?: readonly Array<... | ... | ... | ...>;
        readonly refusal?: string | null;
        readonly role?: "assistant";
        readonly tool_calls?: readonly Array<{
          readonly function?: ...;
          readonly id?: ...;
          readonly index: ...;
          readonly type?: ...;
        }>;
      };
      readonly finish_reason?: "length" | "tool_calls" | "stop" | "content_filter" | "error" | null;
      readonly index: number;
      readonly logprobs?: {
        [key: string]: Json;
        readonly content: readonly Array<...> | null;
        readonly refusal?: readonly Array<...> | null;
      } | null;
    }>;
    readonly created: number;
    readonly error?: {
      readonly code: number;
      readonly message: string;
      readonly metadata?: {
        readonly error_type: "refusal" | "context_length_exceeded" | "max_tokens_exceeded" | "token_limit_exceeded" | "string_too_long" | "authentication" | "permission_denied" | "payment_required" | "rate_limit_exceeded" | "provider_overloaded" | "provider_unavailable" | "invalid_request" | "invalid_prompt" | "not_found" | "precondition_failed" | "payload_too_large" | "unprocessable" | "content_policy_violation" | "invalid_image" | "image_too_large" | "image_too_small" | "unsupported_image_format" | "image_not_found" | "image_download_failed" | "server" | "timeout" | "unmapped";
        readonly provider_code?: string;
      };
    };
    readonly id: string;
    readonly model: string;
    readonly object: "chat.completion.chunk";
    readonly openrouter_metadata?: {
      readonly attempt: number;
      readonly attempts?: readonly Array<ReadonlySide<{
        readonly model: ...;
        readonly provider: ...;
        readonly status: ...;
      }, "Type">>;
      readonly endpoints: ReadonlySide<{
        readonly available: $Array<Struct<...>>;
        readonly total: Number;
      }, "Type">;
      readonly is_byok: boolean;
      readonly params?: {
        readonly quality_floor?: number;
        readonly throughput_floor?: number;
        readonly version_group?: string;
      };
      readonly pipeline?: readonly Array<{
        readonly cost_usd?: ... | ... | ...;
        readonly data?: ... | ...;
        readonly guardrail_id?: ... | ...;
        readonly guardrail_scope?: ... | ...;
        readonly name: string;
        readonly summary?: ... | ...;
        readonly type: ... | ... | ... | ... | ...;
      }>;
      readonly region: string | null;
      readonly requested: string;
      readonly strategy: "auto" | "fusion" | "fallback" | "direct" | "free" | "latest" | "alias" | "pareto" | "bodybuilder";
      readonly summary: string;
    };
    readonly service_tier?: string | null;
    readonly system_fingerprint?: string;
    readonly usage?: {
      readonly completion_tokens: number;
      readonly completion_tokens_details?: {
        [key: string]: Json;
        readonly accepted_prediction_tokens?: number | null;
        readonly audio_tokens?: number | null;
        readonly reasoning_tokens?: number | null;
        readonly rejected_prediction_tokens?: number | null;
      } | null;
      readonly cost?: number | null;
      readonly cost_details?: {
        [key: string]: Json;
        readonly upstream_inference_completions_cost: number;
        readonly upstream_inference_cost?: number | null;
        readonly upstream_inference_prompt_cost: number;
      } | null;
      readonly is_byok?: boolean;
      readonly prompt_tokens: number;
      readonly prompt_tokens_details?: {
        [key: string]: Json;
        readonly audio_tokens?: number;
        readonly cache_write_tokens?: number;
        readonly cached_tokens?: number;
        readonly video_tokens?: number;
      } | null;
      readonly server_tool_use_details?: {
        [key: string]: Json;
        readonly tool_calls_executed?: number | null;
        readonly tool_calls_requested?: number | null;
        readonly web_search_requests?: number | null;
      } | null;
      readonly total_tokens: number;
    };
  }, AiError, never>], AiError>;
}