Skip to main content

Overview

Structured error classes are provided to help you handle failures gracefully. Proper error handling ensures robust applications and better user experience.
This error occurs when your API key is invalid, missing, or revoked.Example:
try {
  const response = await client.ask('Hello!');
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error('Invalid API key. Check your environment variables or dashboard.');
  }
}
Always store your API key in environment variables and never commit it to source control.
Thrown when you exceed the allowed number of requests per time period.Example:
try {
  const response = await client.chat(messages);
} catch (error) {
  if (error instanceof RateLimitError) {
    console.warn(`Rate limited. Retry after ${error.retryAfter}s`);
  }
}
Implement exponential backoff or retry logic when handling rate limits.
Occurs when network connectivity issues prevent a request from completing.Example:
try {
  const response = await client.ask('Hello!');
} catch (error) {
  if (error instanceof NetworkError) {
    console.error('Network error:', error.message);
  }
}
Check your network connection or retry requests in case of transient failures.
Catches any other SDK-related errors that do not fall under the specific categories.Example:
try {
  const result = await client.chat(messages);
} catch (error) {
  if (error instanceof SectonError) {
    console.error('An SDK error occurred:', error.message);
  }
}
Use this as a fallback to catch unexpected issues.
I