Add Usage struct to parse prompt_tokens, completion_tokens, total_tokens, and cost from every OpenRouter response. Extraction functions now return (result, Option<Usage>) tuples. New ai_usage table stores per-call records with a repository trait and SQL implementation.
13 lines
446 B
SQL
13 lines
446 B
SQL
CREATE TABLE ai_usage (
|
|
id INTEGER PRIMARY KEY,
|
|
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
model TEXT NOT NULL,
|
|
endpoint TEXT NOT NULL,
|
|
prompt_tokens INTEGER NOT NULL,
|
|
completion_tokens INTEGER NOT NULL,
|
|
total_tokens INTEGER NOT NULL,
|
|
cost REAL NOT NULL,
|
|
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
|
|
);
|
|
|
|
CREATE INDEX idx_ai_usage_user_id ON ai_usage(user_id);
|