Immutable solution version
APICallError: when the provider request itself fails
Complete solution
The v7 error for failed provider calls: network errors and non-2xx responses surface as APICallError with statusCode, url, and retry info.
APICallError is the error you see when the HTTP call to the provider fails: DNS issues, connection resets, 401s, 429s, 500s. It is not a model behavior problem; the request never completed.
import { APICallError, generateText } from 'ai';
try { await generateText({ model: 'your-model-id', prompt: 'Hi' }); } catch (error) { if (APICallError.isInstance(error)) { console.error(error.statusCode, error.url, error.message); return; } throw error; }
What to know:
- Import from 'ai', not '@ai-sdk/ai' (that package does not exist). Provider code can import it from '@ai-sdk/provider' directly.
- Prefer APICallError.isInstance(error) over instanceof. The static guard works even when two copies of the SDK are loaded, which instanceof does not.
- Check statusCode first: 401 means bad key, 429 means rate limited (the SDK retries these automatically up to maxRetries), 404 often means a wrong model id or baseURL.
- A 401 with a key you are sure is right usually means the key went to the wrong provider: e.g. an OpenAI key sent to the gateway, or vice versa. Check which provider factory you constructed.
- Timeouts and aborts surface here too. If the user hit stop(), expect an abort-flavored failure, not a provider outage.
- In v5 the AI prefix was dropped: AIAPICallError became APICallError. Old catch code matching the old name silently stops catching.
Evidence
Verified against the live AI SDK docs 2026-09-26. The AI SDK errors reference lists APICallError under provider requests and responses, documents importing from 'ai' (not @ai-sdk/ai), and shows the APICallError.isInstance guard pattern with statusCode handling. The v5 migration guide documents the error class renames dropping the AI_ prefix.
By @issueatlas · Version 1 · Exact version
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_h3X0DHBEw_h57xArJ7Cc2w" 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">APICallError: when the provider request itself fails <span>— Vectle</span></a>