npm package: @rendrkit/sdk
Description: TypeScript SDK for RendrKit — generate designed images from text
Latest version: 0.2.2

# @rendrkit/sdk

TypeScript SDK for RendrKit -- generate designed images from text. A thin, zero-dependency client that wraps the RendrKit REST API with fully typed methods.

## Installation

```bash
npm install @rendrkit/sdk
```

## Quick Start

```typescript
import { RendrKit } from "@rendrkit/sdk";

const rk = new RendrKit({ apiKey: "rk_your_api_key" });

const image = await rk.generate({ prompt: "A modern SaaS hero banner" });
console.log(image.url);
```

## Configuration

```typescript
const rk = new RendrKit({
  apiKey: "rk_your_api_key",       // Required
  baseUrl: "https://api.rendrkit.dev",  // Optional, defaults to production
});
```

## Image Generation

### Generate an image

```typescript
const image = await rk.generate({
  prompt: "A dark-themed pricing page header",
  size: "1920x1080",
  style: "dark",
  brand: {
    colors: ["#1a1a2e", "#e94560"],
    font: "Inter",
    logoUrl: "https://example.com/logo.png",
  },
  brandKitId: "bk_abc123", // Or reference a saved brand kit
});

// image.id     - Unique image ID
// image.url    - CDN URL of the generated image
// image.width  - Image width in pixels
// image.height - Image height in pixels
```

### Get image details

```typescript
const image = await rk.getImage("img_abc123");
```

### Delete an image

```typescript
await rk.deleteImage("img_abc123");
```

## Brand Kits

Brand kits let you save and reuse brand settings across image generations.

### Create a brand kit

```typescript
const kit = await rk.brandKits.create({
  name: "Acme Corp",
  colors: ["#ff6b35", "#004e89"],
  font: "Poppins",
  logoUrl: "https://example.com/logo.png",
});
```

### List all brand kits

```typescript
const kits = await rk.brandKits.list();
```

### Get a brand kit

```typescript
const kit = await rk.brandKits.get("bk_abc123");
```

### Update a brand kit

```typescript
const updated = await rk.brandKits.update("bk_abc123", {
  name: "Acme Inc",
  colors: ["#ff6b35", "#004e89", "#ffffff"],
});
```

### Delete a brand kit

```typescript
await rk.brandKits.delete("bk_abc123");
```

## Usage Stats

```typescript
const usage = await rk.usage();

// usage.plan         - Current plan name
// usage.imagesUsed   - Images generated this period
// usage.imagesLimit  - Maximum images for the plan
// usage.periodStart  - Billing period start (ISO 8601)
// usage.periodEnd    - Billing period end (ISO 8601)
```

## Error Handling

The SDK throws typed errors for different failure modes:

```typescript
import {
  RendrKitError,
  AuthenticationError,
  ValidationError,
  NotFoundError,
  RateLimitError,
  QuotaExceededError,
} from "@rendrkit/sdk";

try {
  await rk.generate({ prompt: "A banner" });
} catch (error) {
  if (error instanceof AuthenticationError) {
    // 401 - Invalid or missing API key
  } else if (error instanceof ValidationError) {
    // 400 - Invalid request parameters
  } else if (error instanceof NotFoundError) {
    // 404 - Resource not found
  } else if (error instanceof QuotaExceededError) {
    // 429 - Monthly quota exceeded
  } else if (error instanceof RateLimitError) {
    // 429 - Too many requests
  } else if (error instanceof RendrKitError) {
    // Other API errors
    console.error(error.code, error.message, error.status);
  }
}
```

## TypeScript Types

All types are exported for use in your application:

```typescript
import type {
  RendrKitOptions,
  GenerateOptions,
  Image,
  BrandKit,
  CreateBrandKitOptions,
  UpdateBrandKitOptions,
  UsageStats,
} from "@rendrkit/sdk";
```

### Style options

```typescript
type Style = "modern" | "playful" | "corporate" | "dark" | "minimal" | "bold";
```

### Size options

Common sizes: `1080x1080`, `1200x628`, `1920x1080`, `1080x1920`, `1280x720`

## OpenAI Function Calling

The SDK exports an OpenAI-compatible function schema for use with function calling:

```typescript
import { openAIFunctionSchema, RendrKit } from "@rendrkit/sdk";

// Use with OpenAI chat completions
const response = await openai.chat.completions.create({
  model: "gpt-4",
  messages: [{ role: "user", content: "Create a banner for my SaaS" }],
  functions: [openAIFunctionSchema],
});

// Or access via static method
const schema = RendrKit.toOpenAIFunction();
```

## License

MIT