Skip to main content

Error classes

ClassWhen thrownKey properties
BabySeaErrorAPI returns non-2xxstatus, code, type, message, retryable, requestId, rateLimit, body
BabySeaTimeoutErrorRequest exceeds timeoutmessage
BabySeaRetryErrorAll retry attempts exhaustedlastError, attempts

Catching errors

TypeScript
import {
  BabySea,
  BabySeaError,
  BabySeaTimeoutError,
  BabySeaRetryError,
} from 'babysea';

const client = new BabySea({ apiKey: 'bye_...', region: 'us' });

try {
  await client.generate('google/nano-banana', {
    generation_prompt: 'A cute baby seal',
  });
} catch (err) {
  if (err instanceof BabySeaError) {
    console.log(err.status);     // 402
    console.log(err.code);       // 'BSE1004'
    console.log(err.type);       // 'insufficient_credits'
    console.log(err.message);    // human-readable description
    console.log(err.retryable);  // false
    console.log(err.requestId);  // request trace ID

    // Rate limit info (present on 429 responses)
    if (err.rateLimit) {
      console.log(err.rateLimit.limit);
      console.log(err.rateLimit.remaining);
      console.log(err.rateLimit.reset);
      console.log(err.rateLimit.retryAfter);
    }

    // Provider-level errors (when failover occurred)
    if (err.body.error.provider_errors) {
      for (const pe of err.body.error.provider_errors) {
        console.log(pe.provider); // 'replicate' | 'fal' | 'byteplus' | 'cloudflare'
        console.log(pe.code);
        console.log(pe.message);
      }
    }
  }

  if (err instanceof BabySeaTimeoutError) {
    console.log(err.message); // 'Request timed out after 30000ms'
  }

  if (err instanceof BabySeaRetryError) {
    console.log(err.attempts);              // total attempts made
    console.log(err.lastError.status);      // HTTP status of the last attempt
    console.log(err.lastError.code);        // BSE error code of the last attempt
  }
}

Error codes

Errors are grouped into five categories by prefix. BSE1xxx - Authentication & Authorization
CodeTypeHTTPRetryableDescription
BSE1001authentication_required401NoMissing API key
BSE1002authentication_failed401NoInvalid API key
BSE1003insufficient_permissions403NoAPI key lacks permission for this resource
BSE1004insufficient_credits402NoNot enough credits for this generation
BSE1005rate_limit_exceeded429YesPer-account rate limit exceeded, check rateLimit.retryAfter
BSE1006auth_rate_limited429YesToo many requests from this IP (pre-auth)
BSE1007ip_not_allowed403NoIP not in API key allowlist
BSE1008account_not_found404NoAccount associated with this key was not found
BSE2xxx - Input Validation
CodeTypeHTTPRetryableDescription
BSE2001invalid_input400NoInvalid request parameters
BSE2002file_too_large422NoInput file exceeds maximum allowed dimensions
BSE2003file_too_small422NoInput file below minimum required dimensions
BSE2004unsupported_file_format422NoFile format not supported (JPEG, PNG, WebP only)
BSE2005file_load_error422NoFailed to load or process the provided file
BSE2006content_policy_violation422NoInput flagged by content safety filter
BSE2007file_size_exceeded422NoFile exceeds maximum allowed size in bytes
BSE2008parameter_out_of_range422NoA parameter value is outside the allowed range
BSE2009file_download_error422NoFailed to download file from URL (must be public)
BSE2010request_body_too_large413NoRequest body exceeds 100 KB
BSE2011generation_not_found404NoGeneration ID not found or not owned by this account
BSE2012generation_not_cancelable409NoGeneration already completed, failed, or canceled
BSE2013generation_cancel_window_expired409NoCancel window expired (must cancel within 12 seconds)
BSE3xxx - Model/Configuration
CodeTypeHTTPRetryableDescription
BSE3001model_not_found404NoUnknown model identifier
BSE3002model_not_configured500NoModel exists but is not properly configured
BSE3003feature_not_supported422NoFeature or parameter combination not supported by this model
BSE4xxx - Provider/Upstream
CodeTypeHTTPRetryableDescription
BSE4001provider_timeout504YesProvider did not respond within the time limit
BSE4002provider_out_of_memory502YesModel ran out of memory on the provider
BSE4003all_providers_failed502YesAll providers failed, failover exhausted
BSE4004provider_internal_error502YesProvider encountered an internal error
BSE4005provider_unavailable503YesProvider temporarily unavailable
BSE4006prediction_canceled409NoPrediction was canceled before completion
BSE4007provider_health_check_failed502YesModel failed its health check on the provider
BSE4008provider_start_error502YesProvider failed to start the prediction
BSE4009provider_upload_failed502YesFile upload to the provider failed
BSE5xxx - Internal Server
CodeTypeHTTPRetryableDescription
BSE5001internal_server_error500NoUnexpected internal error
BSE5002database_error500NoDatabase read/write failure
BSE5003storage_error500NoFile storage read/write failure

