Skip to main content

Common Issues

This guide covers the most common issues developers encounter when using the AI SDK and their solutions.

API and Authentication Errors

Missing API Key

Issue:
Solution: Ensure your API key is properly configured:

Invalid API Key Format

Issue:
Solution:
  • OpenAI keys start with sk-
  • Anthropic keys start with sk-ant-
  • Check for whitespace or special characters
  • Verify the key hasn’t expired

Rate Limiting

Issue:
Solution: Implement retry logic with exponential backoff:
Or handle manually:

Streaming Issues

Stream Not Working When Deployed

Issue: Streaming works locally but not in production. Solution: Ensure your deployment platform supports streaming:
For Vercel:
  • Use Edge Runtime or Node.js 18+
  • Ensure runtime = 'edge' or runtime = 'nodejs' is set

Buffering by Proxy/CDN

Issue: Responses are buffered by proxies or CDNs. Solution: Disable response buffering:

Stream Timeout on Vercel

Issue: Streams timeout after 30 seconds on Vercel Hobby. Solution:
  • Upgrade to Vercel Pro for 5-minute timeouts
  • Or use Edge Runtime (no timeout):

RSC Issues

Streamable UI Not Updating

Issue: UI remains in loading state. Solution: Always call .done():

Server Actions in Client Components

Issue:
Solution: Move server actions to a separate file:

File Extension Error (.ts vs .tsx)

Issue:
Solution: Use .tsx extension for files with JSX:
Changed from .ts to .tsx

Tool Calling Issues

Tools Not Being Called

Issue: Model doesn’t call your tools. Solution:
  1. Improve tool descriptions:
  1. Use toolChoice: 'required':

Invalid Tool Input

Issue:
Solution: Validate and provide better schemas:

TypeScript Issues

Model Not Assignable to Type

Issue:
Solution: Use the model instance, not a string:

Cannot Find Namespace ‘JSX’

Issue:
Solution: Ensure tsconfig.json includes React types:

Message Format Issues

useChat Stale Body Data

Issue: Chat messages contain stale or incorrect data. Solution: Ensure proper message state management:

Failed to Parse Stream

Issue:
Solution: Ensure the API returns the correct format:

Performance Issues

Slow TypeScript Compilation with Zod

Issue: TypeScript compilation is very slow. Solution: Use simpler schemas or increase TypeScript memory:
Or simplify schemas:

High Memory Usage with Images

Issue: Application uses too much memory when processing images. Solution: Stream images or process in batches:

Next Steps