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

# Getting Started

> Learn how to install and use the VLM Run Node.js SDK

## Installation

You can install the VLM Run Node.js SDK using npm, yarn, or pnpm:

```bash theme={"theme":{"light":"github-light","dark":"dark-plus"}}
# Using npm
npm install vlmrun

# Using yarn
yarn add vlmrun

# Using pnpm
pnpm add vlmrun
```

## Authentication

To use the VLM Run API, you'll need an API key. You can obtain one by:

1. Create an account at [VLM Run](https://app.vlm.run)
2. Navigate to dashboard Settings -> API Keys

Then use it to initialize the client:

```typescript theme={"theme":{"light":"github-light","dark":"dark-plus"}}
import { VlmRun } from "vlmrun";

const client = new VlmRun({
  apiKey: "your-api-key",
});
```

## Basic Usage

### Image Predictions

Here's a simple example of using the SDK to process an image:

```typescript theme={"theme":{"light":"github-light","dark":"dark-plus"}}
import { VlmRun } from "vlmrun";

// Initialize the client
const client = new VlmRun({
  apiKey: "your-api-key",
});

// Process an image using URL
const imageUrl =
  "https://storage.googleapis.com/vlm-data-public-prod/hub/examples/document.invoice/invoice_1.jpg";
const response = await client.image.generate({
  images: [imageUrl],
  domain: "document.invoice",
  config: {
    jsonSchema: {
      type: "object",
      properties: {
        invoice_number: { type: "string" },
        total_amount: { type: "number" },
      },
    },
  },
});
```

#### Process an image passing [zod](https://zod.dev/) schema

```typescript theme={"theme":{"light":"github-light","dark":"dark-plus"}}
import { z } from "zod";

const imageUrl =
  "https://storage.googleapis.com/vlm-data-public-prod/hub/examples/document.invoice/invoice_1.jpg";

const schema = z.object({
  invoice_number: z.string(),
  total_amount: z.number(),
});

const apiResponse = await client.image.generate({
  images: [imageUrl],
  domain: "document.invoice",
  config: {
    responseModel: schema,
  },
});
const response = apiResponse.response as z.infer<typeof schema>;
console.log(response);
```

#### Process an image using local file

```typescript theme={"theme":{"light":"github-light","dark":"dark-plus"}}
// Process an image using local file
const localResponse = await client.image.generate({
  images: ["path/to/local/image.jpg"],
  model: "vlm-1",
  domain: "document.invoice",
});
```

### Document Predictions

Here's how to process documents:

```typescript theme={"theme":{"light":"github-light","dark":"dark-plus"}}
// Upload a document
const file = await client.files.upload({
  filePath: "path/to/invoice.pdf",
});

// Process a document using file ID
const response = await client.document.generate({
  fileId: file.id,
  model: "vlm-1",
  domain: "document.invoice",
});
console.log(response);

// Process a document using URL
const documentUrl =
  "https://storage.googleapis.com/vlm-data-public-prod/hub/examples/document.invoice/google_invoice.pdf";
const urlResponse = await client.document.generate({
  url: documentUrl,
  model: "vlm-1",
  domain: "document.invoice",
});
console.log(urlResponse);
```

#### Process a document passing [zod](https://zod.dev/) schema

```typescript theme={"theme":{"light":"github-light","dark":"dark-plus"}}
import { z } from "zod";

const schema = z.object({
  invoice_id: z.string(),
  total: z.number(),
  sub_total: z.number(),
  tax: z.number(),
  items: z.array(
    z.object({
      name: z.string(),
      quantity: z.number(),
      price: z.number(),
      total: z.number(),
    })
  ),
});

const apiResponse = await client.document.generate({
  url: documentUrl,
  domain: "document.invoice",
  config: { responseModel: schema },
});

const response = apiResponse.response as z.infer<typeof schema>;
console.log(response);
```

## TypeScript Support

The VLM Run Node.js SDK is written in TypeScript and provides full type definitions out of the box. When using TypeScript, you'll get:

* Full IntelliSense support
* Type checking for all API calls
* Type definitions for request and response objects
* Autocomplete for configuration options

To get the best development experience, make sure your `tsconfig.json` includes:

```json theme={"theme":{"light":"github-light","dark":"dark-plus"}}
{
  "compilerOptions": {
    "esModuleInterop": true,
    "strict": true
  }
}
```
