npm package: @renderfast/client
Description: TypeScript SDK for RenderFast API
Author: RenderFast
Latest version: 0.0.2

# @renderfast/client

Official TypeScript SDK for the RenderFast API - generate dynamic OG images programmatically.

## Installation

```bash
npm install @renderfast/client
# or
pnpm add @renderfast/client
# or
yarn add @renderfast/client
```

## Quick Start

```typescript
import { createClient, getApiTemplates, postApiGenerate } from '@renderfast/client';

// Create a client instance
const client = createClient({
  baseUrl: 'https://renderfa.st',
  headers: {
    Authorization: 'Bearer YOUR_API_KEY'
  }
});

// List your templates
const { data: templates } = await getApiTemplates({ client });
console.log(templates);

// Generate an image from a template
const { data: image, error } = await postApiGenerate({
  client,
  body: {
    templateId: 'your-template-id',
    layers: {
      title: { text: 'Hello World' },
      subtitle: { text: 'Generated with RenderFast' }
    }
  }
});

if (error) {
  console.error('Generation failed:', error);
} else {
  // image is a PNG buffer
  console.log('Image generated successfully');
}
```

## API Reference

### Templates

```typescript
// List all templates
const { data } = await getApiTemplates({ client });

// Get a single template
const { data } = await getApiTemplatesById({ client, path: { id: 'template-id' } });

// Create a template
const { data } = await postApiTemplates({
  client,
  body: {
    name: 'My Template',
    jsonData: { /* template JSON */ }
  }
});

// Update a template
const { data } = await putApiTemplatesById({
  client,
  path: { id: 'template-id' },
  body: { name: 'Updated Name' }
});

// Delete a template
await deleteApiTemplatesById({ client, path: { id: 'template-id' } });

// Clone a template
const { data } = await postApiTemplatesByIdClone({
  client,
  path: { id: 'template-id' }
});
```

### Image Generation

```typescript
// Generate image (authenticated)
const { data } = await postApiGenerate({
  client,
  body: {
    templateId: 'template-id',
    layers: {
      title: { text: 'Dynamic Title' },
      image: { image_url: 'https://example.com/photo.jpg' }
    },
    scale: 1 // optional: 0.5 for half size, 2 for double
  }
});

// Public render endpoint (for OG images)
const { data } = await getApiRender({
  client,
  query: {
    template: 'template-id',
    title: 'Page Title',
    scale: 1
  }
});
```

### Uploads

```typescript
// List uploads
const { data } = await getApiUploads({ client });

// Upload a file
const { data } = await postApiUploads({
  client,
  body: {
    name: 'my-image.png',
    base64: 'data:image/png;base64,...',
    category: 'image'
  }
});

// Get upload URL
const { data } = await getApiUploadsByIdUrl({ client, path: { id: 'upload-id' } });

// Delete upload
await deleteApiUploadsById({ client, path: { id: 'upload-id' } });
```

### Starter Templates

```typescript
// List public starter templates
const { data } = await getApiTemplatesStarter({ client });

// Get starter template categories
const { data } = await getApiTemplatesStarterCategories({ client });
```

## Features

- Fully typed TypeScript client
- Auto-generated from OpenAPI spec
- Fetch-based HTTP client (works everywhere)
- Works in Node.js, Bun, Deno, and browsers
- Tree-shakeable exports

## Error Handling

All functions return `{ data, error }` objects:

```typescript
const { data, error } = await getApiTemplates({ client });

if (error) {
  // error is typed based on possible error responses
  console.error('Request failed:', error);
  return;
}

// data is typed based on success response
console.log('Templates:', data);
```

## TypeScript Support

All types are exported for use in your application:

```typescript
import type {
  PostApiTemplatesData,
  PostApiGenerateData,
  GetApiTemplatesResponses
} from '@renderfast/client';
```

## Documentation

For complete API reference, visit: https://renderfa.st/docs

## License

MIT