An open-source, faster Devin alternative
TypeScript
docs: add reserved capacity preview pages
Igor Zalutskibf752c4a2b1b
diff --git a/docs/api-reference/capacity/cancel-block.mdx b/docs/api-reference/capacity/cancel-block.mdxnew file mode 100644index 00000000..3118e469--- /dev/null+++ b/docs/api-reference/capacity/cancel-block.mdx@@ -0,0 +1,31 @@+---+title: 'Cancel Block'+api: 'DELETE /api/capacity/blocks/{blockId}'+---++<Info>+ **Coming soon.** Reserved capacity is not yet available. See the+ [Reserved Capacity overview](/reserved-capacity/overview).+</Info>++Cancel one capacity block by ID. Equivalent to a one-block+`POST /api/capacity/cancellations` call.++<ParamField path="blockId" type="string" required>+ Block UUID. Must belong to the authenticated org and be currently cancellable.+</ParamField>++<ResponseExample>+```http 204+HTTP/1.1 204 No Content+```++```json 409 blocks_not_cancellable+{+ "error": "blocks_not_cancellable",+ "blocks": [+ { "blockId": "9f67b8f7-7b91-4d2d-b1cb-19d0d0a14562", "reason": "not_cancellable" }+ ]+}+```+</ResponseExample>diff --git a/docs/api-reference/capacity/create-cancellations.mdx b/docs/api-reference/capacity/create-cancellations.mdxnew file mode 100644index 00000000..2d6e8954--- /dev/null+++ b/docs/api-reference/capacity/create-cancellations.mdx@@ -0,0 +1,45 @@+---+title: 'Create Cancellations'+api: 'POST /api/capacity/cancellations'+---++<Info>+ **Coming soon.** Reserved capacity is not yet available. See the+ [Reserved Capacity overview](/reserved-capacity/overview).+</Info>++Cancel one or more capacity blocks by ID. Atomic all-or-nothing — if any+block in the request cannot be cancelled, none are cancelled. No+`skipIneligible` mode; retry with a refreshed ID list instead.++Send an `Idempotency-Key` header so retries return the original result.++<ParamField body="blockIds" type="string[]" required>+ Block UUIDs to cancel. Must belong to the authenticated org and be+ currently cancellable. Duplicates are de-duplicated server-side.+</ParamField>++<ResponseExample>+```json 200+{+ "status": "cancelled",+ "cancelledBlocks": 2,+ "cancelledGb": 2,+ "cancelledGbMinutes": 30,+ "blocks": [+ { "blockId": "9f67b8f7-7b91-4d2d-b1cb-19d0d0a14562", "startsAt": "2026-04-25T09:00:00Z", "endsAt": "2026-04-25T09:15:00Z" },+ { "blockId": "3a94b5e6-2e4f-4a2b-b58a-53c41d61d9bd", "startsAt": "2026-04-25T09:15:00Z", "endsAt": "2026-04-25T09:30:00Z" }+ ]+}+```++```json 409 blocks_not_cancellable+{+ "error": "blocks_not_cancellable",+ "blocks": [+ { "blockId": "9f67b8f7-7b91-4d2d-b1cb-19d0d0a14562", "reason": "not_cancellable" },+ { "blockId": "3a94b5e6-2e4f-4a2b-b58a-53c41d61d9bd", "reason": "already_started" }+ ]+}+```+</ResponseExample>diff --git a/docs/api-reference/capacity/create-reservations.mdx b/docs/api-reference/capacity/create-reservations.mdxnew file mode 100644index 00000000..e4528fa3--- /dev/null+++ b/docs/api-reference/capacity/create-reservations.mdx@@ -0,0 +1,75 @@+---+title: 'Create Reservations'+api: 'POST /api/capacity/reservations'+---++<Info>+ **Coming soon.** Reserved capacity is not yet available. See the+ [Reserved Capacity overview](/reserved-capacity/overview).+</Info>++Reserve capacity across one or more 15-minute UTC intervals. Atomic across+the request — either every interval is booked or nothing is. See+[Reserving and cancelling](/reserved-capacity/reserving-and-cancelling) for+the full write contract.++Send an `Idempotency-Key` header so retries return the original result. Same+key with a different body returns `idempotency_key_conflict`.++<ParamField body="intervals" type="array" required>+ One entry per 15-minute interval to reserve.+</ParamField>++<ParamField body="intervals[].startsAt" type="string" required>+ Interval start. RFC 3339, UTC, aligned to 15 minutes (`:00`, `:15`, `:30`, `:45`).+</ParamField>++<ParamField body="intervals[].endsAt" type="string" required>+ Interval end. Must equal `startsAt + 15 minutes`. Multi-interval spans are rejected.+</ParamField>++<ParamField body="intervals[].capacityGb" type="integer" required>+ Positive integer. Number of 1 GB blocks to create for this interval.+</ParamField>++<ResponseExample>+```json 200+{+ "status": "applied",+ "blockDuration": "PT15M",+ "reservedBlocks": 2,+ "cancellableBlocks": 1,+ "nonCancellableBlocks": 1,+ "blocks": [+ {+ "blockId": "9f67b8f7-7b91-4d2d-b1cb-19d0d0a14562",+ "startsAt": "2026-04-25T09:00:00Z",+ "endsAt": "2026-04-25T09:15:00Z",+ "isCancellable": false,+ "cancellableUntil": null+ },+ {+ "blockId": "3a94b5e6-2e4f-4a2b-b58a-53c41d61d9bd",+ "startsAt": "2026-04-25T09:00:00Z",+ "endsAt": "2026-04-25T09:15:00Z",+ "isCancellable": true,+ "cancellableUntil": "2026-04-24T15:00:00Z"+ }+ ]+}+```++```json 409 capacity_not_available+{+ "error": "capacity_not_available",+ "intervals": [+ {+ "startsAt": "2026-04-25T09:00:00Z",+ "requestedGb": 80,+ "reservableGb": 30,+ "reason": "insufficient_capacity"+ }+ ]+}+```+</ResponseExample>diff --git a/docs/api-reference/capacity/get-block.mdx b/docs/api-reference/capacity/get-block.mdxnew file mode 100644index 00000000..1530330a--- /dev/null+++ b/docs/api-reference/capacity/get-block.mdx@@ -0,0 +1,28 @@+---+title: 'Get Block'+api: 'GET /api/capacity/blocks/{blockId}'+---++<Info>+ **Coming soon.** Reserved capacity is not yet available. See the+ [Reserved Capacity overview](/reserved-capacity/overview).+</Info>++Read one capacity block by ID. Block identity is scoped by org — the same+UUID in another org is a different block and is invisible to this caller.++<ParamField path="blockId" type="string" required>+ Block UUID.+</ParamField>++<ResponseExample>+```json 200+{+ "blockId": "3a94b5e6-2e4f-4a2b-b58a-53c41d61d9bd",+ "startsAt": "2026-04-25T09:00:00Z",+ "endsAt": "2026-04-25T09:15:00Z",+ "isCancellable": true,+ "cancellableUntil": "2026-04-24T15:00:00Z"+}+```+</ResponseExample>diff --git a/docs/api-reference/capacity/get-calendar.mdx b/docs/api-reference/capacity/get-calendar.mdxnew file mode 100644index 00000000..90484cc8--- /dev/null+++ b/docs/api-reference/capacity/get-calendar.mdx@@ -0,0 +1,46 @@+---+title: 'Get Calendar'+api: 'GET /api/capacity/calendar'+---++<Info>+ **Coming soon.** Reserved capacity is not yet available. See the+ [Reserved Capacity overview](/reserved-capacity/overview).+</Info>++Return a planning snapshot of 15-minute UTC intervals in the requested window.+One row per interval, with reservable, already-reserved, and policy fields.+See [Reading the calendar](/reserved-capacity/calendar) for field semantics.++<ParamField query="from" type="string" required>+ Window start. RFC 3339, aligned to 15 minutes, UTC.+</ParamField>++<ParamField query="to" type="string" required>+ Window end. RFC 3339, aligned to 15 minutes, UTC.+</ParamField>++<ResponseExample>+```json 200+{+ "generatedAt": "2026-04-24T12:00:00Z",+ "staleAt": "2026-04-24T12:00:10Z",+ "blockDuration": "PT15M",+ "timezone": "UTC",+ "earliestReservableStart": "2026-04-24T12:30:00Z",+ "intervals": [+ {+ "startsAt": "2026-04-25T09:00:00Z",+ "endsAt": "2026-04-25T09:15:00Z",+ "reservationLimitGb": 300,+ "reservedGb": 80,+ "reservableGb": 220,+ "newReservationNonCancellableRatio": "0.25",+ "cancellableGb": 55,+ "nonCancellableGb": 25,+ "usableGb": 120+ }+ ]+}+```+</ResponseExample>diff --git a/docs/api-reference/capacity/list-blocks.mdx b/docs/api-reference/capacity/list-blocks.mdxnew file mode 100644index 00000000..9b0d872c--- /dev/null+++ b/docs/api-reference/capacity/list-blocks.mdx@@ -0,0 +1,57 @@+---+title: 'List Blocks'+api: 'GET /api/capacity/blocks'+---++<Info>+ **Coming soon.** Reserved capacity is not yet available. See the+ [Reserved Capacity overview](/reserved-capacity/overview).+</Info>++List capacity blocks held by the authenticated org, filtered by time window+and optionally by cancellability.++<ParamField query="from" type="string">+ Return blocks whose `startsAt` is at or after this timestamp. RFC 3339, UTC.+</ParamField>++<ParamField query="to" type="string">+ Return blocks whose `startsAt` is strictly before this timestamp. RFC 3339, UTC.+</ParamField>++<ParamField query="isCancellable" type="boolean">+ When `true`, return only currently-cancellable blocks. When `false`, only+ non-cancellable blocks. Omit for both.+</ParamField>++<ParamField query="cursor" type="string">+ Pagination cursor from a previous response's `nextCursor`.+</ParamField>++<ParamField query="limit" type="integer">+ Maximum blocks per page. Server-defined ceiling applies.+</ParamField>++<ResponseExample>+```json 200+{+ "blocks": [+ {+ "blockId": "9f67b8f7-7b91-4d2d-b1cb-19d0d0a14562",+ "startsAt": "2026-04-25T09:00:00Z",+ "endsAt": "2026-04-25T09:15:00Z",+ "isCancellable": false,+ "cancellableUntil": null+ },+ {+ "blockId": "3a94b5e6-2e4f-4a2b-b58a-53c41d61d9bd",+ "startsAt": "2026-04-25T09:00:00Z",+ "endsAt": "2026-04-25T09:15:00Z",+ "isCancellable": true,+ "cancellableUntil": "2026-04-24T15:00:00Z"+ }+ ],+ "nextCursor": null+}+```+</ResponseExample>diff --git a/docs/api-reference/capacity/reserve-block.mdx b/docs/api-reference/capacity/reserve-block.mdxnew file mode 100644index 00000000..ef2b4fd8--- /dev/null+++ b/docs/api-reference/capacity/reserve-block.mdx@@ -0,0 +1,57 @@+---+title: 'Reserve Block'+api: 'PUT /api/capacity/blocks/{blockId}'+---++<Info>+ **Coming soon.** Reserved capacity is not yet available. See the+ [Reserved Capacity overview](/reserved-capacity/overview).+</Info>++Reserve exactly one 1 GB block with a caller-chosen UUID. Equivalent to a+one-block `POST /api/capacity/reservations` call. Because the ID is+caller-supplied, replaying the same request body is naturally idempotent.++Block IDs are never recycled: once a block is cancelled or settled, its ID+cannot be reused.++<ParamField path="blockId" type="string" required>+ Caller-generated UUID. Must be a valid v4 UUID. Org-scoped — the same+ UUID used by another org is a different block.+</ParamField>++<ParamField body="startsAt" type="string" required>+ Interval start. RFC 3339, UTC, aligned to 15 minutes.+</ParamField>++<ParamField body="endsAt" type="string" required>+ Must equal `startsAt + 15 minutes`.+</ParamField>++<ResponseExample>+```json 200+{+ "blockId": "3a94b5e6-2e4f-4a2b-b58a-53c41d61d9bd",+ "startsAt": "2026-04-25T09:00:00Z",+ "endsAt": "2026-04-25T09:15:00Z",+ "isCancellable": true,+ "cancellableUntil": "2026-04-24T15:00:00Z"+}+```++```json 409 block_id_conflict+{+ "error": "block_id_conflict",+ "blockId": "3a94b5e6-2e4f-4a2b-b58a-53c41d61d9bd",+ "reason": "existing_block_has_different_interval"+}+```++```json 409 block_id_not_reusable+{+ "error": "block_id_not_reusable",+ "blockId": "3a94b5e6-2e4f-4a2b-b58a-53c41d61d9bd",+ "reason": "previously_cancelled"+}+```+</ResponseExample>diff --git a/docs/mint.json b/docs/mint.jsonindex d10cbda2..2c00d7aa 100644--- a/docs/mint.json+++ b/docs/mint.json@@ -74,6 +74,16 @@"sandboxes/elasticity"]},+ {+ "group": "Reserved Capacity",+ "pages": [+ "reserved-capacity/overview",+ "reserved-capacity/concepts",+ "reserved-capacity/calendar",+ "reserved-capacity/reserving-and-cancelling",+ "reserved-capacity/usage-and-overage"+ ]+ },{"group": "Agents","pages": [@@ -219,6 +229,18 @@"api-reference/usage/list-tags"]},+ {+ "group": "Reserved Capacity",+ "pages": [+ "api-reference/capacity/get-calendar",+ "api-reference/capacity/create-reservations",+ "api-reference/capacity/create-cancellations",+ "api-reference/capacity/list-blocks",+ "api-reference/capacity/get-block",+ "api-reference/capacity/reserve-block",+ "api-reference/capacity/cancel-block"+ ]+ },{"group": "Commands","pages": [diff --git a/docs/reserved-capacity/calendar.mdx b/docs/reserved-capacity/calendar.mdxnew file mode 100644index 00000000..aac546fd--- /dev/null+++ b/docs/reserved-capacity/calendar.mdx@@ -0,0 +1,194 @@+---+title: "Reading the Calendar"+description: "Preview reservable capacity, planned terms, and what you already hold"+---++<Info>+ **Coming soon.** Reserved capacity is not yet available. The contract below+ may change before launch.+</Info>++The calendar is how you plan. It answers three questions at once, per+15-minute interval:++1. How much GB can I still reserve here?+2. If I reserved right now, how much of that new reservation would lock+ immediately?+3. How much do I already hold here, and how much of it can I still cancel?++The calendar never holds capacity. It's a snapshot read; write validation is+always authoritative.++## Request++```bash curl+curl "https://app.opencomputer.dev/api/capacity/calendar?from=2026-04-25T09:00:00Z&to=2026-04-25T12:00:00Z" \+ -H "X-API-Key: $OPENCOMPUTER_API_KEY"+```++| Query param | Required | Notes |+| --- | --- | --- |+| `from` | yes | Window start, aligned to 15 minutes, UTC. |+| `to` | yes | Window end, aligned to 15 minutes, UTC. |++## Response++```json+{+ "generatedAt": "2026-04-24T12:00:00Z",+ "staleAt": "2026-04-24T12:00:10Z",+ "blockDuration": "PT15M",+ "timezone": "UTC",+ "earliestReservableStart": "2026-04-24T12:30:00Z",+ "intervals": [+ {+ "startsAt": "2026-04-25T09:00:00Z",+ "endsAt": "2026-04-25T09:15:00Z",+ "reservationLimitGb": 300,+ "reservedGb": 80,+ "reservableGb": 220,+ "newReservationNonCancellableRatio": "0.25",+ "cancellableGb": 55,+ "nonCancellableGb": 25,+ "usableGb": 120+ }+ ]+}+```++### Top-level fields++| Field | Meaning |+| --- | --- |+| `generatedAt` | When the server computed this snapshot. |+| `staleAt` | After this, refresh before using the snapshot for planning. |+| `blockDuration` | Always `PT15M` in v1. |+| `timezone` | Always `UTC` in v1. |+| `earliestReservableStart` | First interval currently eligible for new reservations. Reservations before this time are rejected. |++### Per-interval fields++| Field | Meaning |+| --- | --- |+| `startsAt`, `endsAt` | The 15-minute UTC interval. |+| `reservationLimitGb` | Maximum GB this org may hold in this interval under policy. |+| `reservedGb` | Total GB this org already has reserved in this interval. |+| `reservableGb` | Additional GB the server would currently accept. **This is the number to plan against.** |+| `newReservationNonCancellableRatio` | Decimal string in `[0, 1]`: fraction of a *new* reservation that would lock immediately. |+| `cancellableGb` | Already-reserved GB this org can still cancel at `generatedAt`. |+| `nonCancellableGb` | Already-reserved GB this org can no longer cancel at `generatedAt`. |+| `usableGb` | Reserved capacity available for actual usage in this interval. |++Invariant: `reservedGb == cancellableGb + nonCancellableGb`.++## `reservableGb` is the planning field++Everything you need to decide "can I reserve 50 GB at 9am?" is in+`reservableGb`. The other fields are context:++- `reservationLimitGb` explains the policy cap behind `reservableGb`.+- `reservedGb` tells you how much you already have.+- The limit minus `reservedGb` gives your remaining headroom under the+ policy cap. The server may still reduce `reservableGb` below that headroom+ because of platform capacity.++## `newReservationNonCancellableRatio` is planning-only++This field describes what would happen if you made a new reservation against+this snapshot right now. It is not a property of any individual block.++The cancellable portion is `1 - newReservationNonCancellableRatio`.++Example: you reserve 80 GB at `09:00` with ratio `0.25`:++```text+20 GB locked immediately (cancellableUntil = null)+60 GB cancellable until assigned expiries+```++The exact `cancellableUntil` on each of those 60 GB comes from the policy+ladder applied at booking time. You can read the assigned values per block+via [`GET /api/capacity/blocks`](/api-reference/capacity/list-blocks).++## `staleAt` is a freshness marker, not a hold++The calendar snapshot is cheap and immediate. `staleAt` tells clients when to+refresh before planning again, but capacity can change at any moment — another+tenant (or you, in another tab) may reserve or cancel between+`generatedAt` and your write.++This is fine. Writes are atomic and validation is authoritative: if capacity+moved out from under you, the write returns `capacity_not_available` and you+re-read and retry.++## Race patterns++### Plan then write++```text+GET /api/capacity/calendar → reservableGb: 220+POST /api/capacity/reservations capacityGb: 80 → applied+```++### Plan then write, lost race++```text+GET /api/capacity/calendar → reservableGb: 50+POST /api/capacity/reservations capacityGb: 80 → rejected with reservableGb: 30+```++On rejection, read the calendar again and either:++- Re-submit with the actual current `reservableGb`, or+- Accept the smaller amount via multiple writes at different intervals, or+- Bail out — not all demand fits.++V1 does not accept a "reserve up to N, at least M" shape. Keep retries+explicit in client code.++### Multi-interval request, partial conflict++```text+POST /api/capacity/reservations+ intervals: [+ 09:00 → 09:15, 80 GB+ 09:15 → 09:30, 80 GB # only 30 available+ ]+→ rejected; no blocks created+```++Multi-interval writes are atomic. If any interval fails, none are booked.+Split your request if you want partial success.++## Choosing the window++The calendar supports arbitrary `from`–`to` ranges aligned to the 15-minute+grid. Practical guidance:++- For interactive planning UIs, pull a day or a week at a time; render a+ heatmap of `reservableGb`.+- For scheduled reservation scripts, query just the intervals you're about+ to write — don't pull a week if you only need two hours.+- For large time ranges, expect the response to scale linearly (`4 × hours`+ rows). Paginate or chunk your own queries if you need months.++## What the calendar does *not* tell you++- Exact `cancellableUntil` per block. Those are assigned at booking time+ from the policy ladder. Read blocks after you reserve.+- What other customers hold. Numbers are org-scoped.+- Future policy changes. Terms you book under are frozen on your blocks.++## Where to go next++<CardGroup cols={2}>+ <Card title="Reserving and cancelling" icon="lock" href="/reserved-capacity/reserving-and-cancelling">+ The write flows, idempotency, atomicity.+ </Card>+ <Card title="Concepts" icon="shapes" href="/reserved-capacity/concepts">+ Vocabulary: blocks, intervals, ladder.+ </Card>+ <Card title="Get calendar endpoint" icon="code" href="/api-reference/capacity/get-calendar">+ Full request/response reference.+ </Card>+</CardGroup>diff --git a/docs/reserved-capacity/concepts.mdx b/docs/reserved-capacity/concepts.mdxnew file mode 100644index 00000000..3a3367ed--- /dev/null+++ b/docs/reserved-capacity/concepts.mdx@@ -0,0 +1,167 @@+---+title: "Concepts"+description: "Blocks, intervals, the calendar, and the cancellability ladder"+---++<Info>+ **Coming soon.** Reserved capacity is not yet available. The contract below+ may change before launch.+</Info>++A small vocabulary carries the whole API. Learn these five terms and the rest+reads itself.++## Block++A **block** is one GB of reserved memory for one 15-minute UTC interval. It is+the atomic unit: there is no "half-block," no "multi-hour block," no "flexible+block." Every reservation is a whole number of blocks.++Each block is a first-class resource with its own UUID:++```json+{+ "blockId": "9f67b8f7-7b91-4d2d-b1cb-19d0d0a14562",+ "startsAt": "2026-04-25T09:00:00Z",+ "endsAt": "2026-04-25T09:15:00Z",+ "isCancellable": true,+ "cancellableUntil": "2026-04-24T21:00:00Z"+}+```++You can read, cancel, and reserve individual blocks by ID. A bigger+reservation is just more blocks.++## Interval++An **interval** is a 15-minute window on the UTC quarter-hour grid.++| Field | Meaning |+| --- | --- |+| `startsAt` | Inclusive start. Always ends in `:00`, `:15`, `:30`, or `:45` with zero seconds. |+| `endsAt` | Exclusive end. Always `startsAt + 15 minutes`. |++Half-open intervals (`[startsAt, endsAt)`) mean two adjacent reservations+never overlap and never leave gaps:++```text+09:00 ────────────── 09:15 ────────────── 09:30+ interval A interval B+ startsAt: 09:00 startsAt: 09:15+ endsAt: 09:15 endsAt: 09:30+```++A reservation that spans multiple intervals is a list of adjacent interval+entries, not a single range. The API accepts this explicitly:++```json+{+ "intervals": [+ { "startsAt": "2026-04-25T09:00:00Z", "endsAt": "2026-04-25T09:15:00Z", "capacityGb": 4 },+ { "startsAt": "2026-04-25T09:15:00Z", "endsAt": "2026-04-25T09:30:00Z", "capacityGb": 4 },+ { "startsAt": "2026-04-25T09:30:00Z", "endsAt": "2026-04-25T09:45:00Z", "capacityGb": 4 }+ ]+}+```++## Calendar++The **calendar** is the planning read model. Given a time range, it returns+one row per 15-minute interval with the numbers you need to decide what to+reserve:++| Field | Meaning |+| --- | --- |+| `reservableGb` | GB you could add to this interval right now. |+| `reservationLimitGb` | The policy cap on how much you can hold in this interval. |+| `reservedGb` | What you already hold in this interval. |+| `cancellableGb` | Of `reservedGb`, how much you can still cancel now. |+| `nonCancellableGb` | Of `reservedGb`, how much is already locked. |+| `newReservationNonCancellableRatio` | Fraction of a new reservation that would lock immediately. |+| `usableGb` | Reserved capacity available for usage in this interval. |++The calendar does not hold capacity — it's a snapshot. See+[Reading the calendar](/reserved-capacity/calendar) for the full shape and+planning patterns.++## Cancellability ladder++**Cancellability** is assigned at booking time, per block, from a policy+ladder. It looks roughly like this:++| Lead time | Fraction of new reservation locked | Fraction cancellable |+| --- | --- | --- |+| ≥ 24h before `startsAt` | 0% | 100% |+| 12h – 24h | 25% | 75% |+| 6h – 12h | 50% | 50% |+| < 6h | 100% | 0% |++The exact numbers are a server-side policy and may evolve. What's invariant:++1. Every block gets a `cancellableUntil` timestamp when it's created. It+ never changes afterwards.+2. A later policy change **does not** mutate existing blocks. The terms you+ booked under are the terms you keep.+3. The ratio is computed per interval at reservation time — closer+ intervals produce stricter terms automatically.++The calendar shows the *aggregate* ratio for a new reservation. To see the+exact per-block `cancellableUntil` values after booking, read the blocks:++```bash curl+curl https://app.opencomputer.dev/api/capacity/blocks?from=...&to=... \+ -H "X-API-Key: $OPENCOMPUTER_API_KEY"+```++## Reservation and cancellation (operations, not objects)++There is no public "reservation" or "cancellation" object. Those are+*operations* that create or retire blocks.++```text+POST /api/capacity/reservations → creates N blocks+POST /api/capacity/cancellations → retires N blocks+```++This means:++- There's no `reservationId` to look up later.+- There's no "edit this reservation" endpoint — cancel the specific blocks+ you want to remove.+- There's no "cancel a whole reservation" endpoint — you cancel by block ID.++If you need to track that a group of blocks came from one write, store the+block IDs client-side. The server does not keep that grouping.++## Usage allocation++Reserved capacity is **pooled** by `(org, memory resource, 15-minute+interval)`. In each interval:++```text+overageGb = max(usedGb - reservedGb, 0)+```++There is no per-sandbox attribution. If two sandboxes run together and+consume 14 GB against 10 reserved, 10 GB count as reserved and 4 GB as+overage — it doesn't matter which sandbox "used" which.++Unused reserved capacity inside its interval is not refunded. Cancel blocks+*before* their `cancellableUntil` expires if you decide you don't need them.++## Where to go next++<CardGroup cols={2}>+ <Card title="Reading the calendar" icon="calendar" href="/reserved-capacity/calendar">+ How to plan reservations before you write.+ </Card>+ <Card title="Reserving and cancelling" icon="lock" href="/reserved-capacity/reserving-and-cancelling">+ Write flows, idempotency, atomicity.+ </Card>+ <Card title="Usage and overage" icon="gauge" href="/reserved-capacity/usage-and-overage">+ How reserved capacity consumes actual usage.+ </Card>+ <Card title="API reference" icon="code" href="/api-reference/capacity/get-calendar">+ Every endpoint with full request/response shapes.+ </Card>+</CardGroup>diff --git a/docs/reserved-capacity/overview.mdx b/docs/reserved-capacity/overview.mdxnew file mode 100644index 00000000..85b06600--- /dev/null+++ b/docs/reserved-capacity/overview.mdx@@ -0,0 +1,154 @@+---+title: "Reserved Capacity"+description: "Commit to future compute capacity in 15-minute blocks and pay less for what you run inside them"+---++<Info>+ **Coming soon.** Reserved capacity is not yet available. These pages describe+ the forthcoming v1 API. The contract may change before launch. [Book a+ call](https://cal.com/team/digger/opencomputer-founder-chat) to be notified+ when it ships or to influence the design.+</Info>++Reserved capacity lets you pre-commit to compute you will use later, so+OpenComputer can plan for it instead of holding a margin against uncertain+demand. In exchange for telling us what you need and when, you get lower+effective pricing on that usage and a predictable ceiling on what you can run.++Pure on-demand usage is still fine — reserve only what you already know you+need. Reservations are additive to on-demand: reserved capacity is consumed+first, and any usage above it falls back to on-demand rates.++## The unit is one GB for fifteen minutes++Everything in the API is built from a single atomic unit:++```text+1 block = 1 GB of memory for one 15-minute UTC interval+```++Intervals start on the quarter-hour in UTC: `:00`, `:15`, `:30`, `:45`. A+two-hour, 16 GB reservation is `2 × 4 × 16 = 128` blocks. You don't address+that as one multi-hour object — it's 128 concrete, individually-cancellable+blocks.++This looks like a lot of rows for a small reservation, and that's+intentional: every block has its own identity, its own cancellation deadline,+and its own lifecycle. There are no hidden compound objects.++## A small example++Reserve 2 GB from 9:00 to 9:15 UTC tomorrow:++```bash curl+curl -X POST https://app.opencomputer.dev/api/capacity/reservations \+ -H "X-API-Key: $OPENCOMPUTER_API_KEY" \+ -H "Idempotency-Key: demo-reservation-1" \+ -H "Content-Type: application/json" \+ -d '{+ "intervals": [+ {+ "startsAt": "2026-04-25T09:00:00Z",+ "endsAt": "2026-04-25T09:15:00Z",+ "capacityGb": 2+ }+ ]+ }'+```++The response is two block rows, each with its own `blockId` and its own+`cancellableUntil` deadline:++```json+{+ "status": "applied",+ "reservedBlocks": 2,+ "blocks": [+ {+ "blockId": "9f67b8f7-7b91-4d2d-b1cb-19d0d0a14562",+ "startsAt": "2026-04-25T09:00:00Z",+ "endsAt": "2026-04-25T09:15:00Z",+ "isCancellable": true,+ "cancellableUntil": "2026-04-24T21:00:00Z"+ },+ {+ "blockId": "3a94b5e6-2e4f-4a2b-b58a-53c41d61d9bd",+ "startsAt": "2026-04-25T09:00:00Z",+ "endsAt": "2026-04-25T09:15:00Z",+ "isCancellable": true,+ "cancellableUntil": "2026-04-24T15:00:00Z"+ }+ ]+}+```++Cancel one of them later:++```bash curl+curl -X DELETE \+ https://app.opencomputer.dev/api/capacity/blocks/9f67b8f7-7b91-4d2d-b1cb-19d0d0a14562 \+ -H "X-API-Key: $OPENCOMPUTER_API_KEY"+```++That's the whole model. Everything else in these pages is detail on *when*+you can cancel, *how* you preview available capacity, and *how* usage is+allocated against the blocks you hold.++## Why reserve instead of running on-demand?++Reservations and on-demand capacity solve different problems:++| | On-demand | Reserved |+| --- | --- | --- |+| Cost per GB-minute | Higher (includes reserve-margin premium) | Lower |+| Commitment | None | Progressive — closer to the interval, less cancellable |+| Availability | Subject to platform headroom | Guaranteed for the interval you booked |+| Best for | Unpredictable or bursty workloads | Nightly batch jobs, scheduled runs, known traffic patterns |++If you already know you will run 50 GB of agents at 3am every night, tell us+the day before, and you get better pricing plus a guarantee the capacity is+there. If your workload is "whatever users ask for," stay on-demand.++## Cancellation gets stricter as the interval approaches++Each block has a `cancellableUntil` timestamp, set at the moment you reserve.+As the reservation window gets closer, a larger fraction of any *new*+reservation becomes non-cancellable immediately. Policy details:++| Lead time from reservation to `startsAt` | Portion of a new reservation locked immediately |+| --- | --- |+| ≥ 24 hours | Small (e.g. 0%) |+| 12–24 hours | Moderate (e.g. 25%) |+| 6–12 hours | Larger (e.g. 50%) |+| < 6 hours | Full — entire reservation locked immediately |++The exact ladder is a policy, not an API shape. Read the calendar to see what+fraction of a new reservation would lock right now.++## Where to go next++<CardGroup cols={2}>+ <Card title="Concepts" icon="shapes" href="/reserved-capacity/concepts">+ The vocabulary: blocks, intervals, calendar, policy ladder.+ </Card>+ <Card title="Reading the calendar" icon="calendar" href="/reserved-capacity/calendar">+ Plan reservations before you write.+ </Card>+ <Card title="Reserving and cancelling" icon="lock" href="/reserved-capacity/reserving-and-cancelling">+ The write flows, idempotency, atomicity, retries.+ </Card>+ <Card title="Usage and overage" icon="gauge" href="/reserved-capacity/usage-and-overage">+ How reserved capacity consumes actual sandbox usage.+ </Card>+</CardGroup>++<Tip>+ Full endpoint reference: [`/api/capacity/*`](/api-reference/capacity/get-calendar).+ Design doc: [`001-reserved-capacity-squares.md`](https://github.com/diggerhq/ws-pricing/blob/main/design/001-reserved-capacity-squares.md).+</Tip>++<Note>+ **Pricing is intentionally out of scope here.** This API manages capacity+ rights only. Prices, invoices, and recurring discounts will be announced+ separately before launch.+</Note>diff --git a/docs/reserved-capacity/reserving-and-cancelling.mdx b/docs/reserved-capacity/reserving-and-cancelling.mdxnew file mode 100644index 00000000..9fe8dd40--- /dev/null+++ b/docs/reserved-capacity/reserving-and-cancelling.mdx@@ -0,0 +1,259 @@+---+title: "Reserving and Cancelling"+description: "Write flows, idempotency, atomicity, and retry patterns"+---++<Info>+ **Coming soon.** Reserved capacity is not yet available. The contract below+ may change before launch.+</Info>++All write flows are direct: read the calendar, submit a write, handle+rejection. No intents, no quotes, no shopping cart, no confirmation step.++## Reserve a batch of intervals++One call creates blocks across one or more 15-minute intervals. Atomic across+the whole request — either everything is booked or nothing is.++```bash curl+curl -X POST https://app.opencomputer.dev/api/capacity/reservations \+ -H "X-API-Key: $OPENCOMPUTER_API_KEY" \+ -H "Idempotency-Key: nightly-agents-2026-04-25" \+ -H "Content-Type: application/json" \+ -d '{+ "intervals": [+ { "startsAt": "2026-04-25T09:00:00Z", "endsAt": "2026-04-25T09:15:00Z", "capacityGb": 16 },+ { "startsAt": "2026-04-25T09:15:00Z", "endsAt": "2026-04-25T09:30:00Z", "capacityGb": 16 }+ ]+ }'+```++Response (success):++```json+{+ "status": "applied",+ "reservedBlocks": 32,+ "cancellableBlocks": 24,+ "nonCancellableBlocks": 8,+ "blocks": [+ {+ "blockId": "9f67b8f7-7b91-4d2d-b1cb-19d0d0a14562",+ "startsAt": "2026-04-25T09:00:00Z",+ "endsAt": "2026-04-25T09:15:00Z",+ "isCancellable": false,+ "cancellableUntil": null+ }+ // ... one entry per block+ ]+}+```++### Validation rules++| Rule | Behavior |+| --- | --- |+| `startsAt` and `endsAt` are UTC and 15-minute aligned | Reject misaligned intervals. |+| `endsAt == startsAt + 15 minutes` | Reject multi-interval spans; enumerate them instead. |+| `capacityGb` is a positive integer | Reject zero, negative, or fractional. |+| `startsAt >= earliestReservableStart` | Reject intervals that are too soon to reserve. |+| Requested capacity fits current `reservableGb` | Reject instead of overbooking. |+| `Idempotency-Key` is stable for retries | Replaying returns the original result. |++### Rejected write++```json+{+ "error": "capacity_not_available",+ "intervals": [+ {+ "startsAt": "2026-04-25T09:00:00Z",+ "requestedGb": 80,+ "reservableGb": 30,+ "reason": "insufficient_capacity"+ },+ {+ "startsAt": "2026-04-25T09:15:00Z",+ "requestedGb": 80,+ "reservableGb": 0,+ "reason": "too_soon"+ }+ ]+}+```++The response lists every problematic interval, so the client can retry with+adjusted numbers in a single round-trip.++Common rejection reasons:++| `reason` | Meaning |+| --- | --- |+| `insufficient_capacity` | Request exceeds current `reservableGb`. |+| `too_soon` | `startsAt` is before `earliestReservableStart`. |+| `misaligned` | `startsAt`/`endsAt` not on the 15-minute grid. |+| `reservation_limit_exceeded` | Exceeds the org's `reservationLimitGb` for the interval. |++## Reserve exactly one block with a caller-chosen ID++For single-block reservations where you want idempotency keyed to a UUID you+generate client-side:++```bash curl+curl -X PUT \+ https://app.opencomputer.dev/api/capacity/blocks/3a94b5e6-2e4f-4a2b-b58a-53c41d61d9bd \+ -H "X-API-Key: $OPENCOMPUTER_API_KEY" \+ -H "Content-Type: application/json" \+ -d '{+ "startsAt": "2026-04-25T09:00:00Z",+ "endsAt": "2026-04-25T09:15:00Z"+ }'+```++This is equivalent to reserving `capacityGb: 1` for that interval. Because+you chose the ID, replaying the same `PUT` with the same body is naturally+idempotent — the same key always names the same block.++| Case | Behavior |+| --- | --- |+| No block exists for `(org, blockId)` | Validate capacity and create the block. |+| Existing live block with same `startsAt`/`endsAt` | Return the existing block; no new GB reserved. |+| Existing live block with different `startsAt`/`endsAt` | Reject `block_id_conflict`. |+| Block was cancelled or settled | Reject `block_id_not_reusable`. IDs are never recycled. |+| Same UUID exists in another org | Ignored. Block identity is scoped by org — same UUID in two orgs means two different blocks. |++## Idempotency keys++Both `POST /reservations` and `POST /cancellations` accept an+`Idempotency-Key` header. The server stores the key with the request body+hash and the response. Retries with the same key and body return the cached+response — even if the original write succeeded, the retry is safe.++| Behavior | Response |+| --- | --- |+| Same key, same body | Cached response from first call. |+| Same key, different body | `idempotency_key_conflict`. |+| No key | Request is processed normally; retries are the client's problem. |++Always send a stable `Idempotency-Key` for reservation and cancellation+writes. Build it from a deterministic name for the operation, e.g.+`reserve-nightly-agents-2026-04-25`, so your retry loop sends the same key.++## Cancel blocks by ID++Cancellation targets specific block IDs. It never targets a time range or a+GB amount. Atomic all-or-nothing: if any block in the request is not+cancellable, none are cancelled.++```bash curl+curl -X POST https://app.opencomputer.dev/api/capacity/cancellations \+ -H "X-API-Key: $OPENCOMPUTER_API_KEY" \+ -H "Idempotency-Key: cancel-nightly-2026-04-25" \+ -H "Content-Type: application/json" \+ -d '{+ "blockIds": [+ "9f67b8f7-7b91-4d2d-b1cb-19d0d0a14562",+ "3a94b5e6-2e4f-4a2b-b58a-53c41d61d9bd"+ ]+ }'+```++Response (success):++```json+{+ "status": "cancelled",+ "cancelledBlocks": 2,+ "cancelledGb": 2,+ "cancelledGbMinutes": 30,+ "blocks": [+ { "blockId": "9f67b8f7-7b91-4d2d-b1cb-19d0d0a14562", "startsAt": "2026-04-25T09:00:00Z", "endsAt": "2026-04-25T09:15:00Z" },+ { "blockId": "3a94b5e6-2e4f-4a2b-b58a-53c41d61d9bd", "startsAt": "2026-04-25T09:15:00Z", "endsAt": "2026-04-25T09:30:00Z" }+ ]+}+```++Response (rejection):++```json+{+ "error": "blocks_not_cancellable",+ "blocks": [+ { "blockId": "9f67b8f7-7b91-4d2d-b1cb-19d0d0a14562", "reason": "not_cancellable" },+ { "blockId": "3a94b5e6-2e4f-4a2b-b58a-53c41d61d9bd", "reason": "already_started" }+ ]+}+```++Common rejection reasons:++| `reason` | Meaning |+| --- | --- |+| `not_cancellable` | `cancellableUntil` has already passed. |+| `already_started` | The interval has begun; reservation is settled. |+| `already_cancelled` | A previous cancel retired this block. |+| `not_found` | Block does not exist, or belongs to another org. |++## Cancelling a single block++For one-block cancellation, `DELETE` is a shortcut:++```bash curl+curl -X DELETE \+ https://app.opencomputer.dev/api/capacity/blocks/9f67b8f7-7b91-4d2d-b1cb-19d0d0a14562 \+ -H "X-API-Key: $OPENCOMPUTER_API_KEY"+```++`204 No Content` on success. On failure, the response body matches the+`blocks_not_cancellable` shape with a single entry.++## Retry pattern: "cancel everything cancellable"++The atomic all-or-nothing rule makes "cancel everything that's still+cancellable" a deliberate loop, not a single call:++```bash+# 1. List currently cancellable blocks in the window+curl "https://app.opencomputer.dev/api/capacity/blocks?from=...&to=...&isCancellable=true" \+ -H "X-API-Key: $OPENCOMPUTER_API_KEY"++# 2. POST those IDs to /cancellations++# 3. If the server returns blocks_not_cancellable, refresh the list and retry+# with the remaining IDs.+```++Blocks race into non-cancellable state as their `cancellableUntil` passes.+Between the list and the cancel call, a block may mature. The rejection+response names every blocking ID, so refresh is cheap.++V1 does not accept a `skipIneligible` flag. Strict all-or-nothing is the+only mode — it keeps retries explicit and cancellation behavior predictable.++## Concurrency and atomicity summary++| Operation | Atomic across | On failure |+| --- | --- | --- |+| `POST /reservations` | All intervals in the request | No blocks created. |+| `POST /cancellations` | All blocks in the request | No blocks cancelled. |+| `PUT /blocks/{id}` | One block | No block created. |+| `DELETE /blocks/{id}` | One block | No block cancelled. |++Parallel writes to the same interval from the same org serialize server-side.+Whichever write commits first wins the remaining capacity; later writes see+the updated `reservableGb` in their validation error.++## Where to go next++<CardGroup cols={2}>+ <Card title="Usage and overage" icon="gauge" href="/reserved-capacity/usage-and-overage">+ How reserved capacity consumes actual usage.+ </Card>+ <Card title="Reading the calendar" icon="calendar" href="/reserved-capacity/calendar">+ Plan before you write.+ </Card>+ <Card title="API reference" icon="code" href="/api-reference/capacity/create-reservations">+ Every endpoint with full request/response shapes.+ </Card>+</CardGroup>diff --git a/docs/reserved-capacity/usage-and-overage.mdx b/docs/reserved-capacity/usage-and-overage.mdxnew file mode 100644index 00000000..1bf65a1c--- /dev/null+++ b/docs/reserved-capacity/usage-and-overage.mdx@@ -0,0 +1,161 @@+---+title: "Usage and Overage"+description: "How reserved capacity consumes actual sandbox usage, and what counts as overage"+---++<Info>+ **Coming soon.** Reserved capacity is not yet available. The contract below+ may change before launch.+</Info>++Reserved capacity and actual sandbox execution are independent flows.+Reserving blocks does not start sandboxes. Starting sandboxes does not+reserve blocks. At the end of each 15-minute interval, the server reconciles+what was used against what was reserved and computes overage.++## The allocation identity++For each 15-minute interval, per `(org, memory resource)`:++```text+overageGb = max(usedGb - reservedGb, 0)+```++That's it. Three numbers and a `max`. No per-sandbox attribution, no+proration beyond the 15-minute boundary, no priority rules.++| Variable | Source |+| --- | --- |+| `usedGb` | Sum of actual sandbox memory tiers over this interval, weighted by seconds, divided by 900. |+| `reservedGb` | Sum of live, non-cancelled blocks this org holds in this interval. |+| `overageGb` | Whatever `usedGb` exceeds `reservedGb` by. |++Unused reserved capacity (`reservedGb > usedGb`) is still committed — you+booked it and it was held for you. Cancel blocks before their+`cancellableUntil` if you decide you don't need them.++## Reserved capacity is pooled, not assigned to specific sandboxes++If you reserve 10 GB at `09:00` and run two sandboxes in that interval+(say, 6 GB each), the math runs at the pool level:++```text+reservedGb = 10+usedGb = 12+overageGb = max(12 - 10, 0) = 2+```++It doesn't matter which sandbox "used the reserved capacity" — they both+ran, the sum was 12, the overage was 2. You can't (and don't need to) tag+sandboxes as "reserved" vs "on-demand."++## Starting and stopping sandboxes is unaffected++Reserved capacity is not a gate. Having a reservation does not:++- Change how you start sandboxes — same `POST /api/sandboxes` flow.+- Pre-warm or pre-allocate compute — blocks are an accounting construct, not+ a physical resource.+- Hold capacity open across restarts — capacity is tied to wall-clock+ intervals, not sandbox lifecycles.++Conversely, not having a reservation does not block you — on-demand capacity+continues to be available, subject to platform admission limits.++## Overage falls back to on-demand terms++Usage above `reservedGb` in an interval is treated as on-demand. It is+subject to the same admission controls, limits, and pricing as any other+on-demand usage.++<Note>+ **Pricing is intentionally out of scope for this API.** The on-demand fallback+ is an accounting statement ("overage counts as on-demand usage"), not a+ pricing statement. Dollar amounts for both reserved and on-demand usage will+ be announced separately before launch.+</Note>++## Cancellation before interval start releases the block++If you cancel a block before `cancellableUntil` and before `startsAt`, it+disappears from the allocation math for that interval. The capacity returns+to `reservableGb` for the platform and for other orgs.++If you cancel between `cancellableUntil` and `startsAt`, the block is+already locked — cancellation is rejected.++Once `startsAt` passes, the block is settled. Whether usage consumed it or+not is recorded in the allocation output, but the block itself is no longer+cancellable.++## Intervals settle after they end++Allocation is computed after an interval closes. Sandbox scale events+settle eventually-consistently across workers, so a brief delay is normal.+The server waits until usage data for the interval is stable before writing+the final allocation record.++Practical implication: don't expect an allocation number the instant+`09:15` ticks over. Expect it a few minutes later.++## Visual model++Blocks are squares on a grid; rows are GB, columns are 15-minute intervals.+Actual usage is a line drawn over the grid.++```text+GB+ │+ │ ███▒▒▒▒▒▒+ │ ███████▒▒▒▒▒▒ ← reserved blocks (▒ cancellable, █ locked)+ │ ███████████████▒▒+ │ ─── usage ────+ │+ └─────────────────────── time (15-min intervals)++ overage when the usage line is above the block stack for an interval+```++The squares are the reserved capacity you hold. The line is what you+actually ran. Overage is where the line pokes above the squares.++## Reading past allocation++Per-interval allocation is computed server-side and will be readable through+a billing/usage endpoint — the shape of that endpoint is part of a separate+billing surface design, not part of this API.++For now, the visible surface is:++- The calendar, which shows `reservedGb` and `usableGb` for any interval in+ its window.+- Block reads, which show what you hold and whether it's still cancellable.+- The existing [`/api/usage`](/api-reference/usage/get-usage) endpoint for+ actual sandbox usage quantities.++When reserved-capacity billing ships, the allocation read model will be+documented alongside it.++## Edge cases++| Case | Behavior |+| --- | --- |+| You hold reservations but run nothing | Reserved capacity is still committed for the interval. No overage. |+| You run workloads but have no reservations | `reservedGb = 0`, so `overageGb = usedGb`. All usage is on-demand. |+| You hold reservations in one interval and run in another | No carryover. Allocation is strictly per interval. |+| You cancel a block mid-interval | Cannot — `cancellableUntil` always precedes `startsAt`. Once the interval begins, blocks are settled. |+| A sandbox crashes and hibernates inside an interval | Usage before the crash counts; usage after hibernation does not. Standard scale-event math. |++## Where to go next++<CardGroup cols={2}>+ <Card title="Reserving and cancelling" icon="lock" href="/reserved-capacity/reserving-and-cancelling">+ How blocks are created and retired.+ </Card>+ <Card title="Reading the calendar" icon="calendar" href="/reserved-capacity/calendar">+ Plan capacity you'll actually use.+ </Card>+ <Card title="Sandboxes overview" icon="cube" href="/sandboxes/overview">+ How sandbox memory tiers work today.+ </Card>+</CardGroup>