g1t/services/billing/migrations/0045_gateway.sql
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 the AI Gateway: Anthropic's Messages API on a workspace's tokens | 1 | -- The AI Gateway: a workspace's own model requests, sent with one of its |
| 2 | -- access tokens to the model proxy (models.g1t.sh/anthropic). See | |
| 3 | -- src/gateway.rs. | |
| 4 | -- | |
| 5 | -- What each model costs on g1t's key, per million tokens of each kind, in | |
| 6 | -- millionths of a dollar: the provider's list price. A request is charged | |
| 7 | -- its tokens at these prices plus the price book's `gateway_models` markup | |
| 8 | -- (0 while the gateway is in beta), drawn from AI credit. A model that is | |
| 9 | -- not here is not offered: the proxy refuses it before it reaches the | |
| 10 | -- provider. Cache writes are the five-minute kind, 1.25 times input. | |
| 11 | CREATE TABLE IF NOT EXISTS gateway_models ( | |
| 12 | model TEXT PRIMARY KEY, | |
| 13 | name TEXT NOT NULL, | |
| 14 | provider TEXT NOT NULL, | |
| 15 | input_micros INTEGER NOT NULL, | |
| 16 | output_micros INTEGER NOT NULL, | |
| 17 | cache_read_micros INTEGER NOT NULL, | |
| 18 | cache_write_micros INTEGER NOT NULL, | |
| 19 | -- The order the docs and the page list them in. | |
| 20 | position INTEGER NOT NULL DEFAULT 0, | |
| 21 | updated_at TEXT NOT NULL | |
| 22 | ); | |
| 23 | ||
| 24 | INSERT OR IGNORE INTO gateway_models (model, name, provider, input_micros, output_micros, cache_read_micros, cache_write_micros, position, updated_at) VALUES | |
| 25 | ('claude-opus-5-5', 'Claude Opus 5.5', 'anthropic', 4000000, 20000000, 200000, 5000000, 1, '2026-10-08T00:00:00Z'), | |
| 26 | ('claude-sonnet-5-5', 'Claude Sonnet 5.5', 'anthropic', 2000000, 10000000, 200000, 2500000, 2, '2026-10-08T00:00:00Z'), | |
| 27 | ('claude-haiku-4-5', 'Claude Haiku 4.5', 'anthropic', 1000000, 5000000, 100000, 1250000, 3, '2026-10-08T00:00:00Z'), | |
| 28 | -- The same model by its dated id, which some tools send. | |
| 29 | ('claude-haiku-4-5-20251001', 'Claude Haiku 4.5', 'anthropic', 1000000, 5000000, 100000, 1250000, 4, '2026-10-08T00:00:00Z'); | |
| 30 | ||
| 31 | -- Every request, for the workspace's AI Gateway page and API: kept 30 days | |
| 32 | -- (retention.rs). Prompts and answers are never stored. What a request was | |
| 33 | -- charged is also a ledger line (task `gateway`, reference its id), which | |
| 34 | -- is what Usage, the statement and invoices read. | |
| 35 | CREATE TABLE IF NOT EXISTS gateway_requests ( | |
| 36 | id TEXT PRIMARY KEY, | |
| 37 | workspace TEXT NOT NULL, | |
| 38 | created_at TEXT NOT NULL, | |
| 39 | token_id TEXT NOT NULL, | |
| 40 | token_name TEXT, | |
| 41 | model TEXT NOT NULL, | |
| 42 | input INTEGER NOT NULL DEFAULT 0, | |
| 43 | output INTEGER NOT NULL DEFAULT 0, | |
| 44 | cache_read INTEGER NOT NULL DEFAULT 0, | |
| 45 | cache_write INTEGER NOT NULL DEFAULT 0, | |
| 46 | cost_micros INTEGER NOT NULL DEFAULT 0, | |
| 47 | charged_micros INTEGER NOT NULL DEFAULT 0, | |
| 48 | status INTEGER NOT NULL, | |
| 49 | own_key INTEGER NOT NULL DEFAULT 0, | |
| 50 | streamed INTEGER NOT NULL DEFAULT 0, | |
| 51 | duration_ms INTEGER NOT NULL DEFAULT 0, | |
| 52 | error TEXT | |
| 53 | ); | |
| 54 | CREATE INDEX IF NOT EXISTS gateway_requests_by_workspace ON gateway_requests (workspace, created_at); | |
| 55 | CREATE INDEX IF NOT EXISTS gateway_requests_by_time ON gateway_requests (created_at); |
This file's history is long; its oldest lines are credited to the oldest commit read.