Skip to main content
The babysea package calls the /v1 API with typed responses, request timeouts, retry handling, and webhook signature verification.

npm

Install the official TypeScript SDK.

GitHub

View the package source and examples.

Install

Create a client

TypeScript

Generate an image

TypeScript
client.generate() chooses the route from the request body:
  • no generation_duration: POST /v1/generate/image/{model_identifier}
  • generation_duration present: POST /v1/generate/video/{model_identifier}

Generate a video

TypeScript

Idempotent retries

Pass an Idempotency-Key to safely retry a generation request without creating duplicate work or duplicate charges. The SDK forwards it as the Idempotency-Key request header.
TypeScript
Persist the key alongside the action that triggers the request, and reuse the same key for every retry of that action. See idempotency for the replay window and full contract.

Poll a generation

TypeScript
Use webhooks for production paths that should not poll.

Generate and wait

client.generateAndWait() creates a generation and polls until it reaches a terminal status. It returns the generation when generation_status is succeeded and throws BabySeaGenerationFailedError when the generation fails or is canceled. Use it for scripts and demos. For production throughput, prefer client.generate() with webhooks.
TypeScript
client.waitForGeneration() accepts the same timeout, interval, and signal options when you already have a generation_id.

Client methods

Estimate cost

TypeScript
For resolution-priced or audio-priced models, pass resolution and audio when relevant.

Errors and retries

TypeScript
The SDK retries structured API errors with retryable: true, up to maxRetries. It also retries transient network failures for idempotent methods. For POST generation requests, network retries require an Idempotency-Key.

Verify webhooks

TypeScript
verifyWebhook() checks the t=<unix_timestamp>,v1=<hmac> signature, validates the timestamp tolerance, and returns the parsed payload.

Runtime support

The SDK uses web-standard fetch and crypto.subtle APIs.