Skip to content

g1t/services/billing/migrations/0047_gateway_formats.sql

72 lines5,771 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Merge branch 'main' into worktree-agent-a69aeabc4b0deeb971-- The AI Gateway in both formats, open models on g1t's account, and the
2-- workspace's own providers. See src/gateway.rs.
3--
4-- Prices per million tokens in millionths of a dollar, each provider's list
5-- price on 2026-10-07: Anthropic's pricing page and Cloudflare's Workers AI
6-- pricing page. Charged at these plus the price book's `gateway_models`
7-- markup (0 in beta).
8
9-- Cache writes that live an hour cost twice the input price; five-minute
10-- ones (cache_write_micros) 1.25 times.
11ALTER TABLE gateway_models ADD COLUMN cache_write_1h_micros INTEGER NOT NULL DEFAULT 0;
12-- `chat`, or `embeddings` for a model that only embeds text.
13ALTER TABLE gateway_models ADD COLUMN kind TEXT NOT NULL DEFAULT 'chat';
14-- A model priced by the prompt's length: a request whose prompt (input,
15-- cache read and cache write tokens) is longer than `threshold` tokens is
16-- charged entirely at the over_ prices. 0: one price.
17ALTER TABLE gateway_models ADD COLUMN threshold INTEGER NOT NULL DEFAULT 0;
18ALTER TABLE gateway_models ADD COLUMN over_input_micros INTEGER NOT NULL DEFAULT 0;
19ALTER TABLE gateway_models ADD COLUMN over_output_micros INTEGER NOT NULL DEFAULT 0;
20ALTER TABLE gateway_models ADD COLUMN over_cache_read_micros INTEGER NOT NULL DEFAULT 0;
21ALTER TABLE gateway_models ADD COLUMN over_cache_write_micros INTEGER NOT NULL DEFAULT 0;
22ALTER TABLE gateway_models ADD COLUMN over_cache_write_1h_micros INTEGER NOT NULL DEFAULT 0;
23
24-- Cache reads on Sonnet 5.5 are 0.05 times input ($0.10), not 0.1 times
25-- as 0045 had them. Opus 5.5 ($0.20) and Haiku 4.5 ($0.10) were right.
26UPDATE gateway_models SET cache_read_micros = 100000, updated_at = '2026-10-07T00:00:00Z' WHERE model = 'claude-sonnet-5-5';
27UPDATE gateway_models SET cache_write_1h_micros = 8000000 WHERE model = 'claude-opus-5-5';
28UPDATE gateway_models SET cache_write_1h_micros = 4000000 WHERE model = 'claude-sonnet-5-5';
29UPDATE gateway_models SET cache_write_1h_micros = 2000000 WHERE model IN ('claude-haiku-4-5', 'claude-haiku-4-5-20251001');
30
31-- Claude Haiku 5.5, priced by prompt length: up to 100,000 prompt tokens
32-- $0.10 in, $0.50 out, cache reads $0.01, writes $0.125 (5 min) and $0.20
33-- (1 h); over that, $0.50, $2.50, $0.05, $0.625 and $1. Listed first: the
34-- cheapest Claude, and the one to start with.
35INSERT OR IGNORE INTO gateway_models
36 (model, name, provider, kind, input_micros, output_micros, cache_read_micros, cache_write_micros, cache_write_1h_micros,
37 threshold, over_input_micros, over_output_micros, over_cache_read_micros, over_cache_write_micros, over_cache_write_1h_micros,
38 position, updated_at) VALUES
39 ('claude-haiku-5-5', 'Claude Haiku 5.5', 'anthropic', 'chat', 100000, 500000, 10000, 125000, 200000,
40 100000, 500000, 2500000, 50000, 625000, 1000000, 0, '2026-10-07T00:00:00Z');
41
42-- Open models on Workers AI, through g1t's Cloudflare account. Workers AI
43-- has no prompt-cache price: cached tokens, where a model reports them,
44-- cost what input does.
45INSERT OR IGNORE INTO gateway_models
46 (model, name, provider, kind, input_micros, output_micros, cache_read_micros, cache_write_micros, cache_write_1h_micros, position, updated_at) VALUES
47 ('@cf/zai-org/glm-5.3-flash', 'GLM-5.3 Flash', 'workers-ai', 'chat', 150000, 500000, 150000, 150000, 150000, 10, '2026-10-07T00:00:00Z'),
48 ('@cf/openai/gpt-oss-20b', 'gpt-oss-20b', 'workers-ai', 'chat', 200000, 300000, 200000, 200000, 200000, 11, '2026-10-07T00:00:00Z'),
49 ('@cf/meta/llama-4-scout-17b-16e-instruct', 'Llama 4 Scout', 'workers-ai', 'chat', 270000, 850000, 270000, 270000, 270000, 12, '2026-10-07T00:00:00Z'),
50 ('@cf/openai/gpt-oss-120b', 'gpt-oss-120b', 'workers-ai', 'chat', 350000, 750000, 350000, 350000, 350000, 13, '2026-10-07T00:00:00Z'),
51 ('@cf/mistralai/mistral-small-3.1-24b-instruct', 'Mistral Small 3.1', 'workers-ai', 'chat', 351000, 555000, 351000, 351000, 351000, 14, '2026-10-07T00:00:00Z'),
52 ('@cf/deepseek-ai/deepseek-v4-flash-0731', 'DeepSeek V4 Flash', 'workers-ai', 'chat', 440000, 1320000, 440000, 440000, 440000, 15, '2026-10-07T00:00:00Z'),
53 ('@cf/nvidia/nemotron-3-120b-a12b', 'Nemotron 3 120B', 'workers-ai', 'chat', 500000, 1500000, 500000, 500000, 500000, 16, '2026-10-07T00:00:00Z'),
54 ('@cf/moonshotai/kimi-k2.6', 'Kimi K2.6', 'workers-ai', 'chat', 950000, 4000000, 950000, 950000, 950000, 17, '2026-10-07T00:00:00Z'),
55 ('@cf/deepseek-ai/deepseek-v4-pro-0813', 'DeepSeek V4 Pro', 'workers-ai', 'chat', 1320000, 3960000, 1320000, 1320000, 1320000, 18, '2026-10-07T00:00:00Z'),
56 ('@cf/zai-org/glm-5.3', 'GLM-5.3', 'workers-ai', 'chat', 1400000, 4400000, 1400000, 1400000, 1400000, 19, '2026-10-07T00:00:00Z'),
57 -- Embeddings: input tokens only.
58 ('@cf/baai/bge-m3', 'BGE M3', 'workers-ai', 'embeddings', 12000, 0, 12000, 12000, 12000, 30, '2026-10-07T00:00:00Z'),
59 ('@cf/baai/bge-base-en-v1.5', 'BGE Base (English)', 'workers-ai', 'embeddings', 67000, 0, 67000, 67000, 67000, 31, '2026-10-07T00:00:00Z');
60
61-- What each request was sent as and who served it, for the log.
62-- `anthropic` (Messages) or `openai` (Chat Completions, Embeddings).
63ALTER TABLE gateway_requests ADD COLUMN format TEXT NOT NULL DEFAULT 'anthropic';
64-- `anthropic` or `workers-ai` on g1t's key; on the workspace's own, its
65-- connection's provider (`openai`, `openai_endpoint`…). Every request
66-- before this went to Anthropic's API or an endpoint speaking it.
67ALTER TABLE gateway_requests ADD COLUMN provider TEXT NOT NULL DEFAULT '';
68-- On the workspace's own provider: the connection's name.
69ALTER TABLE gateway_requests ADD COLUMN connection TEXT;
70-- Of cache_write, the tokens written to the hour-long cache.
71ALTER TABLE gateway_requests ADD COLUMN cache_write_1h INTEGER NOT NULL DEFAULT 0;
72UPDATE gateway_requests SET provider = 'anthropic' WHERE provider = '' AND status < 400;

This file's history is long; its oldest lines are credited to the oldest commit read.