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.
NanoGPT-client
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:
npm install nanogpt-client
Or using yarn:
Basic Usage
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
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
const completion = await client.completions.create({
model: 'openai/gpt-5.2',
prompt: 'Write a poem about TypeScript',
max_tokens: 100
});
Image Generation
const image = await client.images.generate({
prompt: 'A cat programming in TypeScript',
model: 'recraft-v3',
n: 1,
size: '1024x1024'
});
Video Generation
const video = await client.videos.create({
prompt: 'A short animation of code being written',
framework: 'emotional_story',
targetLengthInWords: 70
});
Check Balance
const balance = await client.balance.check();
console.log('Current balance:', balance);
Advanced Configuration
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:
- Fork the repository
- Clone your fork
- Install dependencies (
npm install or yarn)
- Make your changes
- Submit a pull request
Resources