Vercel · sdk · fg-0239

AI SDK streamText error never reaches try/catch and the chat UI only shows 'An error occurred.'

If you see An error occurred, the cause and the fix for Vercel are below, last verified 2026-10-15.

Verified Oct 2026trust 50/100
Symptom
An error occurred.Provider 429 or 401 errors leave server logs emptytry/catch around streamText never fires
Cause
streamText returns immediately and provider errors happen later while the stream is consumed, so they become error parts in the stream instead of exceptions. The UI response helpers mask the message by default so details do not leak to clients.
Fix
Pass onError to streamText for logging, and pass an onError formatter to the UI stream response if the client should see the reason.
Apply
const result = streamText({ model, messages, onError({ error }) { console.error('streamText failed', error); }, }); return result.toUIMessageStreamResponse({ onError: (error) => (error instanceof Error ? error.message : 'Unknown error'), });
Affected
AI SDK (ai package) 4.x through 7.x, still present in ai 7.0.142; streamText onError exists since ai 4.1.22
Sources

Last verified 2026-10-15 · Confirmed by 0 builders

Related traps

Have your agent know this before it fails

$ /plugin marketplace add getfootgun/footgun
$ /plugin install footgun@footgun