CREATE TABLE IF NOT EXISTS ai_session (
    id UUID PRIMARY KEY,
    room UUID NOT NULL,
    model UUID NOT NULL,
    version UUID NOT NULL,
    token_input BIGINT NOT NULL DEFAULT 0,
    token_output BIGINT NOT NULL DEFAULT 0,
    latency_ms BIGINT,
    cost DOUBLE PRECISION,
    currency VARCHAR(255),
    error_message TEXT,
    error_code VARCHAR(255),
    created_at TIMESTAMPTZ NOT NULL
);

CREATE INDEX idx_ai_session_room ON ai_session (room);
