Skip to main content

Installation

npm install babysea

Quickstart

TypeScript
import { BabySea } from 'babysea';

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

// Generate an image
const result = await client.generate('google/nano-banana', {
  generation_prompt: 'A cute baby seal on the beach',
});

console.log(result.data.generation_id);

// Poll for result (or use webhooks in production)
let generation = await client.getGeneration(result.data.generation_id);
while (['pending', 'processing'].includes(generation.data.generation_status)) {
  await new Promise(r => setTimeout(r, 2000));
  generation = await client.getGeneration(result.data.generation_id);
}

if (generation.data.generation_status === 'succeeded') {
  console.log('Output URLs:', generation.data.generation_output_file);
}
See Examples for batch generation, webhooks, error handling, and more patterns.

Configuration

TypeScript
const client = new BabySea({
  // Required - your API key (starts with bye_)
  apiKey: 'bye_...',

  // Optional - deployment region ('us' or 'eu'). Defaults to 'us'
  region: 'us',

  // Optional - request timeout in milliseconds (default: 30000)
  timeout: 30_000,

  // Optional - max automatic retries for retryable API errors (default: 2)
  maxRetries: 2,
});

// Or with a custom base URL (Enterprise plan - overrides region)
const dev = new BabySea({
  apiKey: 'bye_...',
  baseUrl: 'https://custom.babysea.ai',
});

Response envelope

All successful responses follow the same envelope:
JSON
{
  "status": "success",
  "request_id": "...",
  "message": "...",
  "timestamp": "...",
  "data": { ... }
}
Paginated responses include extra fields:
JSON
{
  "status": "success",
  "request_id": "...",
  "message": "...",
  "timestamp": "...",
  "data": { ... },
  "total": 1,
  "limit": 50,
  "offset": 0
}

Runtime compatibility

RuntimeSupportedNotes
Node.js 18+Uses native fetch and crypto.subtle
DenoWeb standard APIs
BunWeb standard APIs
Cloudflare WorkersEdge runtime compatible
Vercel Edge FunctionsEdge runtime compatible
Modern BrowsersESM bundle, crypto.subtle required
Node.js < 18No native fetch, use a polyfill or upgrade

Package exports

JSON
{
  "exports": {
    ".": {
      "import": {
        "types": "./dist/index.d.ts",
        "default": "./dist/index.js"
      },
      "require": {
        "types": "./dist/index.d.cts",
        "default": "./dist/index.cjs"
      }
    },
    "./webhooks": {
      "import": {
        "types": "./dist/webhooks.d.ts",
        "default": "./dist/webhooks.js"
      },
      "require": {
        "types": "./dist/webhooks.d.cts",
        "default": "./dist/webhooks.cjs"
      }
    }
  }
}
The webhook helper is a separate export for tree-shaking:
TypeScript
import { verifyWebhook } from 'babysea/webhooks';

TypeScript support

The SDK is written in TypeScript and ships .d.ts declarations. All response types are exported:
TypeScript
import type {
  // Client configuration
  BabySeaOptions,
  BabySeaRegion,

  // Response envelopes
  ApiResponse,
  PaginatedResponse,
  ApiErrorBody,
  RateLimitInfo,

  // /v1/user/account
  AccountData,

  // /v1/user/billing
  BillingData,

  // /v1/estimate/{model_identifier}
  EstimateData,

  // /v1/health/inference/*
  HealthCacheData,
  HealthModel,
  HealthModelProvider,
  HealthModelsData,
  HealthProvider,
  HealthProvidersData,
  HealthStorageData,

  // /v1/generate/image/{model_identifier}
  ImageGenerationParams,
  ImageGenerationData,

  // /v1/generate/video/{model_identifier}
  VideoGenerationParams,
  VideoGenerationData,

  Generation,
  GenerationDeleteData,
  GenerationCancelData,

  // /v1/library/models + /v1/library/providers
  Model,
  ModelSchema,
  LibraryModelsData,
  ProviderProfile,
  LibraryProvidersData,

  // /v1/content/list
  GenerationListData,

  // /v1/status
  StatusData,

  // /v1/usage
  UsageData,
  UsageEndpoint,
  UsageProvider,

  // API key scopes
  ApiKeyScope,
  ApiKeyScopePreset,

  // Webhooks
  WebhookEventType,
  WebhookPayload,
} from 'babysea';