/** * Dynamic model catalog from BlockRun Gateway. * * Pulls GET /api/v1/models once on first use, caches for 5 minutes, and * exposes estimators + category filters. This replaces the hardcoded * pricing/model tables Franklin used to carry — adding a new model or * changing a price on BlockRun's side no longer requires a Franklin * release. Gateway is the single source of truth. * * Per gateway team (2026-04-22): every model returns `billing_mode` and * a mode-specific `pricing` object. Dispatch on billing_mode to compute * an estimated charge. x402 adds a fixed 5% margin on top of base price, * plus a flat $0.001 per-transaction fee on paid calls (Base since * 2026-07-10; Solana instead enforces a $0.001 minimum per call with no * service fee — the flat-fee estimate over-counts there by ≤$0.001, which * is the safe direction for budget tracking). */ export type BillingMode = 'paid' | 'free' | 'flat' | 'per_image' | 'per_second' | 'per_track' | 'per_character' | 'per_generation'; export interface PaidPricing { input: number; output: number; } export interface FlatPricing { flat: number; } export interface PerImagePricing { per_image: number; } export interface PerSecondPricing { per_second: number; default_duration_seconds?: number; max_duration_seconds?: number; } export interface PerTrackPricing { per_track: number; } /** ElevenLabs / ByteDance speech — billed per 1K characters of input text. */ export interface PerCharacterPricing { per_1k_chars: number; max_input_chars?: number; } /** ElevenLabs sound effects — flat charge per generation. */ export interface PerGenerationPricing { per_generation: number; max_duration_seconds?: number; } export type ModelPricing = PaidPricing | FlatPricing | PerImagePricing | PerSecondPricing | PerTrackPricing | PerCharacterPricing | PerGenerationPricing; export interface GatewayModel { id: string; name: string; description?: string; owned_by?: string; billing_mode: BillingMode; categories: string[]; context_window?: number; max_output?: number; pricing: ModelPricing; } /** Test / reset helper. */ export declare function clearGatewayModelsCache(): void; /** * Synchronous, cache-only lookup. Returns null when the catalog has never been * fetched in this process — it never triggers a fetch, so it is safe to call * from the hot path and from sync functions like getContextWindow(). * * Deliberately ignores the TTL: a stale gateway record still beats no record * at all, and the only callers are fallbacks for models we have no static * entry for. Callers must treat the static tables as authoritative — the * gateway's own metadata has been wrong for models we already know. As of * 2026-07-20 it reported max_output 8192 for claude-haiku-4.5 (Anthropic * documents 64000) and 64000 for claude-sonnet-4.6 (documented 128000). * Those two specific numbers are being corrected upstream, so do not treat * them as current — the point that outlives them is that the catalog can be * wrong, and a wrong value here is not cosmetic. * * Correction to an earlier note here: these values are NOT inert metadata. * The gateway clamps with them — Math.min(request.max_tokens, model.maxOutput) * in both the messages and chat/completions handlers — and derives its price * quote from the clamped ceiling. An over-cap request is accepted rather than * rejected: the handler logs "capping to " server-side and continues, * so from here the clamp is invisible until a reply is long enough to hit it. * That is why a short smoke test against a wrongly-capped model looks healthy. * Treat this as "better than a blind default", nothing more. */ export declare function peekGatewayModel(id: string): GatewayModel | null; /** Test helper — seed the cache without a network call. */ export declare function __primeGatewayModelsCache(models: GatewayModel[]): void; /** * Fire-and-forget catalog warm. Populates the cache so the sync peek above has * something to read. Errors are swallowed — every caller has a static fallback. */ export declare function warmGatewayModelsCache(): void; /** * Fetch the model catalog, honoring the 5-minute cache. Concurrent callers * during a cold cache share a single in-flight promise so we don't stampede * the gateway at process start. */ export declare function getGatewayModels(): Promise; /** Return models filtered to a specific category (e.g. 'image', 'video', 'music'). */ export declare function getModelsByCategory(category: string): Promise; /** Find a single model by ID, or null if it's not in the current catalog. */ export declare function findModel(id: string): Promise; /** x402 gateway's fixed margin percentage applied on top of the base price. */ export declare const GATEWAY_MARGIN = 1.05; /** * Flat per-transaction fee (USD) the gateway adds on top of the margined * price on every PAID call (no-op on $0 calls). Introduced upstream * 2026-07-10, briefly $0.002, back to $0.001 since 2026-07-29 * (blockrun src/lib/transaction-fee.ts). */ export declare const GATEWAY_TRANSACTION_FEE_USD = 0.001; export interface EstimateContext { /** Number of images (per_image). Default 1. */ quantity?: number; /** Clip length in seconds (per_second). Falls back to model's default_duration_seconds, then 8. */ duration_seconds?: number; /** Input text length (per_character). Required for a meaningful speech estimate. */ characters?: number; } /** * Estimated USD charge to generate one response from this model under the * given context. Includes the 5% gateway margin and the flat $0.001 * per-transaction fee on paid calls. Returns 0 for free and token-metered * (paid) models where a pre-call estimate isn't meaningful. */ export declare function estimateCostUsd(model: GatewayModel, ctx?: EstimateContext): number; /** Effective default duration for a per_second model (falls back to 8s). */ export declare function defaultDurationSeconds(model: GatewayModel): number; /** Max duration the gateway will accept for a per_second model. */ export declare function maxDurationSeconds(model: GatewayModel): number | null;