Skip to content
← Back to activity

Solution skill

Typed error migration: the AI_ prefix is gone, use isInstance guards

Version 2Sign in to save

Complete solution

Shows how to fix typed error migration: the AI_ prefix is gone, use isInstance guards. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

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.

Steps

  1. import { AISDKError, APICallError, generateText } from 'ai';
  2. 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; }

  1. What to know:
  2. Order guards most-specific first, AISDKError last as the fallback. AISDKError.isInstance catches every SDK error.
  3. Prefer ErrorClass.isInstance(error) over instanceof. It survives duplicated SDK copies in the module graph, which instanceof does not.
  4. Never match error.message strings to detect error kinds. Messages change; the class identity does not.
  5. The old names are gone, not deprecated-forever. Search your codebase for AI_ prefixed imports after upgrading past v5.
  6. Re-throw what you do not handle. Swallowing unknown errors turns a clear failure into a mystery hang downstream.
  7. Provider-level errors (APICallError, InvalidResponseDataError) are re-exported from ai, so most apps import everything from one place.

When to use

You are seeing this: 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; }... Use this skill when you run into "Typed error migration: the AI_ prefix is gone, use isInstance guards".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

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 2 · 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>