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

# Overview

> Introduction to the Verlon AI SDK for TypeScript/JavaScript

The Verlon SDK provides a unified interface for AI capabilities across multiple providers. Use one SDK to access chat, image generation, embeddings, text-to-speech, video generation, and OCR.

## Installation

<CodeGroup>
  ```bash npm theme={null}
  npm install @verlon-ai/sdk
  ```

  ```bash pnpm theme={null}
  pnpm add @verlon-ai/sdk
  ```

  ```bash yarn theme={null}
  yarn add @verlon-ai/sdk
  ```
</CodeGroup>

## Quick Start

```typescript theme={null}
import { Verlon } from '@verlon-ai/sdk';

const verlon = new Verlon({
  apiKey: process.env.VERLON_API_KEY
});

const response = await verlon.chat({
  gateId: 'your-gate-id',
  data: {
    messages: [
      { role: 'user', content: 'Hello!' }
    ]
  }
});

console.log(response.content);
```

## Configuration

### Initialize the Client

```typescript theme={null}
import { Verlon } from '@verlon-ai/sdk';

const verlon = new Verlon({
  apiKey: 'your-api-key',        // Required
  baseUrl: 'https://custom.api'  // Optional, defaults to https://api.verlon.ai
});
```

<Warning>
  Never commit API keys to version control. Use environment variables.
</Warning>

### Get Your API Key

1. Sign up at [verlon.ai/signup](https://verlon.ai/signup)
2. Get your API key from the [Dashboard](https://verlon.ai/dashboard)
3. Store it in an environment variable

```bash .env theme={null}
VERLON_API_KEY=your-api-key-here
```

## Available Methods

The SDK provides methods for different AI capabilities:

<CardGroup cols={2}>
  <Card title="Chat" icon="comments" href="/sdk-reference/chat">
    Text generation with streaming, vision, and function calling
  </Card>

  <Card title="Images" icon="image" href="/sdk-reference/images">
    Generate images from text prompts
  </Card>

  <Card title="Video" icon="video" href="/sdk-reference/video">
    Create videos from text descriptions
  </Card>

  <Card title="Embeddings" icon="vector-square" href="/sdk-reference/embeddings">
    Generate vector embeddings for text
  </Card>

  <Card title="Audio" icon="microphone" href="/sdk-reference/audio">
    Convert text to speech
  </Card>

  <Card title="OCR" icon="file-lines" href="/sdk-reference/ocr">
    Extract text from images
  </Card>
</CardGroup>

## Response Structure

All SDK methods return a `VerlonResponse` object:

```typescript theme={null}
interface VerlonResponse {
  // Common fields
  id: string;              // Request ID
  model: string;           // Model used
  cost: number;            // Request cost in USD
  latency: number;         // Response time in ms

  // Method-specific fields
  content?: string;        // Chat response text
  data?: any[];            // Image/video/embedding data
  url?: string;            // Audio file URL
  text?: string;           // OCR extracted text

  // Usage statistics
  usage?: {
    promptTokens: number;
    completionTokens: number;
    totalTokens: number;
  };
}
```

## Error Handling

Wrap SDK calls in try-catch blocks:

```typescript theme={null}
try {
  const response = await verlon.chat({
    gateId: 'your-gate-id',
    data: {
      messages: [{ role: 'user', content: 'Hello!' }]
    }
  });

  console.log(response.content);
} catch (error) {
  console.error('Error:', error.message);
}
```

### Common Error Messages

| Error                  | Cause                        |
| ---------------------- | ---------------------------- |
| `Invalid token`        | Check your API key           |
| `Gate not found`       | Verify gate ID is correct    |
| `Rate limit exceeded`  | Too many requests, slow down |
| `Insufficient credits` | Add credits to your account  |

## TypeScript Support

The SDK is fully typed:

```typescript theme={null}
import { Verlon, ChatRequest, VerlonResponse } from '@verlon-ai/sdk';

const verlon = new Verlon({
  apiKey: process.env.VERLON_API_KEY!
});

// TypeScript knows the structure
const response: VerlonResponse = await verlon.chat({
  gateId: 'your-gate-id',
  data: {
    messages: [
      { role: 'user', content: 'Hello!' }
    ]
  }
});

// Autocomplete and type safety
console.log(response.content);  // TypeScript knows this exists
console.log(response.cost);     // TypeScript knows this is a number
```

## Environment Variables

Best practice for managing credentials:

```typescript theme={null}
// Good ✅
const verlon = new Verlon({
  apiKey: process.env.VERLON_API_KEY
});

// Bad ❌
const verlon = new Verlon({
  apiKey: 'sk-vrln-hardcoded_key'  // Never do this!
});
```

## Next Steps

Explore specific capabilities:

<CardGroup cols={3}>
  <Card title="Chat" href="/sdk-reference/chat" />

  <Card title="Images" href="/sdk-reference/images" />

  <Card title="Video" href="/sdk-reference/video" />

  <Card title="Embeddings" href="/sdk-reference/embeddings" />

  <Card title="Audio" href="/sdk-reference/audio" />

  <Card title="OCR" href="/sdk-reference/ocr" />
</CardGroup>

Or learn about core concepts:

<CardGroup cols={2}>
  <Card title="Gates & Routing" icon="route" href="/concepts/gates-and-routing">
    How Verlon routes requests to models
  </Card>

  <Card title="Creating Gates" icon="door-open" href="/dashboard/creating-gates">
    Configure gates in the dashboard
  </Card>
</CardGroup>
