Runtime operations
The universal RuntimeClient contract every provider implements. Optional methods can be absent. Check both advertised support and method presence before calling; optional chaining alone can hide an unavailable operation.
getRuntimeCapabilities
Response
| Field | Type | Description |
|---|---|---|
| providerKind | string | Provider identity, e.g. "claude". |
| protocolVersion | string | null | Wire protocol version when applicable. |
| auth | { type?: string; required?: boolean } | Auth expectation. |
| supports | Partial<Record<RuntimeSurface, boolean>> | Per-surface capability flags. |
Example
const caps = await client.getRuntimeCapabilities();
if (caps.supports.batch) { /* … */ }startRun
Request body / Parameters
| Field | Type | Required | Description |
|---|---|---|---|
| input | string | RuntimeRunMessage[] | required | Prompt string or conversation messages ({ role, content }). |
| instructions | string | optional | System / developer instructions (Anthropic system). |
| model | string | optional | Model id; configure an available default or supply it explicitly. |
| tools | Record<string, unknown>[] | optional | Provider-native tool definitions. |
| metadata | Record<string, unknown> | optional | Opaque caller metadata. |
| dryRun | boolean | optional | Validate/echo without executing; yields status: "dry_run". |
Response
| Field | Type | Description |
|---|---|---|
| run_id | string | Run identifier. |
| status | RuntimeRunState | started/running/completed/failed/cancelled/stopping/dry_run. |
| model | string | Resolved model. |
| output | string | Final output text (when completed). |
| response | string | Alias carrying provider response text. |
| error | string | Present on failed. |
| tokens | RuntimeUsage | Normalized token usage (prefer over usage). |
| usage | Record<string, number> | Deprecated raw provider counts. |
Example
const run = await client.startRun({
input: "Summarize the changelog.",
model,
});
const view = { runId: run.run_id, status: run.status, text: run.output };getRun
Optional on the type, but implemented by every shipping provider. Synchronous providers (Claude Messages, AGY) serve getRun from a client-side SynchronousRunStore (remembered terminal status; unknown ids degrade without throwing). Codex and gateway providers poll real upstream run handles. Returns the same RuntimeRunStatus shape as startRun.
Example
const status = await client.getRun?.(run.run_id);cancelRun
Optional. Same availability rules as getRun.
Response
| Field | Type | Description |
|---|---|---|
| status | string | Post-cancel state (e.g. "cancelling", "cancelled"). |
streamRun
Optional. Gateways use a subscribe-by-runId model and omit this, exposing a RunEventStreamProvider instead. handlers receive canonical RunStreamEvents.
Example
await client.streamRun?.(
{ input: "Write a haiku.", model },
{ onEvent: (e) => process.stdout.write(e.event) },
);submitBatch
Implemented by Claude and Codex. Provider-specific batch endpoints and result retrieval differ — see Claude, Codex.
Request body / Parameters
| Field | Type | Required | Description |
|---|---|---|---|
| requests[].customId | string | required | Caller correlation id, echoed on the result. |
| requests[].body | RuntimeRunStartBody | required | The run to enqueue. |
Response
| Field | Type | Description |
|---|---|---|
| batch_id | string | Batch identifier. |
| status | RuntimeBatchState | in_progress/canceling/completed/cancelled/failed. |
| counts | RuntimeBatchCounts | total/processing/succeeded/errored/canceled/expired. |
| resultsAvailable | boolean | True once results are retrievable. |
Example
const batch = await client.submitBatch?.([
{ customId: "a", body: { input: "One" } },
{ customId: "b", body: { input: "Two" } },
]);getBatch
Poll until resultsAvailable is true. Same RuntimeBatchStatus response as submitBatch.
cancelBatch
Returns the updated RuntimeBatchStatus.
getBatchResults
Throws an EndpointNotFound-class error if the batch has not ended — poll getBatch first. Codex has no single results endpoint: read the batch to obtain its output/error file id, then download the JSONL via the Files API (GET /v1/files/:id/content).
Response
| Field | Type | Description |
|---|---|---|
| customId | string | Echoed submission id. |
| outcome | RuntimeBatchOutcome | succeeded/errored/canceled/expired. |
| run | RuntimeRunStatus | Present when outcome === "succeeded". |
| error | string | Present on failure. |