|
1 | | --- LLM call audit log: per-request observability for the Ask TaskNebula |
2 | | --- RAG endpoint and other AI surfaces. We track org/user, model, a hash |
3 | | --- of the prompt (raw text is never stored), token counts, USD cost and |
4 | | --- end-to-end latency so admins can monitor spend and abuse without |
5 | | --- exposing user content. |
6 | | - |
7 | | -CREATE TABLE IF NOT EXISTS "llm_call_audit" ( |
8 | | - "id" text PRIMARY KEY NOT NULL, |
9 | | - "org_id" text, |
10 | | - "user_id" text, |
11 | | - "endpoint" text NOT NULL DEFAULT 'ask', |
12 | | - "model" text NOT NULL, |
13 | | - "prompt_hash" text NOT NULL, |
14 | | - "input_tokens" integer NOT NULL DEFAULT 0, |
15 | | - "output_tokens" integer NOT NULL DEFAULT 0, |
16 | | - "cost_usd" numeric(10, 6) NOT NULL DEFAULT 0, |
17 | | - "latency_ms" integer NOT NULL DEFAULT 0, |
18 | | - "status" text NOT NULL DEFAULT 'success', |
19 | | - "metadata" jsonb NOT NULL DEFAULT '{}'::jsonb, |
20 | | - "created_at" timestamp DEFAULT now() NOT NULL |
21 | | -); |
22 | | - |
23 | | -CREATE INDEX IF NOT EXISTS "llm_call_audit_org_idx" |
24 | | - ON "llm_call_audit" USING btree ("org_id"); |
25 | | -CREATE INDEX IF NOT EXISTS "llm_call_audit_user_idx" |
26 | | - ON "llm_call_audit" USING btree ("user_id"); |
27 | | -CREATE INDEX IF NOT EXISTS "llm_call_audit_created_at_idx" |
28 | | - ON "llm_call_audit" USING btree ("created_at"); |
29 | | -CREATE INDEX IF NOT EXISTS "llm_call_audit_endpoint_created_idx" |
30 | | - ON "llm_call_audit" USING btree ("endpoint", "created_at"); |
| 1 | +-- NO-OP: llm_call_audit is created by 0033_ai_cost_guard with a richer |
| 2 | +-- schema (organization_id, provider, cached_tokens, feature, errorMessage, |
| 3 | +-- INSERT-only triggers, etc.). This migration is kept in the journal as a |
| 4 | +-- placeholder so the idx sequence stays contiguous after the 2026-05 |
| 5 | +-- worktree merge. |
| 6 | +SELECT 1; |
0 commit comments