CREATE TABLE IF NOT EXISTS kamicode_usage (
    id_usage INT UNSIGNED NOT NULL AUTO_INCREMENT,
    id_user INT UNSIGNED NOT NULL,
    id_session INT UNSIGNED NULL,
    model VARCHAR(190) NULL,
    tokens_in INT UNSIGNED NOT NULL DEFAULT 0,
    tokens_out INT UNSIGNED NOT NULL DEFAULT 0,
    tokens_cached INT UNSIGNED NOT NULL DEFAULT 0,
    cost DECIMAL(12,6) NOT NULL DEFAULT 0,
    latency_ms INT UNSIGNED NOT NULL DEFAULT 0,
    ok TINYINT UNSIGNED NOT NULL DEFAULT 1,
    error VARCHAR(255) NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id_usage),
    KEY idx_user_date (id_user, created_at),
    KEY idx_model (model)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
