AbortSignal gives your UI a working Stop button — aborting cancels the underlying provider request so the user stops being billed for tokens they asked to stop.
Quick Start
1
Simple Usage
Pass a trailing
signal to chat() and abort it to stop the call.2
Agent-level Default
Set
signal on the agent config so every call shares one controller. An explicit per-call signal still wins.How It Works
Aborting stops the request itself, not only iterator consumption — no further tokens arrive and no further billing accrues.Choosing Where to Attach the Signal
Pick per-call for a single Stop button; pick agent-level to cancel everything on the agent at once.Configuration Options
SimpleAgentConfig
Agent configuration reference
Agent
Agent class reference
Common Patterns
A. Simple Stop Button (per call)
B. Agent-level Default (one controller, many calls)
C. Per-call Override Wins Over the Agent Default
Streaming
Aborting a stream stops the provider request, so no further tokens arrive and no further billing accrues.Tools
When the signal aborts after the model returned tool calls, the agent stops before invoking the tool, so side effects never run. If you write custom tools, receivectx.signal and check it inside long-running work:
Timeouts + Cancellation Together
The AI-SDK backend merges your caller signal with its own timeout controller usingAbortSignal.any (with a manual fallback for Node < 20). Aborting either cancels the request; a caller abort is terminal and never consumes a retry.
Best Practices
Reuse one AbortController per user action
Reuse one AbortController per user action
Create a fresh
AbortController for each user action (one Stop button press), not a single app-wide one. Once aborted, a controller cannot be reused.Wrap chat() in try/catch and check the signal
Wrap chat() in try/catch and check the signal
Catch the thrown error and check
controller.signal.aborted (or err.name === 'AbortError') to tell a user cancellation apart from a real failure.Agent-level for 'cancel everything', per-call for one request
Agent-level for 'cancel everything', per-call for one request
Use an agent-level
signal when you want one controller to stop every in-flight call. Use a per-call signal for a single specific request — it wins over the agent default.Pass a reason to abort()
Pass a reason to abort()
Call
controller.abort(reason) — the reason surfaces in the thrown error, so your UI can show why the request stopped.Related
Agent
Full agent configuration
Execution
Timeouts and retries

