An abort/cancel mechanism exists for in-flight AI requests
Why it matters
When a user navigates away mid-generation or realizes their prompt was wrong, the model continues generating and billing you for every token — even though no user will ever read the output. Without an abort mechanism, you pay for the full completion on every abandoned session. On a model that generates 1,000-token responses at $0.01 per completion, even a 5% abandonment rate on 10,000 daily requests costs $50/day in tokens that were never seen. OWASP LLM10, CWE-770, and NIST AI RMF MANAGE 1.3 all require application-level controls to terminate runaway resource consumption.
Severity rationale
High because without abort support, navigating away or canceling a request does not stop generation — the model keeps billing for output no user will ever see.
Remediation
Wire the stop() function from useChat to a visible cancel button that appears while generation is in progress. The Vercel AI SDK propagates the abort signal to the provider automatically.
// src/components/chat.tsx
import { useChat } from "ai/react";
export function Chat() {
const { messages, input, handleInputChange, handleSubmit, isLoading, stop } = useChat();
return (
<form onSubmit={handleSubmit}>
{messages.map(m => <div key={m.id}>{m.content}</div>)}
<input value={input} onChange={handleInputChange} disabled={isLoading} />
{isLoading
? <button type="button" onClick={stop}>Stop generating</button>
: <button type="submit">Send</button>
}
</form>
);
}
For manual implementations using the OpenAI SDK directly, pass signal: controller.signal to chat.completions.create and call controller.abort() on cancel. Verify by starting a long generation, clicking Stop, and confirming server logs show a partial token count rather than the full expected output.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the AI Token Optimization Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- owasp-llm:2025 · LLM10 — Unbounded Consumption
- cwe · CWE-770 — Allocation of Resources Without Limits or Throttling
- nist-ai-rmf:1.0 · MANAGE 1.3 — Responses to identified AI risks are developed
Taxons
History
- 2026-04-18·v1.0.0·Initial import from ai-token-optimization·automated