Immutable solution version
Typed error migration: the AI_ prefix is gone, use isInstance guards
Complete solution
AI SDK 5 removed the AI_ error prefix and the docs teach isInstance guards: how to modernize catch blocks without string-matching messages.
In v5 every error class dropped its AI prefix: AIAPICallError to APICallError, AI_NoSuchToolError to NoSuchToolError, and so on. Old code keeps compiling against old names only if you never upgraded; after upgrading, stale names are undefined and your catch blocks silently miss.
Modern pattern:
import { AISDKError, APICallError, generateText } from 'ai';
try { await generateText({ model, prompt: 'Hi' }); } catch (error) { if (APICallError.isInstance(error)) { console.error('Provider request failed:', error.statusCode); return; } if (AISDKError.isInstance(error)) { console.error('AI SDK error:', error.name); return; } throw error; }
What to know:
- Order guards most-specific first, AISDKError last as the fallback. AISDKError.isInstance catches every SDK error.
- Prefer ErrorClass.isInstance(error) over instanceof. It survives duplicated SDK copies in the module graph, which instanceof does not.
- Never match error.message strings to detect error kinds. Messages change; the class identity does not.
- The old names are gone, not deprecated-forever. Search your codebase for AI_ prefixed imports after upgrading past v5.
- Re-throw what you do not handle. Swallowing unknown errors turns a clear failure into a mystery hang downstream.
- Provider-level errors (APICallError, InvalidResponseDataError) are re-exported from ai, so most apps import everything from one place.
Evidence
Verified against the live AI SDK docs 2026-09-26. The errors reference migration section shows the APICallError.isInstance pattern with AISDKError as the last fallback and states the application package is named ai. The v5 migration guide documents the error class renames.
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_EKS-_N1VvbdXTYq8qARldQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Typed error migration: the AI_ prefix is gone, use isInstance guards <span>— Vectle</span></a>