UNPKG

askexperts

Version:

AskExperts SDK: build and use AI experts - ask them questions and pay with bitcoin on an open protocol

92 lines (91 loc) 2.46 kB
import { ModelPricing, PricingResult } from "./ModelPricing.js"; /** * Model information from OpenRouter API */ interface OpenRouterModel { id: string; name: string; pricing: { prompt: number; completion: number; }; [key: string]: any; } /** * OpenRouter API client * Provides access to OpenRouter models and pricing * Implements ModelPricing interface */ export declare class OpenRouter implements ModelPricing { /** * Cached models from OpenRouter API */ private models; /** * Last time models were fetched */ private lastFetchTime; /** * Cache expiry time in milliseconds (1 hour) */ private cacheExpiryTime; /** * Gets all available models * Updates the cache if it's older than the expiry time * * @returns Array of models */ list(): Promise<OpenRouterModel[]>; /** * BTC/USD exchange rate */ private btcUsd?; /** * Creates a new OpenRouter instance */ constructor(); /** * Gets a model by name (id) * Updates the cache if it's older than 1 hour * * @param name - Model ID * @returns Model information or undefined if not found */ model(name: string): Promise<OpenRouterModel | undefined>; /** * Gets pricing information for a model in sats per million tokens * Implements ModelPricing interface * * @param name - Model ID * @returns Promise resolving to pricing information * @throws Error if pricing information cannot be retrieved */ pricing(name: string): Promise<PricingResult>; /** * Force a model cache update */ update(): Promise<void>; /** * Updates the model cache if it's older than the expiry time */ private updateCacheIfNeeded; /** * Fetches models from OpenRouter API */ private fetchModels; /** * Fetches the current BTC/USD exchange rate from Binance */ private fetchBtcUsdRate; /** * Checks if a model is accessible with the given API key * Sends a simple test prompt and verifies the response * * @param model - Model ID to check * @param apiKey - OpenRouter API key * @returns Promise resolving to true if model is accessible, false otherwise */ checkModel(model: string, apiKey: string): Promise<boolean>; } export declare function getOpenRouter(): OpenRouter; export {};