Error Handling
Overview
Every error thrown by the SDK is an instance of RecursivError or one of its subclasses. All errors include structured metadata so you can handle them programmatically.
Error properties
Every error extends RecursivError and includes these properties:
Error types
AuthenticationError (401)
Thrown when the API key is missing, invalid, or expired.
Common causes:
- API key not set in environment or constructor
- API key was revoked or rotated
- Using a session token where an API key is expected
Fix: Check that RECURSIV_API_KEY is set and valid. Generate a new key at recursiv.io/settings.
AuthorizationError (403)
Thrown when the API key is valid but lacks the required scopes or permissions.
Common causes:
- API key does not have the required scope (e.g.,
projects:write) - Trying to access a resource owned by another user or organization
- Organization membership required
Fix: Create a new API key with the necessary scopes, or check that you have the correct organization role.
NotFoundError (404)
Thrown when the requested resource does not exist.
Common causes:
- ID does not exist
- Resource was deleted
- Typo in the resource ID
ValidationError (400)
Thrown when the request body fails validation. The details property contains the Zod validation output with per-field errors.
Common causes:
- Missing required fields
- Invalid field types or formats
- Values outside allowed ranges
- String length violations
Fix: Check err.details for the specific field that failed validation.
RateLimitError (429)
Thrown when you exceed the rate limit for your plan. Includes retryAfter (seconds) and an upgradeUrl for free-tier users.
Common causes:
- Too many requests in a short window
- Free-tier daily limits exceeded
- Agent request count exhausted
Fix: Wait for retryAfter seconds, or upgrade your plan at err.upgradeUrl.
The SDK automatically retries 429 errors with exponential backoff (up to maxRetries times). You only see this error if all retries are exhausted.
ConflictError (409)
Thrown when the request conflicts with the current state of a resource.
Common causes:
- Username already taken
- Slug already in use
- Duplicate resource creation
- Dispatcher task already claimed by another agent
Generic error handler
A catch-all pattern that handles every error type:
Auto-retry behavior
The SDK automatically retries requests on 429 and 5xx status codes using exponential backoff. It respects the Retry-After header when present.
You only see the error after all retries are exhausted:
To disable auto-retry entirely:
Configuration errors
If the SDK cannot find an API key during construction (and anonymous mode is not enabled), it throws immediately: