/** * OpenRouter LLM Provider * * Implements LLMProvider interface for OpenRouter's unified API. * Extends OpenAICompatibleProvider for shared functionality. * * @example * ```typescript * const provider = createOpenRouterProvider({ * model: 'anthropic/claude-sonnet-4-6', * apiKey: process.env.OPENROUTER_API_KEY * }); * ``` * * @remarks * - Requires valid OpenRouter API key * - Default model is meta-llama/llama-3.1-8b-instruct * - Provides access to 100+ models from multiple providers * - Includes custom headers for ranking and attribution */ import type { ChatOptions } from './types.js'; import { ProviderError } from '../errors.js'; import { OpenAICompatibleProvider } from './openai-compatible.js'; /** * Configuration for OpenRouterProvider */ export interface OpenRouterProviderConfig { /** OpenRouter API key (falls back to OPENROUTER_API_KEY env var) */ apiKey?: string; /** Base URL for OpenRouter API (default: https://openrouter.ai/api) */ baseUrl?: string; /** Default model to use (default: meta-llama/llama-3.1-8b-instruct) */ model?: string; /** Default max tokens (default: 4096) */ maxTokens?: number; /** Request timeout in milliseconds (default: 120000) */ timeout?: number; /** Site URL for OpenRouter rankings (optional) */ siteUrl?: string; /** Site name for OpenRouter rankings (optional) */ siteName?: string; /** Optional token estimator (e.g., tiktoken) for debug payload */ estimateTokens?: (text: string) => number; } /** * OpenRouter LLM Provider * * Provides streaming chat completion via OpenRouter's unified API. * Access 100+ models from Claude, GPT, Llama, Mistral, and more. */ export declare class OpenRouterProvider extends OpenAICompatibleProvider { readonly name = "openrouter"; private readonly apiKey; private readonly siteUrl?; private readonly siteName?; constructor(config?: OpenRouterProviderConfig); /** * OpenRouter authentication with Bearer token and custom headers */ protected getAuthHeaders(): Record; /** * OpenRouter chat completions endpoint (OpenAI-compatible) */ protected getEndpointPath(): string; /** * OpenRouter uses standard OpenAI body format */ protected buildProviderSpecificBody(_options?: ChatOptions): Record; /** * Map HTTP errors with OpenRouter-specific messages */ protected mapHttpError(status: number, body: string, _model: string): ProviderError; /** * Map connection errors with OpenRouter-specific messages */ protected mapConnectionError(_error: Error): ProviderError; } /** * Create an OpenRouter provider instance * * @example * ```typescript * // Using environment variable (OPENROUTER_API_KEY) * const provider = createOpenRouterProvider(); * * // With explicit API key * const provider = createOpenRouterProvider({ apiKey: 'sk-or-...' }); * * // With custom model and site attribution * const provider = createOpenRouterProvider({ * model: 'anthropic/claude-sonnet-4-6', * siteUrl: 'https://myapp.com', * siteName: 'My App' * }); * ``` */ export declare function createOpenRouterProvider(config?: OpenRouterProviderConfig): OpenRouterProvider;