OptionalapiKey: stringOpenRouter API key (defaults to OPENROUTER_API_KEY env var)
Checks if a model ID is valid and available
The model ID to validate
True if the model is valid, false otherwise
Fetches all available models from OpenRouter with their pricing information Results are cached in Redis for 3 hours to avoid excessive API calls
Array of available models with pricing details
Sends a chat completion request to OpenRouter and returns the response with usage data and cost Automatically fetches pricing data if not already cached Records usage to the database within a MongoDB transaction Checks subscription status and reports metered overage to Stripe
The model ID to use (e.g., "anthropic/claude-3.5-sonnet")
Array of chat messages
The user ID to associate with this usage record (required)
Object containing the AI's response text, token usage, cost, and detailed cost breakdown
Sends a chat completion request with tool definitions to OpenRouter Used by the agent loop for LLM-driven tool orchestration
The model ID to use (e.g., "anthropic/claude-sonnet-4.5")
Array of chat messages (including tool results)
Array of tool definitions
The user ID to associate with this usage record
Object containing the AI's response, tool calls, usage, and cost
Calculates the cost of a completed API request based on token usage and model pricing Uses Decimal.js for precise financial calculations without floating-point errors Automatically fetches pricing data if not already cached
The model ID that was used
Token usage information from the API response
Cost in USD as a number
Calculates detailed cost breakdown for a completed API request Uses Decimal.js for precise financial calculations without floating-point errors Automatically fetches pricing data if not already cached
The model ID that was used
Token usage information from the API response
Detailed cost breakdown with prompt, completion, and total costs
Clears the pricing and models cache from Redis, forcing fresh data on next request
Transcribes audio to text using Replicate's Whisper model Records usage to the database and calculates cost based on predict_time
Either a data URI (data:audio/...) or a URL to the audio file
The user ID to associate with this usage record (required)
Optionallanguage: stringOptional language hint (e.g., "en", "es")
Object containing transcribed text, duration, and cost
Creates a new AIManager instance configured for OpenRouter