# SDKs

The JavaScript and Python helpers for eWest jobs and webhooks: what they cover (not published yet).

> Not published yet. The eWest SDKs are finished and tested but are not on npm or PyPI, and this page is an outline of what they will contain. Until then use the REST API with any HTTP client; every call below has a plain HTTP equivalent in these docs.

There are two small helper libraries, one for JavaScript (Node 18 or newer, no dependencies, TypeScript types included) and one for Python (3.9 or newer, standard library only). They cover the **async jobs** (video, music, sound and 3D) and **webhook verification**. For chat, embeddings and images, use the OpenAI or Anthropic client libraries pointed at `https://api.ewest.ai/v1`: see [Developer tools](https://ewest.ai/docs/guides).

## The client

|  | JavaScript | Python |
| --- | --- | --- |
| Create | `new Ewest(options)` | `Ewest(api_key=None, ...)` |
| API key | `apiKey, default process.env.EWEST_KEY` | `api_key, default the EWEST_KEY variable` |
| Base URL | `baseUrl, default https://api.ewest.ai` | `base_url, default https://api.ewest.ai` |
| Retries | `maxRetries (default 2)` | `max_retries (default 2)` |
| Timeout | `timeout` | `timeout (60 s per socket operation)` |

A `429` is retried with backoff, honouring `Retry-After`. `5xx` answers and network errors are retried only for reads, because a failed `POST` may already have started a paid job. A `402` is never retried.

## Starting and following jobs

| Task | JavaScript | Python | REST |
| --- | --- | --- | --- |
| Start a video | `videos.generate(params)` | `videos.generate(model, prompt, ...)` | `POST /v1/videos/generations` |
| Start music or sound | `audio.generate(params)` | `audio.generate(model, prompt, ...)` | `POST /v1/audio/generations` |
| Start a 3D model | `threeD.generate(params)` | `three_d.generate(model, ...)` | `POST /v1/3d/generations` |
| Start and wait | `generateAndWait(params, options)` | `generate_and_wait(model, prompt, ...)` | `start, then poll` |
| Read a job | `jobs.get(job)` | `jobs.get(job)` | `GET /v1/jobs/{id}` |
| List jobs | `jobs.list({ limit })` | `jobs.list(limit)` | `GET /v1/jobs` |
| Wait for the end | `jobs.wait(job, options)` | `jobs.wait(job, ...)` | `poll` |
| Live progress | `jobs.stream(job)` | `jobs.stream(job)` | `GET /v1/jobs/{id}/events` |

A job is a plain object with `id`, `status`, `progress`, `eta_seconds`, `input`, `output`, `error` and `usage`, as described in [Jobs and webhooks](https://ewest.ai/docs/jobs#lifecycle). `wait` throws `JobFailedError` when the job ends `failed` and `JobTimeoutError` when your own timeout passes first; `stream` reconnects by itself if the connection drops.

## Verifying webhooks

|  | JavaScript | Python |
| --- | --- | --- |
| Verify a delivery | `verifyWebhook(payload, headers, secret, options)` | `verify_webhook(payload, headers, secret, ...)` |
| Import from | `@ewest/sdk/webhooks` | `ewest` |
| Result | `the finished job, parsed` | `the finished job, parsed` |
| On a bad signature | `throws WebhookVerificationError` | `raises WebhookVerificationError` |

Pass the **raw** request body, not parsed JSON. The default clock tolerance is 5 minutes. The secret comes from `GET /v1/webhooks/secret`; see [Webhooks](https://ewest.ai/docs/webhooks) for the rules the helpers apply.

## Errors

| Status | Error class |
| --- | --- |
| 400 | `BadRequestError` |
| 401 | `AuthError` |
| 402 | `InsufficientBudgetError` |
| 403 | `PermissionDeniedError` |
| 404 | `NotFoundError` |
| 429 | `RateLimitError (has retryAfter / retry_after)` |
| 5xx | `ServerError` |
| no answer | `APIConnectionError` |

HTTP errors carry `status`, `type`, `code`, `param` and the `x-request-id` of the call: quote it when you ask for help. They all extend `EwestError`; see [Errors](https://ewest.ai/docs/errors) for the codes.

## Not in the SDKs yet

- Cancelling a job (`POST /v1/jobs/{id}/cancel`) and the `Idempotency-Key` header: call the REST API for these ([Jobs and webhooks](https://ewest.ai/docs/jobs)).
- Webhook secret and delivery-log calls (`/v1/webhooks/secret`, `/v1/jobs/{id}/webhooks`).
- Chat, images and embeddings: use the OpenAI or Anthropic libraries.

## OpenAPI

For other languages, generate a client from the [OpenAPI 3.1 spec](https://ewest.ai/openapi.json): it describes every endpoint, field and error.

Source: https://ewest.ai/docs/sdks
