import { EventEmitter } from "events"; import { OpenAiCostTrackerCallback } from "../../openai_cost_tracker"; import { OpenAiCostTrackerSqliteEntry, OpenAiCostTrackerSqliteCostSummary } from "./tracker_sqlite_type"; /** * SQLite-backed cost tracker for OpenAI-compatible API calls. * Stores costs in a SQLite database with schema: dateIso, bucketId, provider, modelName, costSpent, costSaved */ export declare class OpenAiCostTrackerSqlite extends EventEmitter { static EVENT: { BUCKET_WRITTEN: string; }; private _database; constructor(dbPath: string); /** * Initialize the database and create schema if needed */ init(): Promise; /** * Close the database connection */ close(): Promise; /** * Get all individual cost tracking records from the database */ getAllRecords(): Promise; /** * Get a JSON summary of costs grouped by bucket and (provider, model) using SQL aggregation */ getSummaryCosts(): Promise; /** * Get the tracker callback function for use with OpenAI cost tracker */ getTrackerCallback(): Promise; /** * Callback to track API costs and store in SQLite. Detects the provider from the request URL. */ private _trackerCallback; private _trackerCallback_Responses_EventStream; /** * Parse a streamed chat.completions SSE response and track its cost. * Chat.completions streams are a sequence of unnamed `data: {...}` JSON chunks terminated by `data: [DONE]`. * Usage is only present when the caller (or our fetch wrapper) set `stream_options.include_usage = true`, * and appears on the last chunk (with an empty `choices` array). */ private _trackerCallback_ChatCompletions_EventStream; /** * Parse a non-streamed chat.completions JSON response and track its cost. */ private _trackerCallback_ChatCompletions_ApplicationJson; /** * Convert a chat.completions `CompletionUsage` to the `Responses.ResponseUsage` shape expected by the calculator. * * In both APIs the cached tokens are a SUBSET of the total prompt/input tokens: chat.completions' * `prompt_tokens` already includes `prompt_tokens_details.cached_tokens`, mirroring the Responses API where * `input_tokens` includes `input_tokens_details.cached_tokens`. The calculator splits the cached subset out * internally, so we pass `prompt_tokens` through as `input_tokens` unchanged (do NOT subtract cached). */ private static _chatUsageToResponsesUsage; private _trackerCallback_Responses_ApplicationJson; private _trackerCallback_Embeddings; private _trackerCallbackPostProcess; }