open-index/open-npm huggingface dataset:
npm package: @regia-ai/js-sdk
Description: JavaScript/TypeScript SDK to interact with the Regia AI services and APIs.
Author: Regia
Latest version: 1.2.0


# @regia-ai/sdk

JavaScript/TypeScript SDK to interact with the Regia AI services and APIs.

## 🚀 Installation

```bash
npm install @regia-ai/js-sdk
```

---

## 📦 Basic Usage

### TypeScript Example

```ts
import { Vision } from '@regia-ai/js-sdk';
import { z } from 'zod';

// Initialize the Vision client with your token
const vision = new Vision("your_token_here");


// Define your schema using Zod
const schema = z.object({
  usageKwh: z.number().describe("The total usage in kWh"),
  dueDate: z.string().describe("The due date of the invoice in the format YYYY-MM-DD"),
  totalAmount: z.number().describe("The total amount of the invoice"),
})

// Extract data from the PDF file
const { usageKwh, dueDate, totalAmount } = await vision.extract('./sample.pdf', { schema });

// Log the extracted data
console.log("Usage kWh: ", usageKwh);
console.log(`Due date: ${dueDate}`);
console.log(`Total amount: ${totalAmount}`);
```

---

## 🧠 Schema Definition

You define the structure of the extracted data using [Zod](https://zod.dev/), a TypeScript-first schema declaration and validation library.

This allows the server to understand what fields to extract using generative AI.

You can also pass a JSON Schema string to the `schema` parameter.

---

## 🔐 Authentication

All requests require a bearer token passed during client initialization:

```ts
const client = new Vision('your-api-token')
```

---

## 📘 API Reference

For more information checkout the [Developer Documentation](https://docs.regia.ai).

### `Vision(token, options)`
| Option           | Type   | Required | Description                          |
|------------------|--------|----------|--------------------------------------|
| `token`          | string | ✅       | Your API token                       |

---

### `client.extract(file, { schema })`

Extracts structured data from a media file.

| Parameter | Type        | Required | Description                                                  |
|-----------|-------------|----------|--------------------------------------------------------------|
| `file`    | `string`    | ✅       | Path to the local file or a base64-encoded string.       |
| `schema`  | `ZodSchema` | ✅       | The schema defining the desired fields to extract.           |

---

## ✅ Requirements

- Node.js >= 18
- Zod for schema definition
- Access to Regia's PDF Extractor API

---