Cancellation
How to abort an in-flight build, skill, or augmenter from the client. Cancellation is cooperative — the server stops the run and may partially refund quota.
#AbortController / context
The SDK accepts a standard cancellation primitive — an AbortSignal in TS, a context.Context in Go, an internal cancel handle in Python.
const ac = new AbortController();
const stream = client.apps.generateStream(
{ prompt: 'pricing page' },
{ signal: ac.signal },
);
// Cancel after 30s
setTimeout(() => ac.abort(), 30_000);
try {
for await (const ev of stream) {
if (shouldStop(ev)) ac.abort();
}
} catch (e) {
if (ac.signal.aborted) console.log('cancelled cleanly');
else throw e;
}#Server-side cancel
For long-lived runs (or when you don't have the original connection), explicitly cancel by run id:
await client.runs.cancel('run_abc');Both the streaming client and the explicit endpoint converge on the same effect — the server halts the pipeline at the next safe checkpoint and emits a final { type: "cancelled" } event before closing.
#Quota refund policy
Cancellation timing affects whether quota is refunded:
- Before planner finishes — full refund.
- After planner, before code agents start — partial refund (planner tokens are committed).
- After any code agent has emitted a file — no refund. The artifacts are kept; you can resume from this state.
#What happens to artifacts
Files committed before cancel stay in the workspace. The chat remains valid — you can send a follow-up prompt to continue or fix what was started. To discard everything from a cancelled run, use the rollback endpoint or simply send a new full prompt.