Auto-retry behavior

The SDK automatically retries errors where retryable is true - the SDK checks this field on every error, not the HTTP status code:
  • Default: 2 retries (3 total attempts).
  • Retryable errors: rate limits (BSE1005, BSE1006) and most upstream provider failures (BSE4001, BSE4002, BSE4003, BSE4004, BSE4005, BSE4007, BSE4008, BSE4009).
  • Auth, input validation, model configuration, and internal server errors are never retried.
  • Respects Retry-After header on 429 responses.
  • Falls back to exponential backoff for other retryable errors: 1s → 2s → 4s → … (capped at 30s).
TypeScript
// Disable retries
const client = new BabySea({ apiKey: 'bye_...', region: 'us', maxRetries: 0 });

// More retries for batch jobs
const client = new BabySea({ apiKey: 'bye_...', region: 'us', maxRetries: 5 });

Rate limit headers

Rate limit headers are included on every response:
HeaderDescription
X-RateLimit-LimitMaximum requests per window
X-RateLimit-RemainingRequests remaining in the current window
X-RateLimit-ResetUnix timestamp when the window resets
Retry-AfterSeconds to wait (only on 429 responses)

Troubleshooting common errors

”insufficient_credits” (BSE1004)

What happened: Your account doesn’t have enough credits for this generation. Solutions:
  • Check your balance: await client.billing()
  • Estimate cost first: await client.estimate(model, count)
  • Purchase credits from Credit packs or upgrade your plan

”all_providers_failed” (BSE4003)

What happened: All inference providers (Replicate, FAL, BytePlus, Cloudflare) failed. This is rare and usually temporary. Solutions:
  • The SDK retried automatically (check maxRetries setting)
  • Wait 30 seconds and retry manually
  • Check provider status using client.health.providers() - see Provider health
  • Try a different model supported by different providers

”generation_not_found” (BSE2011)

What happened: The generation ID doesn’t exist or isn’t owned by your account. Solutions:
  • Verify the generation_id - it should be a UUID
  • Make sure you’re using the correct API key
  • Generations are deleted if they fail billing checks

”rate_limit_exceeded” (BSE1005)

What happened: Your account exceeded the request rate limit for your plan. Solutions:
  • Wait for the window to reset (see X-RateLimit-Reset header)
  • The SDK respects Retry-After and retries automatically by default
  • Upgrade your plan for higher rate limits
  • Batch requests efficiently to avoid unnecessary calls

Authentication failures

CodeCauseFix
BSE1001Missing API keyEnsure apiKey is set in client config or env
BSE1002Invalid API keyVerify the key starts with bye_ and is not expired
BSE1007IP not allowedAdd your IP to the key’s allowlist or remove allowlist
BSE1008Account not foundThe associated account was deleted