Cancel Runs

Stop an in-flight chat generation or workflow run.

POST/v1/runs/{run_id}/cancel

Closing the stream is not enough

Aborting the HTTP connection client-side only stops you from reading the output — the model keeps generating (and keeps consuming tokens) on the server. Call this endpoint to actually stop the work.

Usage

The run_id is returned on every response and streamed chunk from POST /chat/completions, and as id from POST /runs. One endpoint serves both — cancelling is the same call for chat replies and workflow runs.

Request body

PropertyTypeRequiredDefaultDescription
userstringYesThe same end-user identifier that started the run.
bash
curl https://cloud.xpectrum.dev/v1/runs/d3adbeef-0000-4000-8000-000000000000/cancel \
  -H "Authorization: Bearer xpectrum_XXXXXXXXXXXXXXXX" \
  -H "Content-Type: application/json" \
  -d '{ "user": "user-123" }'
json
{
  "id": "d3adbeef-0000-4000-8000-000000000000",
  "object": "run.cancelled"
}

With the Xpectrum SDK

typescript
let controller: AbortController | undefined;
let runId: string | undefined;

const reply = chat.stream("Write a long essay", {
  getAbortController: (c) => { controller = c; },
  onToken: (delta, full) => render(full),
  onDone: (result) => { runId = result.runId; },
});

controller?.abort();              // UI stops now
if (runId) await chat.cancel(runId); // server stops too