export type OpenRouterClientConfig = { allowedModels?: readonly string[]; apiKey?: string; batchBaseUrl?: string; baseUrl?: string; fetch?: typeof globalThis.fetch; headers?: HeadersInit | (() => HeadersInit | Promise); tokenSource?: () => Promise | string; /** Default workspace for APIs that accept explicit workspace selection. */ workspaceId?: string; }; export type OpenRouterPKCE = { codeChallenge: string; codeChallengeMethod: "S256"; codeVerifier: string; }; export type OpenRouterAuthorizationUrlOptions = { baseUrl?: string; callbackUrl?: string; codeChallenge?: string; codeChallengeMethod?: "S256" | "plain"; keyLabel?: string; }; export type OpenRouterAuthCodeExchangeRequest = { code: string; code_challenge_method?: "S256" | "plain"; code_verifier?: string; }; export type OpenRouterAuthCodeExchangeResponse = { key: string; user_id: string | null; }; export type OpenRouterCreateAuthCodeRequest = { callback_url: string; code_challenge?: string; code_challenge_method?: "S256" | "plain"; expires_at?: string; key_label?: string; limit?: number; usage_limit_type?: string; workspace_id?: string; }; export type OpenRouterCreateAuthCodeResponse = { data: { app_id: number; created_at: string; id: string; }; }; export type OpenRouterBatchEndpoint = "/v1/chat/completions" | "/v1/responses" | "/v1/messages" | "/v1/embeddings"; export type OpenRouterBatchStatus = "validating" | "in_progress" | "finalizing" | "completed" | "failed" | "expired" | "cancelling" | "cancelled"; export type OpenRouterBatchRequest = { custom_id: string; body: Record; }; export type OpenRouterBatchResult = { custom_id: string; id: string; response?: { body: Record; request_id: string; status_code: number; }; error?: Record; }; export type OpenRouterBatch = { id: string; endpoint: OpenRouterBatchEndpoint; model: string; status: OpenRouterBatchStatus; completion_window?: "24h"; created_at?: string; completed_at?: string | null; request_counts?: { completed: number; failed: number; total: number; }; results?: OpenRouterBatchResult[]; usage?: { completion_tokens: number; cost: number; is_byok: boolean; prompt_tokens: number; total_tokens: number; }; [field: string]: unknown; }; export type OpenRouterCreateBatchRequest = { endpoint: OpenRouterBatchEndpoint; model: string; requests: [OpenRouterBatchRequest, ...OpenRouterBatchRequest[]]; completion_window?: "24h"; }; export type OpenRouterModel = { id: string; name?: string; description?: string; context_length?: number; architecture?: Record; pricing?: OpenRouterPricing; supported_parameters?: string[] | Record; [field: string]: unknown; }; export type OpenRouterPricingKey = "prompt" | "completion" | "request" | "image" | "web_search" | "internal_reasoning" | "input_cache_read" | "input_cache_write"; export type OpenRouterPricing = Partial> & Record; export type OpenRouterCostUnits = Partial>; export type OpenRouterCostEstimate = { components: Partial>; total: number; }; /** Estimate USD cost using OpenRouter's per-unit model pricing fields. */ export declare const estimateOpenRouterCost: (pricing: OpenRouterPricing, units: OpenRouterCostUnits) => OpenRouterCostEstimate; export declare const estimateOpenRouterModelCost: (model: Pick, units: OpenRouterCostUnits) => OpenRouterCostEstimate; export type OpenRouterModelList = { data: OpenRouterModel[]; }; export type OpenRouterModelQuery = { arch?: string; context?: number; distillable?: "false" | "true"; input_modalities?: string; max_price?: number; min_price?: number; model_authors?: string; output_modalities?: string; providers?: string; q?: string; region?: "eu"; supported_parameters?: string; sort?: "pricing-low-to-high" | "pricing-high-to-low" | "context-high-to-low" | "throughput-high-to-low" | "latency-low-to-high" | "most-popular" | "top-weekly" | "newest" | "intelligence-high-to-low" | "design-arena-elo-high-to-low"; zdr?: "true"; }; export type OpenRouterEmbeddingRequest = { model: string; input: string | string[] | number[] | number[][]; dimensions?: number; encoding_format?: "float" | "base64"; provider?: Record; user?: string; }; export type OpenRouterChatRequest = Record & { messages: readonly unknown[]; model: string; stream?: false; }; export type OpenRouterChatResponse = Record & { choices: Array>; id: string; model: string; usage?: Record; }; export type OpenRouterEmbeddingResponse = { data: Array<{ embedding: number[] | string; index: number; object: string; }>; model: string; object: string; usage?: { prompt_tokens: number; total_tokens: number; cost?: number; }; }; export type OpenRouterRerankRequest = { model: string; query: string; documents: Array; top_n?: number; return_documents?: boolean; }; export type OpenRouterRerankResponse = { id?: string; model?: string; results: Array<{ document?: { text: string; }; index: number; relevance_score: number; }>; usage?: Record; }; export type OpenRouterImageRequest = { model: string; prompt: string; n?: number; resolution?: string; aspect_ratio?: string; size?: string; quality?: "auto" | "low" | "medium" | "high"; output_format?: "png" | "jpeg" | "webp" | "svg"; background?: "auto" | "transparent" | "opaque"; output_compression?: number; seed?: number; input_references?: Array>; provider?: Record; stream?: boolean; }; export type OpenRouterImageResponse = { created: number; data: Array<{ b64_json: string; media_type?: string; }>; usage?: Record; }; export type OpenRouterImageModelEndpoint = { allowed_passthrough_parameters: string[]; pricing: Array<{ billable: string; cost_usd: number; unit: "image" | "megapixel" | "token" | string; variant?: string; }>; provider_name: string; provider_slug: string; provider_tag: string | null; supported_parameters: Record; supports_streaming: boolean; }; export type OpenRouterImageModelEndpoints = { endpoints: OpenRouterImageModelEndpoint[]; id: string; }; export type OpenRouterResponsesRequest = Record & { input: unknown; model: string; stream?: boolean; }; export type OpenRouterSpeechRequest = Record & { input: string; model: string; voice: string; }; export type OpenRouterTranscriptionRequest = Record & { input_audio: { data: string; format: string; }; language?: string; model: string; provider?: Record; temperature?: number; }; export type OpenRouterTranscriptionResponse = { text: string; usage: { cost: number; input_tokens: number; output_tokens: number; seconds: number; total_tokens: number; }; }; export type OpenRouterVideoRequest = Record & { model: string; prompt: string; }; export type OpenRouterImageStreamEvent = Record & { type: string; b64_json?: string; media_type?: string; partial_image_index?: number; usage?: Record; }; export type OpenRouterFile = { created_at: string; downloadable: boolean; filename: string; id: string; mime_type: string; size_bytes: number; type: "file"; }; export type OpenRouterFileList = { cursor: string | null; data: OpenRouterFile[]; first_id: string | null; has_more: boolean; last_id: string | null; }; export type OpenRouterVideoJob = { error?: string; generation_id?: string | null; id: string; polling_url?: string; status: "pending" | "in_progress" | "completed" | "failed" | "cancelled" | "expired"; unsigned_urls?: string[]; usage?: { cost?: number; is_byok?: boolean; }; }; export type OpenRouterVideoWebhookEvent = { created_at: string; data: OpenRouterVideoJob & { model?: string | null; }; type: "video.generation.completed" | "video.generation.failed" | "video.generation.cancelled" | "video.generation.expired"; }; export type OpenRouterZdrEndpoint = Record & { context_length: number; model_id: string; model_name: string; name: string; pricing: Record; provider_name: string; supported_parameters: string[]; tag: string; }; export type OpenRouterPresetVersion = { config: Record; created_at: string; creator_id: string; id: string; preset_id: string; system_prompt: string | null; updated_at: string | null; version: number; }; export type OpenRouterPreset = { created_at: string; creator_user_id: string; designated_version: OpenRouterPresetVersion; designated_version_id: string; description: string | null; id: string; name: string; slug: string; status: string; status_updated_at: string | null; updated_at: string | null; workspace_id: string; }; export type OpenRouterPresetResponse = { data: OpenRouterPreset; }; export type OpenRouterPresetVersionResponse = { data: OpenRouterPresetVersion; }; export type OpenRouterPresetInferenceRequest = Record & { model?: string; models?: string[]; }; export type OpenRouterActivityQuery = { api_key_hash?: string; date?: string; user_id?: string; workspace_id?: string; }; export type OpenRouterActivityItem = { byok_usage_inference: number; completion_tokens: number; date: string; endpoint_id: string; model: string; model_permaslug: string; prompt_tokens: number; provider_name: string; reasoning_tokens: number; requests: number; usage: number; workspace_id?: string; }; export type OpenRouterAnalyticsQuery = { metrics: [string, ...string[]]; dimensions?: string[]; filters?: Array<{ field: string; operator: string; value: unknown; }>; granularity?: string; group_limit?: number; limit?: number; order_by?: { direction: "asc" | "desc"; field: string; }; time_range?: { end: string; start: string; }; }; export type OpenRouterAnalyticsResponse = { data: { data: Record[]; metadata: { query_time_ms: number; row_count: number; truncated: boolean; }; }; }; export type OpenRouterAnalyticsMeta = { data: { dimensions: Array<{ display_label: string; name: string; }>; granularities: Array<{ display_label: string; name: string; }>; metrics: Array<{ display_format: string; display_label: string; is_rate: boolean; name: string; }>; operators: Array<{ name: string; value_type: string; }>; }; }; export type OpenRouterTaskClassifications = { data: { as_of: string; classifications: Array<{ category_token_share: number; category_usage_share: number; display_name: string; macro_category: string; models: Array<{ id: string; tag_token_share: number; tag_usage_share: number; }>; tag: string; token_share: number; usage_share: number; }>; macro_categories: Array<{ key: string; label: string; token_share: number; usage_share: number; }>; window_days: 7; }; }; export type OpenRouterWorkspace = { created_at: string; created_by: string; default_image_model: string | null; default_provider_sort: "price" | "throughput" | "latency" | "exacto" | null; default_text_model: string | null; description: string | null; id: string; io_logging_api_key_ids: number[] | null; io_logging_sampling_rate: number; is_data_discount_logging_enabled: boolean; is_observability_broadcast_enabled: boolean; is_observability_io_logging_enabled: boolean; name: string; slug: string; updated_at: string | null; }; export type OpenRouterWorkspaceOptions = { default_image_model?: string | null; default_provider_sort?: OpenRouterWorkspace["default_provider_sort"]; default_text_model?: string | null; description?: string | null; io_logging_api_key_ids?: number[] | null; io_logging_sampling_rate?: number; is_data_discount_logging_enabled?: boolean; is_observability_broadcast_enabled?: boolean; is_observability_io_logging_enabled?: boolean; name?: string; slug?: string; }; export type OpenRouterCreateWorkspaceRequest = OpenRouterWorkspaceOptions & { name: string; slug: string; }; export type OpenRouterWorkspaceBudgetInterval = "daily" | "weekly" | "monthly" | "lifetime"; export type OpenRouterWorkspaceBudget = { created_at: string; id: string; limit_usd: number; reset_interval: OpenRouterWorkspaceBudgetInterval; updated_at: string | null; workspace_id: string; }; export type OpenRouterWorkspaceMember = { created_at: string; id: string; role: string; user_id: string; workspace_id: string; }; export type OpenRouterHttpRequestOptions = Omit & { body?: unknown; headers?: HeadersInit; query?: Record; }; export type OpenRouterClient = ReturnType; export declare const openRouterModelMatchesRule: (model: string, rule: string) => boolean; export declare const generateOpenRouterPKCE: () => Promise; export declare const createOpenRouterAuthorizationUrl: (options?: OpenRouterAuthorizationUrlOptions) => string; /** Exchange a single-use OAuth code. This endpoint intentionally has no API-key authentication. */ export declare const exchangeOpenRouterAuthCode: (body: OpenRouterAuthCodeExchangeRequest, options?: { baseUrl?: string; fetch?: typeof globalThis.fetch; }) => Promise; export declare const createOpenRouterKeyLinks: (key: string, siteUrl?: string) => Promise<{ hash: string; logsUrl: string; settingsUrl: string; }>; /** Verify `X-OpenRouter-Signature` against the exact raw webhook bytes. */ export declare const verifyOpenRouterWebhookSignature: (options: { body: string | Uint8Array; header: string; secret: string; nowSeconds?: number; toleranceSeconds?: number; }) => Promise; export declare const createOpenRouterClient: (config: OpenRouterClientConfig) => { addWorkspaceMembers: (id: string, userIds: readonly string[]) => Promise<{ added_count: number; data: OpenRouterWorkspaceMember[]; }>; createAuthCode: (body: OpenRouterCreateAuthCodeRequest) => Promise; chat: (body: OpenRouterChatRequest) => Promise; createPresetFromChatCompletions: (slug: string, body: OpenRouterPresetInferenceRequest) => Promise; createPresetFromMessages: (slug: string, body: OpenRouterPresetInferenceRequest) => Promise; createPresetFromResponses: (slug: string, body: OpenRouterPresetInferenceRequest) => Promise; createWorkspace: (body: OpenRouterCreateWorkspaceRequest) => Promise<{ data: OpenRouterWorkspace; }>; createBatch: (body: OpenRouterCreateBatchRequest) => Promise; createEmbedding: (body: OpenRouterEmbeddingRequest) => Promise; generateImage: (body: OpenRouterImageRequest) => Promise; deleteFile: (id: string, workspaceId?: string | undefined) => Promise<{ id: string; type: "file_deleted"; }>; deleteWorkspace: (id: string) => Promise<{ deleted: true; }>; deleteWorkspaceBudget: (id: string, interval: OpenRouterWorkspaceBudgetInterval) => Promise<{ deleted: true; }>; downloadFile: (id: string, workspaceId?: string | undefined) => Promise; downloadVideo: (id: string, index?: number) => Promise; generateVideo: (body: OpenRouterVideoRequest) => Promise; getBatch: (id: string) => Promise; getActivity: (query?: OpenRouterActivityQuery) => Promise<{ data: OpenRouterActivityItem[]; }>; getAnalyticsMeta: () => Promise; getCredits: () => Promise<{ data: Record; }>; getCurrentKey: () => Promise<{ data: Record; }>; getFile: (id: string, workspaceId?: string | undefined) => Promise; getGeneration: (id: string) => Promise<{ data: Record; }>; getGenerationContent: (id: string) => Promise>; getModelEndpoints: (model: string) => Promise>; getModel: (model: string) => Promise<{ data: OpenRouterModel; }>; getImageModelEndpoints: (model: string) => Promise; getPreset: (slug: string) => Promise; getPresetVersion: (slug: string, version: number | string) => Promise; getTaskClassifications: (window?: "7d") => Promise; getVideo: (id: string) => Promise; getWorkspace: (id: string) => Promise<{ data: OpenRouterWorkspace; }>; listImageModels: () => Promise; listEmbeddingModels: () => Promise; listFiles: (query?: { cursor?: string; limit?: number; workspace_id?: string; }) => Promise; listModels: (query?: OpenRouterModelQuery) => Promise; listUserModels: () => Promise; listZdrEndpoints: () => Promise<{ data: OpenRouterZdrEndpoint[]; }>; countModels: (outputModalities?: string) => Promise<{ data: { count: number; }; }>; listPresets: (offset?: number, limit?: number) => Promise<{ data: OpenRouterPreset[]; total_count: number; }>; listPresetVersions: (slug: string, offset?: number, limit?: number) => Promise<{ data: OpenRouterPresetVersion[]; total_count: number; }>; listProviders: () => Promise<{ data: Record[]; }>; listRerankModels: () => Promise; listVideoModels: () => Promise; listWorkspaceBudgets: (id: string) => Promise<{ data: OpenRouterWorkspaceBudget[]; }>; listWorkspaces: (offset?: number, limit?: number) => Promise<{ data: OpenRouterWorkspace[]; total_count: number; }>; queryAnalytics: (body: OpenRouterAnalyticsQuery) => Promise; removeWorkspaceMembers: (id: string, userIds: readonly string[]) => Promise<{ data: OpenRouterWorkspaceMember[]; removed_count: number; }>; request: (path: string, options?: OpenRouterHttpRequestOptions) => Promise; requestRaw: (path: string, options?: OpenRouterHttpRequestOptions) => Promise; streamImage: (body: Omit, options?: Omit) => AsyncGenerator; respond: (body: OpenRouterResponsesRequest) => Promise | Promise>; rerank: (body: OpenRouterRerankRequest) => Promise; speak: (body: OpenRouterSpeechRequest) => Promise; transcribe: (body: OpenRouterTranscriptionRequest | FormData) => Promise; uploadFile: (file: Blob, options?: { filename?: string; workspaceId?: string; }) => Promise; updateWorkspace: (id: string, body: OpenRouterWorkspaceOptions) => Promise<{ data: OpenRouterWorkspace; }>; upsertWorkspaceBudget: (id: string, interval: OpenRouterWorkspaceBudgetInterval, limitUsd: number) => Promise<{ data: OpenRouterWorkspaceBudget; }>; waitForBatch: (id: string, options?: { intervalMs?: number; signal?: AbortSignal; timeoutMs?: number; }) => Promise; };