Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to Overmind are recorded here, in the reader's order: Remove

## [Unreleased]

### Added

- AI Gateway: a tab with requests and tokens by model, requests by provider and errors, once watched. It is free, so it adds no limits.

---

## [0.2.2] - 2026-10-11
Expand Down
7 changes: 7 additions & 0 deletions Modules/Analytics/Tests/ReadPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ struct ReadPlanTests {
#expect(query.contains(#"actionType_in: ["write"]"#))
}

@Test func `should rank AI Gateway's models by how many requests each had`() throws {
let query = plan.breakdowns(try ServiceCatalog.builtIn("ai-gateway"), focus: .everything, at: Fixture.now).query.text

#expect(query.contains("b0: aiGatewayRequestsAdaptiveGroups(limit: 5"))
#expect(query.contains("orderBy: [count_DESC]) { dimensions { model } count }"))
}

@Test func `should chart only KV's reads on the reads chart`() throws {
let query = plan.breakdowns(try ServiceCatalog.builtIn("kv"), focus: .everything, at: Fixture.now).query.text

Expand Down
20 changes: 17 additions & 3 deletions Modules/Monitor/Sources/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ public final class Account {
defer { isRefreshing = false }
if let planReadAt, now.timeIntervalSince(planReadAt) >= Self.planEvery { await readPlan(summary, at: now) }
let reads = limits.map { LimitRead($0.definition, period: plan.period(for: $0.id, at: now)) }
// Only charts are watched (AI Gateway): nothing to read, and an empty query is an error.
guard !reads.isEmpty else {
lastRead = now
lastProblem = nil
return
}
let planned = ReadPlan(account: summary.id).limits(reads, at: now)
let started = Date()
do {
Expand Down Expand Up @@ -262,7 +268,13 @@ public final class Account {
}
let reads = definitions.map { LimitRead($0, period: Self.isKept($0) ? nil : month) }
let planned = ReadPlan(account: summary.id).limits(reads, at: now)
guard let usages = try? planned.usages(from: try await analytics.read(planned.query)) else { return }
let usages: [LimitID: Usage]
if reads.isEmpty {
usages = [:] // nothing priced is watched: the subscription alone
} else {
guard let read = try? planned.usages(from: try await analytics.read(planned.query)) else { return }
usages = read
}
let monthToDate = usages.filter { !Self.isKept(usage: $0.value) }.mapValues(\.used)
let kept = usages.filter { Self.isKept(usage: $0.value) }.mapValues(\.used)
var invoices: [Invoice] = []
Expand Down Expand Up @@ -323,9 +335,11 @@ public final class Account {
public func isWatching(_ serviceID: String) -> Bool { watching.contains { $0.id == serviceID } }

/// Whether the account's plans count any of this service: R2 needs R2 on the account
/// (*not on this account's plans*).
/// (*not on this account's plans*). A service with no limits (AI Gateway) has nothing a plan
/// could miss.
public func isCounted(_ serviceID: String) -> Bool {
services.first { $0.id == serviceID }?.limits.contains { plan.allowance(for: $0.id) != nil } ?? false
guard let service = services.first(where: { $0.id == serviceID }) else { return false }
return service.limits.isEmpty || service.limits.contains { plan.allowance(for: $0.id) != nil }
}

/// Whether *Watching* lets this switch go off: never the last one (law 21).
Expand Down
32 changes: 32 additions & 0 deletions Modules/Monitor/Tests/AccountTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,38 @@ struct AddOnTests {
#expect(account.isCounted("d1"))
}

@Test func `should watch AI Gateway for its charts, without a card or a gap in the plans`() async throws {
let world = World()
let account = try world.account()
await account.connect(token: "tok", at: .utc("2026-10-09T14:20:00"))
let before = account.limits.count

await account.watch("ai-gateway", at: .utc("2026-10-09T14:30:00"))

#expect(account.isWatching("ai-gateway"))
#expect(account.limits.count == before)
#expect(account.isCounted("ai-gateway"))
}

@Test func `should count a refresh as a good read, without asking Cloudflare, when only AI Gateway is watched`() async throws {
let world = World()
let account = try world.account()
await account.connect(token: "tok", at: .utc("2026-10-09T14:20:00"))
await account.watch("ai-gateway", at: .utc("2026-10-09T14:20:00"))
account.unwatch("workers")
account.unwatch("d1")
let before = world.cloudflare.queries.count

await account.refresh(at: .utc("2026-10-09T14:40:00"))
await account.openBill(at: .utc("2026-10-09T14:40:00"))

#expect(account.watching.map(\.id) == ["ai-gateway"])
#expect(account.lastRead == .utc("2026-10-09T14:40:00"))
#expect(account.lastProblem == nil)
#expect(account.bill?.estimate == Money(0, "USD"))
#expect(world.cloudflare.queries.count == before) // an empty query is a GraphQL error
}

@Test func `should never offer R2 as a plan to switch to, and quote Workers Paid with R2 kept`() async throws {
let world = World()
world.cloudflare.ratePlans = ["r2_paid"]
Expand Down
22 changes: 22 additions & 0 deletions Modules/Services/Resources/Services/ai-gateway.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"id": "ai-gateway",
"name": "AI Gateway",
"order": 9,
"watchedByDefault": false,
"look": { "glyph": "⇄", "color": "pink" },
"limits": [],
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
"breakdowns": [
{ "title": "Requests by model · last 24 hours",
"top": { "dataset": "aiGatewayRequestsAdaptiveGroups", "dimension": "model", "measure": "count",
"count": 5, "time": "datetime", "focus": "gateway" } },
{ "title": "Tokens by model · last 24 hours",
"top": { "dataset": "aiGatewayRequestsAdaptiveGroups", "dimension": "model", "measure": "sum.totalTokens",
"count": 5, "time": "datetime", "focus": "gateway" } },
{ "title": "Requests by provider",
"split": { "dataset": "aiGatewayRequestsAdaptiveGroups", "dimension": "provider", "measure": "count",
"time": "datetime", "focus": "gateway" } },
{ "title": "Errors by model",
"top": { "dataset": "aiGatewayErrorsAdaptiveGroups", "dimension": "model", "measure": "count",
"count": 5, "time": "datetime", "focus": "gateway" } }
]
}
15 changes: 12 additions & 3 deletions Modules/Services/Tests/BuiltInServicesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ import Measures
/// The built-in service files, read through the real JSON.
@Suite
struct BuiltInServicesTests {
@Test func `should show Workers, then D1, KV, Queues, R2, Workers AI, Vectorize and Durable Objects`() throws {
#expect(try ServiceCatalog.builtIns().map(\.id) == ["workers", "d1", "kv", "queues", "r2", "ai", "vectorize", "durable-objects"])
@Test func `should show Workers, then D1, KV, Queues, R2, Workers AI, Vectorize, Durable Objects and AI Gateway`() throws {
#expect(try ServiceCatalog.builtIns().map(\.id) == ["workers", "d1", "kv", "queues", "r2", "ai", "vectorize", "durable-objects", "ai-gateway"])
}

@Test func `should know AI Gateway is charts only, free on every plan, ranking models by requests`() throws {
let gateway = try ServiceCatalog.builtIn("ai-gateway")

#expect(gateway.limits.isEmpty)
let source = BreakdownDefinition.Source(dataset: "aiGatewayRequestsAdaptiveGroups", measure: "count", time: .datetime, focus: "gateway")
#expect(gateway.breakdowns.first?.kind == .top(source, dimension: "model", count: 5))
#expect(gateway.watchedByDefault == false)
}

@Test func `should leave every service but Workers and D1 off until the person watches it`() throws {
#expect(try ServiceCatalog.builtIns().filter { !$0.watchedByDefault }.map(\.id)
== ["kv", "queues", "r2", "ai", "vectorize", "durable-objects"])
== ["kv", "queues", "r2", "ai", "vectorize", "durable-objects", "ai-gateway"])
}

@Test func `should know Workers AI counts neurons across every model`() throws {
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Try it without an account: `OVERMIND_DEMO=1 .build/dd/Build/Products/Debug/Overm
| Workers AI (off until watched) | neurons against 10k a day; on Workers Paid each day's overage is priced | neurons per hour, top models |
| Vectorize (off until watched) | queried and stored vector dimensions | queried dimensions per day, top indexes |
| Durable Objects (off until watched) | requests, SQLite rows read and written, storage | requests per hour, requests by outcome |
| AI Gateway (off until watched) | none: it is free on every plan | requests and tokens by model, requests by provider, errors by model |

Plans: Free and Workers Paid, with R2 as an add-on beside either; the Bill tab prices this month on both. Other Cloudflare products
are one JSON file each → [ENGINE_DESIGN](docs/architecture/ENGINE_DESIGN.md).
Expand Down
1 change: 1 addition & 0 deletions Sources/App/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct SettingsView: View {
SettingsRow(title: "\(service.look.glyph) \(service.name)",
note: locked ? "Overmind watches at least one service"
: account.summary != nil && !account.isCounted(service.id) ? "not on this account's plans"
: service.limits.isEmpty ? "free · charts only"
: service.limits.map(\.name).joined(separator: " · ")) {
PopSwitch(isOn: on) {
if on { account.unwatch(service.id) } else { Task { await account.watch(service.id, at: Demo.now ?? .now) } }
Expand Down
1 change: 1 addition & 0 deletions design-concept/overmind-pop.html
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ <h4>Watching</h4>
<div class="set-row unwatched"><span class="svc-i" style="background:var(--pink)">✦</span><div>Workers AI<small>new · neurons</small></div><div class="end"><span class="toggle off" data-svc="Workers AI"><span class="sw-t"></span></span></div></div>
<div class="set-row unwatched"><span class="svc-i" style="background:var(--mint)">⋰</span><div>Vectorize<small>new · queried dimensions · stored dimensions</small></div><div class="end"><span class="toggle off" data-svc="Vectorize"><span class="sw-t"></span></span></div></div>
<div class="set-row unwatched"><span class="svc-i" style="background:var(--sky)">◈</span><div>Durable Objects<small>new · requests · rows read · rows written · storage</small></div><div class="end"><span class="toggle off" data-svc="Durable Objects"><span class="sw-t"></span></span></div></div>
<div class="set-row unwatched"><span class="svc-i" style="background:var(--pink)">⇄</span><div>AI Gateway<small>new · free · charts only</small></div><div class="end"><span class="toggle off" data-svc="AI Gateway"><span class="sw-t"></span></span></div></div>
<div class="set-note" id="watch-note">A service you don't watch is never read: no tab, no card, no warning, no line in the Bill.</div>
</div>
<div class="card set">
Expand Down
Binary file modified design-concept/screenshots/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion docs/architecture/CANONICAL_MODEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ Account ◆ THE ROOT — one per app (v1)
│
├── watching: [ServiceDefinition] "Worker ☑ · D1 ☑ · KV ☐" — DERIVED from the person's choices and
│ each file's watchedByDefault; never empty (law 21)
├── isCounted(service) DERIVED — false when no plan or add-on counts it: "not on this account's plans"
├── isCounted(service) DERIVED — false when no plan or add-on counts any of its limits: "not on this account's plans";
│ true for a service with no limits (AI Gateway: "free · charts only")
├── canUnwatch(service) DERIVED — false for the last one watched: its switch is dimmed
├── estimateCovers: Coverage DERIVED — everything · only(["Worker"]): "est. · Worker only"
├── focus: Focus ◇ .worker(name) · .allWorkers — breakdowns only
Expand Down
6 changes: 6 additions & 0 deletions docs/architecture/ENGINE_DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ by `date`, in one query; `Bill` counts the days whose use reached the allowance
| `split(dataset, dimension, measure)` | a list per value | invocations by `status` |
| `figures([Read])` | a row of numbers | CPU p50 · p99, errors |

A `top` or `split` measures a field (`sum.totalTokens`) or `count`, the number of requests in
each group. **A service may have no limits**: AI Gateway is free on every plan, so its file has
only charts. It adds a tab when watched, and no card, menu bar number, warning or Bill line.

## 5 · The files

```jsonc
Expand Down Expand Up @@ -165,6 +169,8 @@ by `date`, in one query; `Bill` counts the days whose use reached the allowance
| Vectorize limits | Free: 30M queried dimensions a month, 5M stored; Paid: 50M queried a month then $0.01/M, 10M stored then $0.05 per 100M a month | verified on [Vectorize pricing](https://developers.cloudflare.com/vectorize/platform/pricing/), 2026-10-11 |
| Durable Objects | GraphQL `durableObjectsInvocationsAdaptiveGroups` · `sum.requests`; `durableObjectsPeriodicGroups` · `sum.rowsRead` · `sum.rowsWritten` (also `sum.duration`, `sum.activeTime`); `durableObjectsSqlStorageGroups` · `max.storedBytes` per `namespaceId`; all by `datetime` | verified by introspection 2026-10-11; **the unit of `sum.duration` is not**, so GB-s duration waits for a live read on an account using Durable Objects |
| Durable Objects limits | Free per day: 100k requests, SQLite 5M rows read, 100k written, 5 GB stored; Paid per month: 1M requests then $0.15/M, 25B rows read then $0.001/M, 50M written then $1.00/M, 5 GB then $0.20/GB-month | verified on [Durable Objects pricing](https://developers.cloudflare.com/durable-objects/platform/pricing/), 2026-10-11 |
| AI Gateway | GraphQL `aiGatewayRequestsAdaptiveGroups` · `count`, `sum.totalTokens`, `sum.cachedRequests`, `sum.erroredRequests`, by `gateway` · `model` · `provider` · `cached`, `datetime`; also `aiGatewayErrorsAdaptiveGroups`, `aiGatewayCacheAdaptiveGroups`, `aiGatewaySizeAdaptiveGroups` (`max.rows`, logs stored) | verified by introspection and a live read 2026-10-11 (`orderBy: [count_DESC]` accepted; `cached` is 0 or 1, so no chart labels by it) |
| AI Gateway pricing | core features free on every plan; Logpush on Paid 10M a month then $0.05/M; logs stored: legacy Free 100k across gateways, Paid 10M **per gateway**, gateways from 2026-09-24 on Workers Logs pricing. No limit ships: per gateway is no `Allowance` case, and the new pricing is unclear | [AI Gateway pricing](https://developers.cloudflare.com/ai-gateway/reference/pricing/), 2026-10-11 |
| Rate Limiting bindings | none exists | out of scope ([journeys §5](USER_JOURNEYS.md#5--out-of-scope-for-now)) |
| GraphQL budget | 300 queries / 5 min / user; 31 days retention on adaptive datasets | verified |
| Plan | `GET /accounts/{id}/subscriptions`: one entry per rate plan (an account can have *R2 Paid* without *Workers Paid*) | verified |
Expand Down
1 change: 1 addition & 0 deletions docs/architecture/TARGET_ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ ConnectSheet ─ account.connect(token)
```text
Refresher ─ account.refresh(at: now)
limits of the watched services only law 21
none (only AI Gateway watched) → a good read, no query: an empty query is a GraphQL error
plan.period(for: each limit, at: now) law 5
ReadPlan(limits, periods) → one AnalyticsQuery one POST per refresh: the GraphQL API allows 300 per 5 min
AnalyticsAPI.read(query) → answer
Expand Down
3 changes: 2 additions & 1 deletion docs/architecture/USER_JOURNEYS.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ do, the command that lands on the domain, and the node that answers.
| 21b | Kai tries to turn the last service off | the last switch is dimmed: *Overmind watches at least one service* | — | `account.unwatch(…)` says no | `Account` (law 21) |
| 21d | Lee watches *R2* on an account with an R2 subscription | R2 cards (*Class A*, *Class B*, *R2 storage*) against R2's own free tier; the Bill adds R2's lines to the Workers plan's; the header still reads *FREE* or *WORKERS PAID* | — | `account.watch("r2")` | `Plan.addOns` (law 23) |
| 21e | Lee watches *R2* without an R2 subscription | the *R2* row reads *not on this account's plans*; no R2 cards | — | — | `account.isCounted("r2")`: no allowance, so no limit (ENGINE §3) |
| 21f | Lee watches *AI Gateway* | its row reads *free · charts only*; an *AI Gateway* tab: requests by model, tokens by model, requests by provider, errors by model. No card, no menu bar number, no warning: Cloudflare charges nothing for it | reads | `account.watch("ai-gateway")` · `account.open("ai-gateway")` | `Breakdown` only (ENGINE §4) |
| 21c | A new version ships KV | *KV* appears in *Watching*, off; Worker and D1 keep Kai's choices | turns it on if they use KV | `account.watch("kv")` | the service file's `watchedByDefault` |
| 22 | A new version is out | Sparkle's *A new version of Overmind is available* · *Check now* in Settings | installs | — | `Updater` (App, Sparkle) |

Expand Down Expand Up @@ -105,7 +106,7 @@ do, the command that lands on the domain, and the node that answers.

- **Changing anything on Cloudflare.** The token is read-only, and no port has a write call.
- **Several accounts at once.** One connected account; switching is *Connect again*.
- **Services other than Workers and D1, all at once.** They ship one at a time, each off until the person watches it (moment 21c): KV, then Queues and R2 (an add-on plan, law 23), then Workers AI (billed day by day, law 24), Vectorize and Durable Objects, each once its datasets were confirmed by introspection (ENGINE §6): a wrong dataset name would fail the whole refresh. Durable Objects' GB-s duration waits for a live read. Decided 2026-10-11.
- **Services other than Workers and D1, all at once.** They ship one at a time, each off until the person watches it (moment 21c): KV, then Queues and R2 (an add-on plan, law 23), then Workers AI (billed day by day, law 24), Vectorize and Durable Objects, each once its datasets were confirmed by introspection (ENGINE §6): a wrong dataset name would fail the whole refresh. Durable Objects' GB-s duration waits for a live read. AI Gateway is a tab only: it is free, so nothing counts against a plan; its provider spend (`cost`) is not Cloudflare's bill and stays out. Decided 2026-10-11.
- **The `cf` CLI's login.** v1 connects with an API token. `Analytics` and `BillingAPI` are ports, so a `cf`-backed credential or adapter can come later without touching the domain.
- **Changing the plan from Overmind.** Cloudflare's API can (`POST`/`PUT`/`DELETE /accounts/{id}/subscriptions`), but it needs *Billing: Edit*, which can cancel any subscription, and the payment belongs in Cloudflare's own flow. Decided 2026-10-09: a link to Cloudflare's plans page instead; revisit as an opt-in capability once a Paid account can verify it.
- **Rate limits.** Cloudflare keeps no analytics for Rate Limiting bindings, and a request the Worker answers with 429 is a *success* to Workers analytics. Once a Worker writes an Analytics Engine data point per block, a *Blocked by rate limit* breakdown is one entry in `worker.json`. Decided 2026-10-09: not in v1.
3 changes: 2 additions & 1 deletion docs/features/service-tabs/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
description: The Worker, D1, KV, Queues, R2, Workers AI, Vectorize and Durable Objects tabs — the charts and lists each shows, the Worker focus, and the deployment pins. Read when a chart looks empty or different from the dashboard.
description: The Worker, D1, KV, Queues, R2, Workers AI, Vectorize, Durable Objects and AI Gateway tabs — the charts and lists each shows, the Worker focus, and the deployment pins. Read when a chart looks empty or different from the dashboard.
---

# Service tabs
Expand All @@ -14,6 +14,7 @@ description: The Worker, D1, KV, Queues, R2, Workers AI, Vectorize and Durable O
| **Workers AI** | neurons per hour today · top models by neurons · the neurons limit (10k a day on both plans) |
| **Vectorize** | queried dimensions per day (7 days) · top indexes · queried and stored dimensions |
| **Durable Objects** | requests per hour today · requests by outcome · requests, SQLite rows read and written, storage. The Worker focus narrows the request charts. GB-s duration isn't counted yet |
| **AI Gateway** | requests by model · tokens by model · requests by provider · errors by model, over the last 24 hours. Charts only: AI Gateway is free, so it has no limits, cards or warnings |

- **The focus** (*leaderboard ▾ · All Workers*) narrows the charts to one Worker. The limits never change: Cloudflare counts them across the account.
- **Pins** (*d605dc93*) mark when a version of the focused Worker went live.
Expand Down
Loading
Loading