An open-source, faster Devin alternative
TypeScript
SDKs + docs for the new points + totals shape
Igor Zalutskic94df3509aa7
diff --git a/docs/api-reference/usage/get-sandbox-usage.mdx b/docs/api-reference/usage/get-sandbox-usage.mdxindex 09640d72..349b06c8 100644--- a/docs/api-reference/usage/get-sandbox-usage.mdx+++ b/docs/api-reference/usage/get-sandbox-usage.mdx@@ -1,22 +1,29 @@----title: 'Sandbox Usage Drilldown'+title: 'Sandbox Usage'api: 'GET /api/sandboxes/{id}/usage'----Per-sandbox GB-second spend over a window, plus tag set and-lifetime bounds. Works for torn-down sandboxes — scale events and-tags persist.+Per-sandbox memory usage over a window, as 1-minute points plus+envelope totals. Allocation is integrated from scale events (same+math the billing pipeline uses); used memory is sampled every 60s+from the qemu process's cgroup `memory.current`.++<Note>+v1 is memory only. CPU mirrors this shape (`cpuUsedCoreSeconds`,+`usedCpuPctAvg`, etc.) once the worker collector starts populating+cgroup `cpu.stat` — additive change, no shape break.+</Note><ParamField path="id" type="string" required>Sandbox ID.</ParamField><ParamField query="from" type="string">- ISO-8601 lower bound. Default: now minus 30 days.+ RFC3339 lower bound. Default: now minus 1 hour.</ParamField><ParamField query="to" type="string">- ISO-8601 upper bound. Default: now. Window must be ≤ 90 days.+ RFC3339 upper bound. Default: now. Window must be ≤ 30 days.</ParamField><ResponseExample>@@ -24,19 +31,67 @@ tags persist.{"sandboxId": "sb-abc","alias": "my-agent",- "status": "running",- "from": "2026-03-23T00:00:00Z",- "to": "2026-04-22T00:00:00Z",- "memoryGbSeconds": 12345.6,- "diskOverageGbSeconds": 789.0,- "tags": { "env": "prod", "team": "payments" },- "tagsLastUpdatedAt": "2026-04-19T14:02:00Z",- "firstStartedAt": "2026-03-25T09:13:02Z",- "lastEndedAt": null+ "from": "2026-05-27T00:00:00Z",+ "to": "2026-05-28T00:00:00Z",+ "totals": {+ "memoryAllocatedGbSeconds": 8000,+ "memoryUsedGbSeconds": 5400,+ "uptimeSeconds": 86400,+ "memoryAllocatedPeakMb": 2048,+ "memoryUsedPeakMb": 1640+ },+ "points": [+ {+ "ts": "2026-05-27T00:00:00Z",+ "memoryAllocatedGbSeconds": 1.024,+ "memoryUsedGbSeconds": 0.612,+ "uptimeSeconds": 60,+ "allocatedMemoryMb": 1024,+ "usedMemoryMbAvg": 612,+ "usedMemoryMbPeak": 720+ },+ {+ "ts": "2026-05-27T00:01:00Z",+ "memoryAllocatedGbSeconds": 1.024,+ "memoryUsedGbSeconds": 0.683,+ "uptimeSeconds": 60,+ "allocatedMemoryMb": 1024,+ "usedMemoryMbAvg": 683,+ "usedMemoryMbPeak": 742+ }+ ]}```</ResponseExample>-`firstStartedAt` / `lastEndedAt` come from session records clamped to-the query window. `lastEndedAt` is `null` while any session for this-sandbox is open.+### Reading the response++`totals.memoryAllocatedGbSeconds` is what the bill is computed from —+the same physical quantity the Stripe pipeline reports. `totals.memoryUsedGbSeconds`+is the integrated actual RSS; the ratio between the two tells you+whether the sandbox is over-provisioned.++Each point's `memoryAllocatedGbSeconds` and `memoryUsedGbSeconds`+integrate over that 1-minute bucket — summing them across any+subrange reconstructs the integral for that subrange. `totals.*` is+the server-side sum across all returned points. Snapshot scalars+(`allocatedMemoryMb`, `usedMemoryMb{Avg,Peak}`) are time-weighted+averages over the bucket and are intended for chart rendering.++### Bucket semantics++- Buckets are minute-aligned in UTC, not aligned to `from`. The first+ and last buckets may be partial if `from` / `to` are mid-minute.+- Minutes where the sandbox is not running emit zero-points+ (`uptimeSeconds: 0`, all integrals `0`) rather than nulls — gaps+ read as continuous flat zero on a chart.+- When a sandbox is resized mid-bucket, `allocatedMemoryMb` shows the+ time-weighted average across the bucket; subsequent buckets reflect+ the new tier.++### Use the aggregator for cross-sandbox questions++To rank sandboxes by spend (or, soon, by actual usage), use+[`GET /api/usage`](/api-reference/usage/get-usage) — that endpoint+serves cross-sandbox aggregates and supports filter/sort/cursor. The+per-sandbox endpoint here is for "look at this one sandbox in detail."diff --git a/sdks/python/opencomputer/__init__.py b/sdks/python/opencomputer/__init__.pyindex cb7b40c3..ae6b3471 100644--- a/sdks/python/opencomputer/__init__.py+++ b/sdks/python/opencomputer/__init__.py@@ -20,6 +20,8 @@ from opencomputer.usage import (UsageBySandboxResponse,UsageByTagResponse,SandboxUsageResponse,+ SandboxUsagePoint,+ SandboxUsageTotals,TagKeyInfo,)@@ -54,7 +56,9 @@ __all__ = ["UsageBySandboxResponse","UsageByTagResponse","SandboxUsageResponse",+ "SandboxUsagePoint",+ "SandboxUsageTotals","TagKeyInfo",]-__version__ = "0.5.4"+__version__ = "0.6.0"diff --git a/sdks/python/opencomputer/usage.py b/sdks/python/opencomputer/usage.pyindex ba59cd53..a696d79f 100644--- a/sdks/python/opencomputer/usage.py+++ b/sdks/python/opencomputer/usage.py@@ -66,19 +66,48 @@ class UsageByTagResponse:next_cursor: str | None+@dataclass+class SandboxUsagePoint:+ """One 1-minute bucket of memory usage. Integrals (``*_gb_seconds``,+ ``uptime_seconds``) compose by summation; snapshot scalars+ (``allocated_memory_mb``, ``used_memory_mb_*``) are for charts.++ v1 is memory only. CPU fields will appear once the server-side+ collector starts populating cgroup cpu.stat.+ """++ ts: str+ memory_allocated_gb_seconds: float+ memory_used_gb_seconds: float+ uptime_seconds: int+ allocated_memory_mb: int+ used_memory_mb_avg: int+ used_memory_mb_peak: int+++@dataclass+class SandboxUsageTotals:+ """Envelope totals over ``[from_, to)``. Invariant: summing the+ matching field across ``points`` reproduces the value here."""++ memory_allocated_gb_seconds: float+ memory_used_gb_seconds: float+ uptime_seconds: int+ memory_allocated_peak_mb: int+ memory_used_peak_mb: int++@dataclassclass SandboxUsageResponse:+ """Response for ``GET /sandboxes/:id/usage``. Default window is+ last 1 hour; max 30 days (server returns 400 beyond that)."""+sandbox_id: strfrom_: strto: str- memory_gb_seconds: float- disk_overage_gb_seconds: float- tags: dict[str, str]- tags_last_updated_at: str | None- first_started_at: str | None- last_ended_at: str | None+ totals: SandboxUsageTotals+ points: list[SandboxUsagePoint]alias: str | None = None- status: str | None = None@dataclass@@ -235,18 +264,31 @@ class Usage:resp = await self._client.get(f"/sandboxes/{sandbox_id}/usage", params=params)resp.raise_for_status()b = resp.json()+ t = b.get("totals") or {}return SandboxUsageResponse(sandbox_id=b["sandboxId"],from_=b["from"],to=b["to"],- memory_gb_seconds=b["memoryGbSeconds"],- disk_overage_gb_seconds=b["diskOverageGbSeconds"],- tags=b.get("tags") or {},- tags_last_updated_at=b.get("tagsLastUpdatedAt"),- first_started_at=b.get("firstStartedAt"),- last_ended_at=b.get("lastEndedAt"),+ totals=SandboxUsageTotals(+ memory_allocated_gb_seconds=t.get("memoryAllocatedGbSeconds", 0.0),+ memory_used_gb_seconds=t.get("memoryUsedGbSeconds", 0.0),+ uptime_seconds=t.get("uptimeSeconds", 0),+ memory_allocated_peak_mb=t.get("memoryAllocatedPeakMb", 0),+ memory_used_peak_mb=t.get("memoryUsedPeakMb", 0),+ ),+ points=[+ SandboxUsagePoint(+ ts=p["ts"],+ memory_allocated_gb_seconds=p["memoryAllocatedGbSeconds"],+ memory_used_gb_seconds=p["memoryUsedGbSeconds"],+ uptime_seconds=p["uptimeSeconds"],+ allocated_memory_mb=p["allocatedMemoryMb"],+ used_memory_mb_avg=p["usedMemoryMbAvg"],+ used_memory_mb_peak=p["usedMemoryMbPeak"],+ )+ for p in b.get("points") or []+ ],alias=b.get("alias"),- status=b.get("status"),)diff --git a/sdks/python/pyproject.toml b/sdks/python/pyproject.tomlindex d44d2101..d2498465 100644--- a/sdks/python/pyproject.toml+++ b/sdks/python/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "hatchling.build"[project]name = "opencomputer-sdk"-version = "0.5.4"+version = "0.6.0"description = "Python SDK for OpenComputer - cloud sandbox platform"readme = "README.md"requires-python = ">=3.10"diff --git a/sdks/typescript/package-lock.json b/sdks/typescript/package-lock.jsonindex 1b37e8fb..6cf6c844 100644--- a/sdks/typescript/package-lock.json+++ b/sdks/typescript/package-lock.json@@ -1,12 +1,12 @@{"name": "@opencomputer/sdk",- "version": "0.5.17",+ "version": "0.6.0","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "@opencomputer/sdk",- "version": "0.5.17",+ "version": "0.6.0","license": "MIT","devDependencies": {"@types/node": "^25.3.0",diff --git a/sdks/typescript/package.json b/sdks/typescript/package.jsonindex 84483112..9f55155b 100644--- a/sdks/typescript/package.json+++ b/sdks/typescript/package.json@@ -1,6 +1,6 @@{"name": "@opencomputer/sdk",- "version": "0.5.17",+ "version": "0.6.0","description": "TypeScript SDK for OpenComputer - cloud sandbox platform","type": "module","main": "dist/index.js",diff --git a/sdks/typescript/src/index.ts b/sdks/typescript/src/index.tsindex 1632fd68..1bd215b0 100644--- a/sdks/typescript/src/index.ts+++ b/sdks/typescript/src/index.ts@@ -31,6 +31,8 @@ export {type UsageQueryOpts,type UsageFilterMap,type SandboxUsageResponse,+ type SandboxUsagePoint,+ type SandboxUsageTotals,type TagKeyInfo,} from "./usage.js";// Node.js-only modules (use crypto, fs, path) — import via "@opencomputer/sdk/node".diff --git a/sdks/typescript/src/usage.ts b/sdks/typescript/src/usage.tsindex 8d3f4fad..2dcc71d0 100644--- a/sdks/typescript/src/usage.ts+++ b/sdks/typescript/src/usage.ts@@ -69,18 +69,50 @@ export interface UsageQueryOpts {cursor?: string;}+/**+ * One 1-minute bucket of memory usage for a sandbox. Integrals+ * (`*GbSeconds`, `uptimeSeconds`) compose by summation; snapshot scalars+ * (`allocatedMemoryMb`, `usedMemoryMb*`) are for chart rendering.+ *+ * v1 is memory only. CPU fields will be added symmetrically once the+ * server-side collector starts populating cgroup cpu.stat.+ */+export interface SandboxUsagePoint {+ ts: string; // RFC3339, bucket start, minute-aligned in UTC+ memoryAllocatedGbSeconds: number;+ memoryUsedGbSeconds: number;+ uptimeSeconds: number;+ allocatedMemoryMb: number;+ usedMemoryMbAvg: number;+ usedMemoryMbPeak: number;+}++/**+ * Envelope totals over `[from, to)`. Server-side invariant: summing+ * the matching field across `points[]` reproduces the value here.+ */+export interface SandboxUsageTotals {+ memoryAllocatedGbSeconds: number;+ memoryUsedGbSeconds: number;+ uptimeSeconds: number;+ memoryAllocatedPeakMb: number;+ memoryUsedPeakMb: number;+}++/**+ * Response shape for `GET /api/sandboxes/:id/usage`. Default window is+ * last 1 hour; max window is 30 days (server returns 400 beyond that).+ * Allocation comes from scale events; used memory from cgroup samples.+ *+ * Charts read `points[]`; programmatic consumers usually want `totals`.+ */export interface SandboxUsageResponse {sandboxId: string;alias?: string;- status?: string;from: string;to: string;- memoryGbSeconds: number;- diskOverageGbSeconds: number;- tags: Record<string, string>;- tagsLastUpdatedAt: string | null;- firstStartedAt: string | null;- lastEndedAt: string | null;+ totals: SandboxUsageTotals;+ points: SandboxUsagePoint[];}export interface TagKeyInfo {