@bobmatnyc/ai-code-review
Version:
A TypeScript-based tool for automated code reviews using AI models from Google Gemini, Anthropic Claude, and OpenRouter
83 lines (82 loc) • 3.03 kB
TypeScript
/**
* @fileoverview Token counting and cost estimation utilities for AI API usage.
*
* This module provides utilities for estimating token usage and associated costs
* when using various AI APIs including Google's Gemini and OpenRouter models.
* It implements accurate token counting using model-specific tokenizers and maintains
* current pricing information for different AI models.
*
* Key responsibilities:
* - Counting tokens for input and output text using model-specific tokenizers
* - Calculating approximate API costs based on token usage and model
* - Tracking different pricing tiers for various AI models
* - Providing cost information for review outputs
* - Supporting cost-aware decision making for API usage
*
* These utilities help users understand the resource usage and costs associated
* with their code reviews, enabling better planning and resource allocation.
*/
/**
* Utility functions for estimating token counts and costs for AI API calls
*/
/**
* Count tokens in a text using the appropriate tokenizer for a model
* @param text Text to count tokens for
* @param modelName Name of the model (optional)
* @returns Token count
*/
export declare function estimateTokenCount(text: string, modelName?: string): number;
/**
* Calculate the estimated cost for an AI API call
* @param inputTokens Number of input tokens
* @param outputTokens Number of output tokens
* @param modelName Name of the model used
* @returns Estimated cost in USD
*/
export declare function calculateCost(inputTokens: number, outputTokens: number, modelName?: string): number;
/**
* Format a cost value as a currency string
* @param cost Cost value in USD
* @returns Formatted cost string
*/
export declare function formatCost(cost: number): string;
/**
* Cost information for an API call
*/
export interface CostInfo {
inputTokens: number;
outputTokens: number;
totalTokens: number;
estimatedCost: number;
formattedCost: string;
cost: number;
passCount?: number;
perPassCosts?: PassCostInfo[];
contextMaintenanceFactor?: number;
}
/**
* Cost information for a single pass in a multi-pass review
*/
export interface PassCostInfo {
passNumber: number;
inputTokens: number;
outputTokens: number;
totalTokens: number;
estimatedCost: number;
}
/**
* Calculate cost information for an API call based on text
* @param inputText Input text sent to the API
* @param outputText Output text received from the API
* @param modelName Name of the model used
* @returns Cost information
*/
export declare function getCostInfoFromText(inputText: string, outputText: string, modelName?: string): CostInfo;
/**
* Calculate cost information for an API call based on token counts
* @param inputTokens Number of input tokens
* @param outputTokens Number of output tokens
* @param modelName Name of the model used
* @returns Cost information
*/
export declare function getCostInfo(inputTokens: number, outputTokens: number, modelName?: string): CostInfo;