/** * OpenRouter API client. Supports single-call and multi-step flows with strict validators. */ import type { ExportsMap } from './types.js'; /** Thrown when OpenRouter returns a non-OK HTTP status (used for fallback and feedback). */ export declare class OpenRouterHttpError extends Error { readonly status: number; constructor(status: number, message: string); } /** Map HTTP status to Free LLM Router feedback issue type. */ export declare function issueFromHttpStatus(status: number): 'rate_limited' | 'unavailable' | 'error'; /** Result of auth/availability check: ok, unauthorized (401), or rate-limited (429). */ export type AuthCheckResult = { ok: true; } | { ok: false; reason: 'unauthorized'; } | { ok: false; reason: 'rate_limited'; message: string; }; /** * Minimal request to validate API key and model availability. * Returns { ok: true }, { ok: false, reason: 'unauthorized' } on 401, or { ok: false, reason: 'rate_limited', message } on 429. */ export declare function checkOpenRouterAuth(apiKey: string, model: string): Promise; /** * Try OpenRouter auth with the first model that succeeds. Stops on 401 (invalid key). * Other failures try the next candidate (Free LLM Router free-model list). */ export declare function checkOpenRouterAuthTryModels(apiKey: string, models: string[]): Promise; /** Token usage from OpenRouter API response. */ export interface TokenUsage { prompt_tokens: number; completion_tokens: number; total_tokens: number; } export interface OpenRouterOptions { apiKey: string; model: string; systemPrompt: string; userContent: string; /** Called with usage from the API response when present (for observability). */ onUsage?: (usage: TokenUsage) => void; /** Called with response metadata (usage + sizes) for per-call analytics. */ onMeta?: (meta: { usage?: TokenUsage; responseChars: number; rawJsonChars: number; }) => void; } /** * Strips markdown code fence if present. Handles ```json ... ```, ``` ... ```, and inline text. */ export declare function stripMarkdownJson(raw: string): string; /** * Low-level: send request, return parsed JSON (no validation). * Throws on HTTP error, missing content, or invalid JSON. */ export declare function callOpenRouterRaw(options: OpenRouterOptions): Promise; /** * Call OpenRouter and validate response with a strict validator. Throws on validation failure. */ export declare function callOpenRouterWithValidator(options: OpenRouterOptions, validate: (parsed: unknown) => T, stepName: string): Promise; export type FreeRouterFeedbackIssue = 'error' | 'rate_limited' | 'unavailable'; export interface FreeRouterCallFeedback { requestId?: string; onSuccess: (modelId: string) => void; onIssue: (modelId: string, issue: FreeRouterFeedbackIssue, details?: string) => void; } /** * Try OpenRouter models in order until one returns valid JSON for the step. * Optional feedback hooks for [Free LLM Router](https://freellmrouter.com/docs). */ export declare function callOpenRouterWithValidatorTryModels(base: Omit, models: string[], validate: (parsed: unknown) => T, stepName: string, feedback?: FreeRouterCallFeedback): Promise<{ result: T; modelUsed: string; }>; export interface PackageOverview { summary: string; sideEffects: string[]; keywords: string[]; frameworks: string[]; whenToUse?: string; reasonToUse?: string[]; useCases?: string[]; documentation?: string; relatedPackages?: string[]; extensions?: Record; } /** * Guardrail: Step 1 response must have summary (string), sideEffects, keywords, frameworks (string[]). * Optional: whenToUse, reasonToUse, useCases, documentation, relatedPackages. */ export declare function validatePackageOverview(parsed: unknown): PackageOverview; export interface ExportsStepResult { exports: ExportsMap; hooks: string[]; } /** * Guardrail: Step 2 response must have exports (object) and hooks (string[]). Each export: type, description, hook. */ export declare function validateExportsStep(parsed: unknown): ExportsStepResult; /** * Validator for "list export names only" step. Returns array of export names. */ export declare function validateExportNamesList(parsed: unknown): string[]; //# sourceMappingURL=openrouter.d.ts.map