> ## Documentation Index
> Fetch the complete documentation index at: /llms.txt
> Use this file to discover all available pages before exploring further.

# gRPC API

> Raw gRPC access to the boxd public API, for any language with a protoc plugin.

The boxd CLI, the SDKs, and the console are all clients of one thing: the public gRPC API at `boxd.sh:9443`. If your language doesn't have a boxd SDK yet, generate one from the proto file and talk to it directly.

## Installation

There is nothing to install from boxd's side. Point a gRPC client at the endpoint, and generate stubs from [the proto](/reference/grpc-proto.md) if your toolchain wants them.

### Endpoint

```text
boxd.sh:9443
```

* **Transport.** TLS, with the same certificate the cluster's HTTPS domains use. Plain HTTP/2 (h2c) is still accepted on the same port so clients released before TLS keep working. New integrations should connect over TLS. Auth is short-lived JWTs either way.
* **Reflection.** [gRPC server reflection](https://grpc.io/docs/guides/reflection/) (the v1 protocol) is enabled, so tools like `grpcurl` 1.9+ work without the proto file.
* **Service.** `boxd.api.v1.BoxdApi`.

### Regions

Each [region](/guides/regions.md) has its own endpoint. `boxd.sh:9443` is Frankfurt, and New York is `nyc.boxd.sh:9443`.

* **Where calls go.** A call on a machine, snapshot or disk, or on anything inside a machine, goes to the endpoint of the machine's region. Account, org, API key, env var, secret and billing calls go to `boxd.sh:9443`.
* **Credentials.** The same bearer token works in every region. An API key works in a region once its org has that region enabled.
* **Discovery.** `ListRegions` lists each region with its `id`, `name`, `zone`, `api_endpoint` and `console_endpoint`, `home` (true for Frankfurt, the region account and org calls go to), and the org's `org_state` there: `enabled`, `requested` or `available`. `RequestOrgRegion` asks for one, for org admins.
* **The org's default region.** The `region` field of `GetOrgMachineDefaults` and `SetOrgMachineDefaults`. The CLI and the console create machines there when nobody names a region.
* **Where things are.** Machines, snapshots, disks and org domains carry `region`. `ListVms`, `ListSnapshots` and `ListDisks` take `with_elsewhere` and answer `elsewhere`, the count in each other region. A not-found names the region that looked (`vm not found (region nyc)`), and `FindElsewhere` says where else your orgs have a name.
* **Per-region settings.** `SetOrgDomain`, `GetOrgDomain` and `ClearOrgDomain` act on the org's wildcard domain in the region of the endpoint you call. `GetTeam` and `SetTeamDefaultSnapshot` do the same for a team's default snapshot.

With `$BOXD_JWT` set as in [Hello world](#hello-world):

```bash
# The regions, and where your org stands with each
grpcurl -H "authorization: Bearer $BOXD_JWT" \
  boxd.sh:9443 boxd.api.v1.BoxdApi/ListRegions

# A machine in New York
grpcurl -H "authorization: Bearer $BOXD_JWT" -d '{"name": "web"}' \
  nyc.boxd.sh:9443 boxd.api.v1.BoxdApi/CreateVm
```

### The proto

The full service definition lives on its own page: [Proto](/reference/grpc-proto.md). Copy it into a local `api.proto` and generate stubs with `protoc`, [`buf`](https://buf.build), [`grpc_tools`](https://pypi.org/project/grpcio-tools/), or `@grpc/proto-loader`.

You often don't need the file at all. [Server reflection](https://grpc.io/docs/guides/reflection/) is on, so the schema can be inferred straight from the endpoint, and `grpcurl boxd.sh:9443 describe boxd.api.v1.BoxdApi` prints it on demand.

## Authentication

Two steps: a long-lived API key is exchanged for a short-lived JWT, and the JWT rides as a bearer token on every gRPC call.

### 1. Create an API key

API keys are issued from the console. Sign in at [app.boxd.sh](https://app.boxd.sh), open the API keys page, and create one. The raw key is shown **once**, so copy it immediately. The format is `bxd_` followed by 43 base62 characters.

You can also create them with the CLI once you're logged in:

```bash
boxd auth login
boxd auth keys create my-app
```

### 2. Exchange for a JWT

Send the API key to the exchange endpoint on the console host, over HTTPS:

```bash
curl -X POST https://app.boxd.sh/api/v1/auth/token \
  -H "Content-Type: application/json" \
  -d '{"api_key":"bxd_..."}'
```

```json
{
  "token": "eyJhbGciOi...",
  "expires_at": 1735689600,
  "user_id": "usr_4f1c..."
}
```

The JWT from an API-key exchange lives for **1 hour**, so re-exchange before expiry. The endpoint is rate-limited per source IP.

### 3. Send it on every gRPC call

```text
authorization: Bearer eyJhbGciOi...
```

Standard gRPC metadata. Most generated clients expose this as a per-call interceptor or call option.

### What an API-key session can do

An API key is fenced to one org. A `member` key (the default) covers the machine, snapshot, checkpoint, disk, port, proxy, domain, env/secret, file, and org and team surface, always for that one org. An `org` key is a userless service credential that reaches only the org's shared machines, and env/secret and org operations reject it too. A handful of RPCs additionally require a JWT from an **interactive login** (the browser or CLI device flow) and answer `PERMISSION_DENIED` to API-key sessions: `CreateApiKey`, `ListApiKeys`, `DeleteApiKey`, `CreateToken`, `RevokeToken`, `LinkSshKey`, `CreateNetwork`, `ListNetworks`, `GetBilling`, `GetOrgBilling`, the checkout/portal calls, `CreateOrg`, and any invite or role change that would make someone an admin. `GetOrgMembers` lists pending invites to an API-key session without their tokens and links. The practical consequence is that an API key can never mint more keys, and never more standing than it has.

## Commands

The full RPC surface is the `service BoxdApi` block in [the proto](/reference/grpc-proto.md): machines, computer use, files and directories, snapshots, checkpoints, disks, ports, proxies, domains, env vars and secrets, organizations and their members, teams, tokens, billing, and usage and cost. What a given RPC expects is documented on its request message, and `grpcurl describe` dumps any of it on demand. Egress control is `SetVmEgressAllow` plus the `domains` field of `SetVarRequest`. See [Egress control](/guides/egress). SSH on or off is `SetSsh`, or `config.network.ssh` on create. See [Turn SSH off](/cli/commands.md#turn-ssh-off). Machine specs are the `spec` field of `CreateVm` and `CreateVmFromSnapshot`, plus `UpdateMachineSpec`. See [Machine specs](#machine-specs) below.

### Hello world

> [tab] grpcurl
>
> Easiest way to verify auth and reachability, with no proto file needed since server reflection is on.
>
> ```bash
> # Set your JWT
> export BOXD_JWT="$(curl -s -X POST https://app.boxd.sh/api/v1/auth/token \
>   -H 'Content-Type: application/json' \
>   -d '{"api_key":"bxd_..."}' | jq -r .token)"
>
> # Whoami
> grpcurl \
>   -H "authorization: Bearer $BOXD_JWT" \
>   boxd.sh:9443 boxd.api.v1.BoxdApi/Whoami
>
> # Create a machine
> grpcurl \
>   -H "authorization: Bearer $BOXD_JWT" \
>   -d '{"name": "myapp"}' \
>   boxd.sh:9443 boxd.api.v1.BoxdApi/CreateVm
>
> # List machines
> grpcurl \
>   -H "authorization: Bearer $BOXD_JWT" \
>   boxd.sh:9443 boxd.api.v1.BoxdApi/ListVms
> ```
>
> Install: `brew install grpcurl` or [github.com/fullstorydev/grpcurl](https://github.com/fullstorydev/grpcurl).

> [tab] Go
>
> Save [the proto](/reference/grpc-proto.md) as `gen/api.proto`, then generate stubs:
>
> ```bash
> cd gen
> protoc --go_out=. --go_opt=paths=source_relative \
>        --go-grpc_out=. --go-grpc_opt=paths=source_relative \
>        api.proto
> ```
>
> Hello world:
>
> ```go main.go
> package main
>
> import (
>     "context"
>     "encoding/json"
>     "fmt"
>     "log"
>     "net/http"
>     "strings"
>
>     boxdv1 "yourmodule/gen"
>     "google.golang.org/grpc"
>     "google.golang.org/grpc/credentials"
>     "google.golang.org/grpc/metadata"
> )
>
> func exchange(apiKey string) string {
>     body := strings.NewReader(`{"api_key":"` + apiKey + `"}`)
>     resp, err := http.Post("https://app.boxd.sh/api/v1/auth/token",
>         "application/json", body)
>     if err != nil { log.Fatal(err) }
>     defer resp.Body.Close()
>     var out struct{ Token string }
>     json.NewDecoder(resp.Body).Decode(&out)
>     return out.Token
> }
>
> func main() {
>     jwt := exchange("bxd_...")
>
>     conn, err := grpc.NewClient("boxd.sh:9443",
>         grpc.WithTransportCredentials(credentials.NewTLS(nil)))
>     if err != nil { log.Fatal(err) }
>     defer conn.Close()
>
>     client := boxdv1.NewBoxdApiClient(conn)
>     ctx := metadata.AppendToOutgoingContext(context.Background(),
>         "authorization", "Bearer "+jwt)
>
>     me, err := client.Whoami(ctx, &boxdv1.WhoamiRequest{})
>     if err != nil { log.Fatal(err) }
>     fmt.Println("user:", me.UserId)
>
>     vm, err := client.CreateVm(ctx, &boxdv1.CreateVmRequest{
>         Name: "myapp",
>     })
>     if err != nil { log.Fatal(err) }
>     fmt.Printf("created %s at %s (%dms)\n",
>         vm.Name, vm.Url, vm.BootTimeMs)
> }
> ```

> [tab] TypeScript
>
> Save [the proto](/reference/grpc-proto.md) as `./api.proto`, then install runtime deps:
>
> ```bash
> npm install @grpc/grpc-js @grpc/proto-loader
> ```
>
> Hello world, using dynamic loading with no codegen step:
>
> ```typescript hello.ts
> import * as grpc from '@grpc/grpc-js';
> import * as protoLoader from '@grpc/proto-loader';
>
> async function exchange(apiKey: string): Promise<string> {
>   const r = await fetch('https://app.boxd.sh/api/v1/auth/token', {
>     method: 'POST',
>     headers: { 'content-type': 'application/json' },
>     body: JSON.stringify({ api_key: apiKey }),
>   });
>   const { token } = await r.json();
>   return token;
> }
>
> async function main() {
>   const jwt = await exchange('bxd_...');
>
>   const def = protoLoader.loadSync('./api.proto', {
>     keepCase: true, longs: String, enums: String, defaults: true,
>   });
>   const proto = grpc.loadPackageDefinition(def) as any;
>
>   const meta = new grpc.Metadata();
>   meta.set('authorization', `Bearer ${jwt}`);
>
>   const client = new proto.boxd.api.v1.BoxdApi(
>     'boxd.sh:9443',
>     grpc.credentials.createSsl(),
>   );
>
>   client.Whoami({}, meta, (err: any, me: any) => {
>     if (err) throw err;
>     console.log('user:', me.user_id);
>
>     client.CreateVm({ name: 'myapp' }, meta, (err: any, vm: any) => {
>       if (err) throw err;
>       console.log(`created ${vm.name} at ${vm.url} (${vm.boot_time_ms}ms)`);
>     });
>   });
> }
>
> main();
> ```

> [tab] Python
>
> Save [the proto](/reference/grpc-proto.md) as `./api.proto`, then:
>
> ```bash
> pip install grpcio grpcio-tools requests
> python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. api.proto
> ```
>
> Hello world:
>
> ```python hello.py
> import grpc
> import requests
> import api_pb2 as pb
> import api_pb2_grpc as rpc
>
> def exchange(api_key: str) -> str:
>     r = requests.post(
>         "https://app.boxd.sh/api/v1/auth/token",
>         json={"api_key": api_key},
>     )
>     r.raise_for_status()
>     return r.json()["token"]
>
> def main():
>     jwt = exchange("bxd_...")
>     meta = (("authorization", f"Bearer {jwt}"),)
>
>     with grpc.secure_channel("boxd.sh:9443", grpc.ssl_channel_credentials()) as ch:
>         client = rpc.BoxdApiStub(ch)
>
>         me = client.Whoami(pb.WhoamiRequest(), metadata=meta)
>         print("user:", me.user_id)
>
>         vm = client.CreateVm(pb.CreateVmRequest(name="myapp"), metadata=meta)
>         print(f"created {vm.name} at {vm.url} ({vm.boot_time_ms}ms)")
>
> if __name__ == "__main__":
>     main()
> ```

### Usage and cost

Three read-only RPCs answer "what did this cost". They are for org owners and admins, and an API key fenced to the org can call them. A token minted inside a machine cannot. Inside a machine, `boxd machine usage` shows that machine's own usage.

| RPC | Returns |
| - | - |
| `GetOrgUsage` | Every machine in the org over a window, most expensive first: time in each state, vCPU-hours, RAM and disk GiB-hours, and an estimated cost. Default window: the last 28 days. |
| `GetVmUsage` | The same for one machine, by name or id. Default window: its whole life. A deleted machine is found by its id, or by its name in the org's usage history. |
| `ListBillingActivity` | What changed the balance, newest first: top-ups, credits and usage charges, plus the current balance. Paged with `page_token`. |

```bash
# Every machine in the org, last 28 days
grpcurl \
  -H "authorization: Bearer $BOXD_JWT" \
  -d '{"org": "acme"}' \
  boxd.sh:9443 boxd.api.v1.BoxdApi/GetOrgUsage

# One machine over its whole life (also works after it is deleted)
grpcurl \
  -H "authorization: Bearer $BOXD_JWT" \
  -d '{"vm_id": "myapp", "org": "acme"}' \
  boxd.sh:9443 boxd.api.v1.BoxdApi/GetVmUsage

# What was actually charged
grpcurl \
  -H "authorization: Bearer $BOXD_JWT" \
  -d '{"org": "acme", "page_size": 100}' \
  boxd.sh:9443 boxd.api.v1.BoxdApi/ListBillingActivity
```

* **Money.** Amounts are in micro-units (1e-6) of the org's `currency` (`"eur"` or `"usd"`), so `cost_micro / 1e6` is the amount.
* **Windows.** Windows are unix seconds, `[since, until)`, at most 366 days.
* **Costs are estimates.** Usage is metered every second and settled every 15 minutes, and costs are priced at the org's current rates. `ListBillingActivity` is what was charged: one `usage_charge` per 15 minutes for the whole org.
* **`complete`.** The flag on a machine (and on the `GetOrgUsage` response) is true once all of its usage in the window is metered, so the figure will not grow. Metering lags by up to about 25 minutes. A machine that still exists is never complete in a window that runs to now. To record what a deleted machine cost, read it again until `complete` is true.
* **Shared names.** A deleted machine's name can be reused. If several deleted machines carried the name you pass, `GetVmUsage` answers `INVALID_ARGUMENT` and lists their ids.

### Computer use

`ComputerAction` does one screenshot, mouse or keyboard action on a machine's desktop, which starts on demand. Set exactly one action on the request. The response carries the screen's size and held state, where the pointer is, and a screenshot when you ask for one. See [Computer use](/guides/computer-use.md).

```bash
# A screenshot, scaled down to fit
grpcurl \
  -H "authorization: Bearer $BOXD_JWT" \
  -d '{"vm_id": "myapp", "screenshot": {}, "screenshot_options": {"format": "jpeg", "max_width": 1280}}' \
  boxd.sh:9443 boxd.api.v1.BoxdApi/ComputerAction

# A click, and a screenshot after it in the same call
grpcurl \
  -H "authorization: Bearer $BOXD_JWT" \
  -d '{"vm_id": "myapp", "click": {"at": {"x": 640, "y": 400}}, "return_screenshot": true}' \
  boxd.sh:9443 boxd.api.v1.BoxdApi/ComputerAction

# Hold the screen at a size. Both 0 releases it.
grpcurl \
  -H "authorization: Bearer $BOXD_JWT" \
  -d '{"vm_id": "myapp", "set_screen_size": {"width": 1280, "height": 800}}' \
  boxd.sh:9443 boxd.api.v1.BoxdApi/ComputerAction
```

* **Screenshots and the 4 MiB limit.** A full-size PNG of a large screen can pass 30 MB. A client on gRPC's default 4 MiB receive limit should raise it, or ask for less with `max_width`, `max_height` or JPEG.
* **Errors.** `INVALID_ARGUMENT` means the request doesn't fit and nothing was done, such as a point off the screen. `UNAVAILABLE` from the desktop not starting means nothing was done either. After other failures the action may have run, so take a screenshot before sending it again.

### Machine specs

A machine spec describes a machine in one value: what it boots from, its size, labels, networks, isolation, egress allowlist, env, the secrets it gets, the integrations and agent logins it needs, and shell commands to run on its first boot. The machine keeps it. See [Machine specs](/guides/machine-specs.md) for what each part does.

| RPC or field | What it does |
| - | - |
| `CreateVm`, field `spec` | Create a machine from a `MachineSpec`. It can't be combined with the fields it covers: `image_ref`, `team`, `labels`, `networks`, `isolated`, `env`, `config.vcpu` and `config.memory_bytes`. A spec whose `base` is a snapshot restores it. |
| `CreateVmFromSnapshot`, field `spec` | A spec merged over the snapshot's own. Its `base`, if set, must be this snapshot, and its `size`, if set, the snapshot's. Not together with `labels` or `isolated`: put them in the spec. |
| `GetVm`, `ListVms` | `spec` (as it stands) and `created_spec` (as created, never changed); `created_by` and `created_by_name` on a machine created for its owner; `requirements` (`MachineRequirement`: `kind`, `name`, `scope`, `tag`, `met`, `can_fix`, `reason`); `packages` (`MachinePackage`: `command`, `state`, `exit_code`, `output_tail`, `reason`, `started_at_ms`, `finished_at_ms`). `ListVms` leaves each package's `output_tail` empty, and `GetVm` has it. |
| `UpdateMachineSpec` | Patch a machine's spec and apply what changes. Request: `vm`, `patch`, `dry_run`, `reboot`, `retry_packages`, `expected_spec`. Response: `changes` (`MachineSpecChange`: `field`, `apply`, `added`, `removed`, `changed`, `before`, `after`, `note`, `warnings`), `reboot_required`, `reboot_recommended`, `spec`, `applied`, `rebooted`, `resize_error`. |
| `SetVar`, field `scope` | `"unattached"` (the org's with `org`, else yours) and `"private-unattached"` (yours in `org`), for secrets only: a secret that reaches only the machines whose spec lists it. `ListVars` reports `bound_machines`, how many machines list it. |

`MachineSpec` holds `version` (must be 1), `base` (`MachineSpecBase`: `team` or `snapshot`), `size` (`"<vcpu>x<memory GiB>"`, such as `"2x8"`), `assign_to`, `labels`, `networks`, `isolated`, `egress`, `env`, `secrets` (names), `connections` (integration name to `"personal"` or `"shared:<tag>"`), `agents` (`"claude"`, `"codex"`) and `packages`. Server reflection describes every message: `grpcurl boxd.sh:9443 describe boxd.api.v1.MachineSpec`.

```bash
# Create a machine from a spec
grpcurl \
  -H "authorization: Bearer $BOXD_JWT" \
  -d '{"name": "mike-dev", "org": "acme", "spec": {"version": 1, "base": {"team": "eng"}, "size": "2x8", "networks": ["eng"], "connections": {"github": "shared:eng-bot"}, "agents": ["claude"], "packages": ["apt-get update", "apt-get install -y nginx"]}}' \
  boxd.sh:9443 boxd.api.v1.BoxdApi/CreateVm

# What a bigger size would change, without changing anything
grpcurl \
  -H "authorization: Bearer $BOXD_JWT" \
  -d '{"vm": "mike-dev", "patch": "{\"size\": \"4x16\"}", "dry_run": true}' \
  boxd.sh:9443 boxd.api.v1.BoxdApi/UpdateMachineSpec

# Run the packages again from the one that failed
grpcurl \
  -H "authorization: Bearer $BOXD_JWT" \
  -d '{"vm": "mike-dev", "patch": "{}", "retry_packages": true}' \
  boxd.sh:9443 boxd.api.v1.BoxdApi/UpdateMachineSpec
```

* **The patch is a JSON string.** `patch` is a [JSON Merge Patch](https://datatracker.ietf.org/doc/html/rfc7396) on the spec's JSON form, the one the SDKs print (camelCase, so `assignTo`), sent as a string so that `null` and `[]` survive. A field it leaves out is untouched, a scalar replaces, maps merge key by key with `null` removing a key, and a list replaces the whole list. `expected_spec` is the spec you read, in the same form: if the machine's spec is no longer that one, nothing is applied.
* **All or nothing.** A change that can't apply (`base`, `isolated` and `assign_to` after creation, packages on a fork, a size change on standby or hibernated) refuses the whole patch, and so does a size change for a running machine without `reboot`. A resize that fails after the rest of the patch applied still answers OK, with `applied` true, `rebooted` false and `resize_error` set.
* **Status codes.** `INVALID_ARGUMENT`: a bad patch, or a spec the rules refuse, naming the field (`spec.size: ...`). `PERMISSION_DENIED`: a secret you may not list, `assign_to` your role or credential doesn't allow (an org key, a token from inside a machine), or a change a machine may not make to itself from inside (its own egress or secrets). `FAILED_PRECONDITION`: a refused change, a reboot without `reboot`, or a machine without a spec. `ABORTED`: the spec changed while your update ran, and nothing was applied. Read it again and retry.
* **Egress.** A new allowlist from a spec update is in force within about a second of the response.

### Errors

Standard gRPC status codes. The most common ones you'll hit:

| Code | When |
| - | - |
| `UNAUTHENTICATED` | Missing/malformed/expired JWT, or `authorization` metadata not set |
| `PERMISSION_DENIED` | Valid JWT, but the caller may not do this (for example an API-key session calling an interactive-only RPC) |
| `NOT_FOUND` | Machine, disk, snapshot, or domain doesn't exist |
| `RESOURCE_EXHAUSTED` | The org's machine cap is reached |
| `INVALID_ARGUMENT` | Bad request shape (for example an invalid machine name, or conflicting fields) |
| `FAILED_PRECONDITION` | The resource is in the wrong state for the call (for example a spec change that needs `reboot`) |
| `ABORTED` | The resource changed while the call ran (for example a machine's spec during `UpdateMachineSpec`). Nothing was applied: read it again and retry |
| `INTERNAL` | Server-side error |

The error message in `Status.message()` is human-readable and safe to surface to users.

### Streaming RPCs

Two RPCs stream:

* `Exec` is bidirectional. The first message must contain `vm_id` and `command`. Subsequent client messages with `stdin=true` pipe stdin, or `window_change=true` with `cols`/`rows` resize a PTY. Server messages carry `data`, with `is_stderr` set for stderr chunks on non-PTY execs (PTY-mode execs merge stderr into stdout at the kernel). The final server message has `exit_code` set. Closing the client's send half signals stdin EOF to the subprocess.
* `UploadFileStream` is client-streaming and lifts the 4 MiB single-message gRPC cap of `UploadFile`. The first `UploadFileChunk` carries `vm_id`, `path`, and `total_size`, and subsequent chunks carry bytes only. The server reads exactly `total_size` bytes and returns the confirmed byte count.

## Calling from a browser or Cloudflare Worker

Raw gRPC needs HTTP/2 trailers and a socket API that neither browsers nor Cloudflare Workers expose. Both are limited to `fetch` and `WebSocket`. `boxd.sh:9443` also speaks [grpc-web](https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-WEB.md), a wire-compatible HTTP/1.1-friendly framing of the same protobuf messages, over the same port, for exactly this case.

Everything above still applies: same endpoint, same `Authorization: Bearer` JWT (as a normal HTTP header this time, not gRPC metadata), same RPCs, same errors. The differences are only in how a message gets on the wire:

* **Content type.** `application/grpc-web+proto`. Each message is one frame: a 1-byte flag, a 4-byte big-endian length, then the protobuf payload. The response ends with a trailer frame (flag bit `0x80` set) carrying `grpc-status` and `grpc-message` as `key: value\r\n` text. `grpc-message` is percent-encoded, so decode it before displaying it.
* **CORS.** Enabled, so a browser can call directly with no server-side proxy.
* **`Exec` and `UploadFileStream` run half-duplex.** The whole request (every message you'd have sent on a native gRPC stream) has to finish before the response starts streaming back, since `fetch` can't read a response body while still writing the request body. This is already how `exec()` (send the command, read the result) and a file upload (send the bytes, read the confirmation) behave in every boxd SDK. The only thing that doesn't work over grpc-web is an **interactive** PTY session, which needs a connection that's live in both directions at once.

> [!NOTE]
>
> Unless you're targeting a language with no grpc-web library, use the TypeScript SDK's `@boxd-sh/sdk/web` entry point rather than framing grpc-web by hand. See [TypeScript SDK](/reference/typescript-sdk.md#cloudflare-workers-browsers-and-other-non-node-runtimes). It implements the framing above once and exposes the same `boxd.<namespace>.<verb>()` surface as the Node SDK.

### Minimal example (no library)

```typescript
const jwt = await fetch("https://app.boxd.sh/api/v1/auth/token", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({ api_key: "bxd_..." }),
}).then((r) => r.json()).then((r) => r.token);

// One grpc-web frame: [flag:1][length:4 BE][protobuf payload]
function frame(payload: Uint8Array): Uint8Array {
  const f = new Uint8Array(5 + payload.length);
  new DataView(f.buffer).setUint32(1, payload.length, false);
  f.set(payload, 5);
  return f;
}

const body = frame(WhoamiRequest.encode({}).finish()); // encode with your protobuf lib of choice

const resp = await fetch("https://boxd.sh:9443/boxd.api.v1.BoxdApi/Whoami", {
  method: "POST",
  headers: {
    "content-type": "application/grpc-web+proto",
    "authorization": `Bearer ${jwt}`,
  },
  body,
});

// Parse the response the same way: read 5-byte-prefixed frames from resp.body
// until the TRAILER frame (flag & 0x80), which carries grpc-status/grpc-message
// instead of a protobuf payload.
```
