BoxApi, configure auth, and call methods like box.create, box.prompt, and box.events.
Configure
fetch. Older runtimes need a fetch polyfill. For ESM examples, set "type": "module" in package.json; CommonJS projects can use the require example below.
Create, prompt, and clean up
Use
ttlSeconds when creating a Box. Set a friendly name afterward with box.update.CommonJS
Methods
All methods are called onBoxApi. Request bodies are plain objects typed by the exported model interfaces.
| Method | Arguments | Returns | Use |
|---|---|---|---|
me() | none | Promise<MeResponse> | Get the authenticated Box account user. |
limits() | none | Promise<LimitsResponse> | Check whether the account can create or operate Boxes before starting work. |
repos({ sync, limit, cursor, sort, q, selected }?) | optional sync, pagination, search, and selected-only filters | Promise<ReposResponse> | List GitHub installations, repositories, and selected repositories. |
selectRepo({ repoSelectionRequest }) | repositoryId, optional baseBranch | Promise<RepoSelectionResponse> | Select a repository for future Boxes. Use databaseId from repos() as repositoryId. |
apiKeys() | none | Promise<ApiKeysResponse> | List API key metadata. Raw secrets are not returned. |
createApiKey({ apiKeyCreateRequest }?) | optional name | Promise<ApiKeysResponse> | Create an API key. Store response.secret immediately; it is returned once. |
rotateApiKey({ apiKeyId }) | API key id | Promise<ApiKeysResponse> | Rotate an API key secret. Store response.secret immediately; it is returned once. |
deleteApiKey({ apiKeyId }) | API key id | Promise<ApiKeyDeleteResponse> | Delete an API key. |
secrets() | none | Promise<SecretsResponse> | Read the current environment variables and secret files configured for Boxes. |
updateSecrets({ secretsUpdateRequest }) | envContents, secretFiles | Promise<SecretsResponse> | Replace the complete secret setup. Send every env var and file that should remain. |
boxes({ limit, cursor, sort, state }?) | optional pagination and state filter | Promise<BoxListResponse> | List Boxes for the account. |
create({ createBoxRequest }?) | optional ttlSeconds | Promise<CreateBoxResponse> | Create a Box. Use ttlSeconds: null to disable auto-stop. |
get({ boxId }) | Box id | Promise<BoxInfoResponse> | Fetch the latest Box state and connection fields. |
update({ boxId, updateBoxRequest }) | Box id plus name and/or ttlSeconds | Promise<BoxInfoResponse> | Rename a Box or change its auto-stop TTL. |
stop({ boxId }) | Box id | Promise<BoxActionResponse> | Stop/archive a Box. |
resume({ boxId }) | Box id | Promise<BoxActionResponse> | Resume an archived Box. Poll get() until it is ready. |
fork({ boxId }) | Box id | Promise<BoxActionResponse> | Create a new Box from the source Box snapshot. |
remove({ boxId }) | Box id | Promise<DeleteBoxResponse> | Delete a Box record and associated machine resources when allowed. |
prompt({ boxId, promptRequest }) | Box id plus provider, prompt, optional model, optional reasoningEffort | Promise<PromptResponse> | Queue work inside a Box. Returns promptRun.status and promptId. |
promptRunStatus({ boxId, promptId }) | Box id and prompt id | Promise<PromptRunResponse> | Read first-class prompt run status. |
events({ boxId, limit, cursor, sort, type }) | Box id plus optional pagination/filtering | Promise<EventsResponse> | Read typed event history for a Box. |
readFile({ boxId, path, encoding }) | Box id and relative path | Promise<FileReadResponse> | Deterministically read a text/base64 file from the Box work directory. |
writeFile({ boxId, fileWriteRequest }) | Box id plus relative path/content | Promise<FileWriteResponse> | Deterministically write a text/base64 file. |
command({ boxId, commandRequest }) | Box id plus command/cwd/timeout | Promise<CommandResponse> | Execute a bounded command in the Box work directory. |
artifact({ boxId, path }) | Box id and relative path | Promise<Blob> | Download an artifact as bytes. |
interrupt({ boxId }) | Box id | Promise<BoxActionResponse> | Interrupt current work in a running Box. |
desktop({ boxId, vnc, theme, requestBody }) | Box id plus optional desktop parameters. For VNC, send requestBody: { publicAccess: true } to return a URL without _token. | Promise<DesktopResponse> | Create or fetch a desktop streaming URL. Treat returned URLs as secrets. If provisioning is true, poll again. |
sshKey({ boxId, sshKeyRequest }) | Box id plus public SSH key | Promise<SshKeyResponse> | Add a public SSH key for Box SSH access. |
Waiters and helpers
The package exports first-class waiters and deterministic file/command helper functions:waitForPrompt/waitForPromptDone instead of inferring completion from box.state plus event polling. Use streamPrompt or streamEvents when you need incremental response/tool-call events as work runs.
Streaming responses and tool calls
The SDK now exportsstreamEvents and streamPrompt for response streaming. They use the Box v1 events cursor API under the hood, so no separate SSE or WebSocket endpoint is required. response events carry text in event.data.content; streaming partials set event.data.isStreaming; tool-call events are response events with event.data.tools.
streamEvents(box, boxId, { type: "prompt,response,git_checkpoint" }) and stop it with an AbortController.
Operation request types
These exported interfaces wrap method parameters forBoxApi methods.
| Type | Fields | Used by |
|---|---|---|
ArtifactRequest | boxId, path | artifact() |
BoxesRequest | limit, cursor, sort, state | boxes() |
CommandOperationRequest | boxId, commandRequest | command() |
CreateRequest | createBoxRequest | create() |
CreateApiKeyRequest | apiKeyCreateRequest | createApiKey() |
DeleteApiKeyRequest | apiKeyId | deleteApiKey() |
DesktopRequest | boxId, vnc, theme, requestBody | desktop(); set requestBody.publicAccess for an ungated VNC URL. |
EventsRequest | boxId, limit, cursor, sort, type | events() |
ForkRequest | boxId | fork() |
GetRequest | boxId | get() |
InterruptRequest | boxId | interrupt() |
PromptOperationRequest | boxId, promptRequest | prompt() |
PromptRunStatusRequest | boxId, promptId | promptRunStatus() |
ReadFileRequest | boxId, path, encoding | readFile() |
RemoveRequest | boxId | remove() |
ReposRequest | sync, limit, cursor, sort, q, selected | repos() |
ResumeRequest | boxId | resume() |
RotateApiKeyRequest | apiKeyId | rotateApiKey() |
SelectRepoRequest | repoSelectionRequest | selectRepo() |
SshKeyOperationRequest | boxId, sshKeyRequest | sshKey() |
StopRequest | boxId | stop() |
UpdateRequest | boxId, updateBoxRequest | update() |
UpdateSecretsRequest | secretsUpdateRequest | updateSecrets() |
WriteFileRequest | boxId, fileWriteRequest | writeFile() |
BoxesSortEnum | "asc", "desc" | boxes({ sort }) |
DesktopVncEnum | 1 | desktop({ vnc }) |
DesktopThemeEnum | "light", "dark" | desktop({ theme }) |
EventsSortEnum | "asc", "desc" | events({ sort }) |
ReadFileEncodingEnum | "utf8", "base64" | readFile({ encoding }) |
ReposSortEnum | "asc", "desc" | repos({ sort }) |
Model types
TypeScript models use camelCase fields.| Type | Fields | Notes |
|---|---|---|
ApiKey | id, name, keyPrefix, keyLastFour, createdAt, lastUsedAt | Metadata only; not the raw secret. |
ApiKeyCreateRequest | name | Optional display name. |
ApiKeyDeleteResponse | ok, type, apiKeys | Returned after deletion with the remaining key metadata. |
ApiKeysResponse | ok, type, apiKeys, apiKey, secret | secret is present after create/rotate only. |
Box | id, name, state, url, ip, createdAt, updatedAt, archiveAfter, desktopAvailable, desktopUrl, snapshotAvailable, snapshotCompletedAt | desktopUrl can contain a token; redact it. |
BoxActionResponse | ok, type, id, status, box | Returned by lifecycle actions such as stop, resume, fork, and interrupt. |
BoxInfoResponse | ok, type, box | Returned by get() and update(). |
BoxEvent | id, type, timestamp, taskId, data, plus additional fields | Extensible event object returned inside EventsResponse.events. Branch on each event type. |
BoxListResponse | ok, type, boxes, pageInfo | Returned by boxes(). |
CommandRequest | command, cwd, timeoutSeconds | Bounded command execution request. |
CommandResponse | ok, type, success, exitCode, signal, stdout, stderr, stdoutTruncated, stderrTruncated, timedOut, cwd, startedAt, finishedAt | Returned by command() and execCommand(). |
CompletionEvent | id, type, timestamp, taskId, data | Event subtype for task_notification and compaction_complete. |
CreateBoxRequest | ttlSeconds | Seconds before auto-stop; null disables auto-stop. |
CreateBoxResponse | ok, type, status, ttlSeconds, box | Returned immediately after creation starts. |
DeleteBoxResponse | ok, type, id, status | Returned by remove(). |
DesktopResponse | ok, type, success, desktopUrl, ip, mode, provisioning, message | If provisioning is true, poll desktop() again. |
ErrorEnvelope | ok, type, status, code, message, requestId, error | Non-2xx response body. Include requestId in support logs. |
ErrorEnvelopeError | code, message, status, details | Structured error details. |
ErrorEvent | id, type, timestamp, taskId, data | Event subtype for usage_limit and shield. |
EventsResponse | ok, type, id, events, pageInfo | events contains Box event objects. |
FileReadResponse | ok, type, success, path, encoding, size, content | Returned by readFile() and readText(). |
FileWriteRequest | path, content, encoding | Write a UTF-8 string or base64 payload. |
FileWriteResponse | ok, type, success, path, encoding, size | Returned by writeFile() and writeText(). |
GitCheckpointEvent | id, type, timestamp, taskId, data | Event subtype for git_checkpoint. |
GitCheckpointEventData | commitSha, commitMessage, commitUrl, branch, filesChanged, additions, deletions, pushed | Git checkpoint event payload. |
LimitsFields | accessTier, blockedReason, currentLimits, standardLimits, trialLimits, upgradeEffects, canStart, checkoutRequired, startBlockedReason, contactMessage, activeBoxes, activeStates, maxActiveBoxes, maxCreationRequestsPerMinute, maxCreationRequestsPerDay, hasPaymentHistory, _package, subscriptionQuotaSeconds, subscriptionRemainingSeconds, packBalanceSeconds, creditPurchasedSeconds, creditUsedSeconds, liveUsageSeconds, creditSecondsPerDollar, billingStatus, subscriptionStatus, subscriptionCancelAtPeriodEnd, hasSubscription, subscriptionTrialEndsAt, subscriptionCurrentPeriodEnd, creditBalanceSeconds | Shared limit and billing-access fields. Use canStart and startBlockedReason before creating Boxes. |
LimitsFieldsCurrentLimits | activeBoxes, creationRatePerMinute, creationRequestsPerDay | Numeric quota limits. |
LimitsResponse | ok, type, plus all LimitsFields fields | Returned by limits(). |
MeResponse | ok, type, user | Authenticated account response. |
MeResponseAllOfUser | login, email | User identity fields. |
PageInfo | nextCursor, hasMore, limit | Optional pagination metadata on list responses. |
PromptEvent | id, type, timestamp, taskId, data | Event subtype for prompt. |
PromptEventData | prompt, status, isReverted | Prompt event payload. |
PromptRequest | provider, model, reasoningEffort, prompt | provider is codex or claude-code. Omit model to use the saved default. |
PromptResponse | ok, type, id, promptId, promptRun, status, provider, model, reasoningEffort | Returned after work is queued. |
PromptRun | id, promptId, boxId, status, done, createdAt, model, reasoningEffort | First-class prompt run state. |
PromptRunResponse | ok, type, id, promptRun | Returned by promptRunStatus(). |
ResponseEvent | id, type, timestamp, taskId, data | Event subtype for response. |
ResponseEventData | content, model, tools, isStreaming | Response event payload. |
RepoSelectionRequest | repositoryId, baseBranch | repositoryId is a databaseId from repos(). |
RepoSelectionResponse | ok, type, success, environmentId, selectedRepositories | Returned by selectRepo(). |
ReposResponse | ok, type, installations, environmentId, selectedRepositories, pageInfo | Repository inventory and current selections. |
Repository | id, databaseId, name, fullName, _private, permissions, pushedAt | Use databaseId when selecting a repository. |
RepositoryInstallation | type, accountLogin, accountAvatarUrl, repositories | Group of repositories available through one installation/account. |
SecretFile | path, contents | Treat contents as sensitive. |
SecretsResponse | ok, type, success, environmentId, envContents, secretFiles, pushed | Current secret setup. Treat envContents and secretFiles as sensitive. |
SecretsUpdateRequest | envContents, secretFiles | Full replacement request for secrets. |
SelectedRepository | id, databaseId, name, fullName, _private, permissions, pushedAt, baseBranch, setupRoutineId, setupScript, setupBlocking, preCommitHooks | Repository selected for future Boxes. |
SelectedRepositoryAllOfPreCommitHooks | id, script, blocking | Pre-commit hook configured for a selected repository. |
SshKeyRequest | key | Public SSH key in OpenSSH format. |
SshKeyResponse | ok, type, success, machineIp, sshUser | Returned after adding an SSH key. |
SuccessBase | ok, type | Base success-envelope fields. |
UnknownEvent | type, plus additional properties | Forward-compatible fallback for event types the SDK does not model yet. |
UpdateBoxRequest | name, ttlSeconds | Send only fields you want to change. ttlSeconds: null disables auto-stop. |
Errors
Non-2xx responses reject with aResponseError. Read the status and parse the JSON body for the structured Box error envelope. Redact API keys, Box secrets, SSH keys, and desktop URLs.