> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rimp.io/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript SDK

> Official TypeScript / JavaScript client for the Rimp API.

The TypeScript SDK wraps every endpoint with full types, smart defaults, and a `waitFor` helper that polls async jobs to completion.

## Install

<CodeGroup>
  ```bash pnpm theme={null}
  pnpm add @rimp/sdk
  ```

  ```bash npm theme={null}
  npm install @rimp/sdk
  ```

  ```bash bun theme={null}
  bun add @rimp/sdk
  ```
</CodeGroup>

## Initialize

```ts theme={null}
import { RimpClient } from '@rimp/sdk';

const client = new RimpClient({
  apiKey: process.env.RIMP_API_KEY!,
  // baseUrl defaults to https://api.rimp.example
});
```

## Generations

### Image (synchronous)

```ts theme={null}
const gen = await client.generations.createImage({
  model: 'flux-pro',
  prompt: 'a red rimp on chrome',
  aspect_ratio: '1:1',
  num_outputs: 1,
});

// gen.outputs[0].url has the signed R2 URL (TTL 1h by default)
```

### Video (asynchronous + waitFor)

```ts theme={null}
const job = await client.generations.createVideo({
  model: 'veo-3-1-fast',
  prompt: 'waves at golden hour',
  duration_s: 4,
});

const final = await client.generations.waitFor(job.id, {
  pollIntervalMs: 2_000,
  timeoutMs: 30 * 60_000,
});
```

### Cancel

```ts theme={null}
await client.generations.cancel(jobId);
```

## Comparisons

```ts theme={null}
const cmp = await client.comparisons.create({
  prompt: 'cinematic portrait at golden hour',
  models: ['flux-pro', 'imagen-4'],
});

const result = await client.comparisons.waitFor(cmp.id);
```

## Models

```ts theme={null}
const { data: models } = await client.models.list();
// → [{ slug: 'flux-pro', modality: 'image', pricing: { ... }, ... }, ...]
```

## Uploads (for image-to-image / image-to-video)

```ts theme={null}
const upload = await client.uploads.createPresigned('image/png');
await fetch(upload.url, {
  method: 'PUT',
  body: fileBlob,
  headers: { 'Content-Type': 'image/png' },
});

// Then reference upload.id when creating a generation:
await client.generations.createVideo({
  model: 'runway-gen4-turbo',
  prompt: '...',
  image_url: upload.public_url,
});
```

## Webhooks

```ts theme={null}
const { secret } = await client.webhooks.create({
  url: 'https://app.example/webhooks/rimp',
  events: ['generation.completed'],
});
// Save `secret` — used to verify incoming events.
```

See [Webhooks](/concepts/webhooks) for signature verification snippets.

## Error handling

```ts theme={null}
import { RimpApiError } from '@rimp/sdk';

try {
  await client.generations.createImage({ model: 'flux-pro', prompt: '...' });
} catch (err) {
  if (err instanceof RimpApiError) {
    console.error(err.status, err.code, err.message, err.requestId);
  } else {
    throw err;
  }
}
```

## Edge runtime

The SDK uses `fetch` natively and works on Vercel Edge, Cloudflare Workers, Deno, Bun.

```ts theme={null}
// app/api/route.ts (Next.js edge)
export const runtime = 'edge';

export async function POST(req: Request) {
  const client = new RimpClient({ apiKey: process.env.RIMP_API_KEY });
  const gen = await client.generations.createImage({ ... });
  return Response.json(gen);
}
```
