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

# TypeScript Library

> TypeScript client for NanoGPT API

# NanoGPT-client

[NanoGPT-client](https://github.com/aspic/nanogpt-client) is an unofficial TypeScript implementation of the NanoGPT API. This library aims to provide a type-safe client for both browser and Node.js environments.

## Overview

NanoGPT-client is built on the inferred OpenAPI spec, providing a strongly-typed interface to interact with the NanoGPT API. This makes it easier to integrate NanoGPT's capabilities into your TypeScript applications with full type checking and IntelliSense support.

## Installation

Install the package via npm:

```bash theme={null}
npm install nanogpt-client
```

Or using yarn:

```bash theme={null}
yarn add nanogpt-client
```

## Basic Usage

```typescript theme={null}
import { NanoGPTClient } from 'nanogpt-client';

// Initialize with your API key
const client = new NanoGPTClient({
  apiKey: 'your-api-key'
});

async function main() {
  try {
    const response = await client.chatCompletions.create({
      model: 'openai/gpt-5.2',
      messages: [
        { role: 'system', content: 'You are a helpful assistant.' },
        { role: 'user', content: 'Explain TypeScript interfaces.' }
      ]
    });
    
    console.log(response.choices[0].message.content);
  } catch (error) {
    console.error('Error:', error);
  }
}

main();
```

## Features

* **Type Safety**: Full TypeScript type definitions for all API endpoints and parameters
* **Cross-Platform**: Works in both browser and Node.js environments
* **Modern Architecture**: Built with modern TypeScript practices
* **Comprehensive Coverage**: Supports all NanoGPT API endpoints

## API Methods

### Chat Completions

```typescript theme={null}
const completion = await client.chatCompletions.create({
  model: 'openai/gpt-5.2',
  messages: [
    { role: 'user', content: 'Hello, world!' }
  ],
  temperature: 0.7,
  max_tokens: 150
});
```

### Text Completions

```typescript theme={null}
const completion = await client.completions.create({
  model: 'openai/gpt-5.2',
  prompt: 'Write a poem about TypeScript',
  max_tokens: 100
});
```

### Image Generation

```typescript theme={null}
const image = await client.images.generate({
  prompt: 'A cat programming in TypeScript',
  model: 'recraft-v3',
  n: 1,
  size: '1024x1024'
});
```

### Video Generation

```typescript theme={null}
const video = await client.videos.create({
  prompt: 'A short animation of code being written',
  framework: 'emotional_story',
  targetLengthInWords: 70
});
```

### Check Balance

```typescript theme={null}
const balance = await client.balance.check();
console.log('Current balance:', balance);
```

## Advanced Configuration

```typescript theme={null}
const client = new NanoGPTClient({
  apiKey: 'your-api-key',
  baseUrl: 'https://custom-domain.com/api', // Optional custom API URL
  timeout: 30000, // Request timeout in ms
  headers: {
    'Custom-Header': 'value'
  }
});
```

## Development

The library is open-source and welcomes contributions. To contribute:

1. Fork the [repository](https://github.com/aspic/nanogpt-client)
2. Clone your fork
3. Install dependencies (`npm install` or `yarn`)
4. Make your changes
5. Submit a pull request

## Resources

* [GitHub Repository](https://github.com/aspic/nanogpt-client)
* [NanoGPT API Documentation](https://docs.nano-gpt.com)
* [Get your API Key](https://nano-gpt.com/api)
