npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

chatgpt-client-wrapper

v1.0.2

Published

A simple wrapper for OpenAI ChatGPT API with text and image generation capabilities

Downloads

30

Readme

ChatGPT API Wrapper

A simple and lightweight npm package for interacting with OpenAI's ChatGPT API, supporting both text completion and image generation.

Features

  • 🤖 Text Completion: Support for all ChatGPT models (GPT-3.5, GPT-4, etc.)
  • 🎨 Image Generation: DALL-E 2 and DALL-E 3 support
  • 🔧 TypeScript Support: Full type definitions included
  • Simple API: Easy-to-use methods for common tasks
  • 🛡️ Error Handling: Comprehensive error handling and validation
  • 🔄 Flexible Configuration: Customizable timeout, base URL, and model selection

Installation

npm install chatgpt-api-wrapper

Quick Start

const ChatGPT = require('chatgpt-api-wrapper');

const client = new ChatGPT({
  apiKey: 'your-openai-api-key'
});

// Simple text completion
const response = await client.complete('What is artificial intelligence?');
console.log(response);

// Generate an image
const image = await client.generateImage({
  prompt: 'A beautiful sunset over mountains',
  model: 'dall-e-3'
});
console.log(image.data[0].url);

API Reference

Constructor

const client = new ChatGPT({
  apiKey: 'your-api-key',        // Required
  baseURL: 'custom-base-url',    // Optional
  timeout: 30000                 // Optional (default: 30000ms)
});

Text Completion

Simple Completion

const response = await client.complete(prompt, model);

Advanced Chat

const response = await client.chat({
  model: ChatGPT.MODELS.GPT_4,
  messages: [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: 'Hello!' }
  ],
  maxTokens: 150,
  temperature: 0.7,
  topP: 1,
  frequencyPenalty: 0,
  presencePenalty: 0
});

Image Generation

const image = await client.generateImage({
  prompt: 'A cute robot',
  model: 'dall-e-3',          // 'dall-e-2' or 'dall-e-3'
  size: '1024x1024',          // Various sizes available
  quality: 'standard',        // 'standard' or 'hd' (DALL-E 3 only)
  style: 'vivid',             // 'vivid' or 'natural' (DALL-E 3 only)
  n: 1                        // Number of images
});

Available Models

console.log(ChatGPT.MODELS);
// Output:
// {
//   GPT_4: 'gpt-4',
//   GPT_4_TURBO: 'gpt-4-turbo',
//   GPT_4_TURBO_PREVIEW: 'gpt-4-turbo-preview',
//   GPT_3_5_TURBO: 'gpt-3.5-turbo',
//   GPT_3_5_TURBO_16K: 'gpt-3.5-turbo-16k'
// }

Utility Methods

// Test API connection
const isConnected = await client.testConnection();

// Get available models
const models = client.getAvailableModels();

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | apiKey | string | Required | Your OpenAI API key | | baseURL | string | https://api.openai.com/v1 | API base URL | | timeout | number | 30000 | Request timeout in milliseconds |

Image Generation Options

DALL-E 2

  • Sizes: 256x256, 512x512, 1024x1024
  • Up to 10 images per request

DALL-E 3

  • Sizes: 1024x1024, 1792x1024, 1024x1792
  • Quality: standard, hd
  • Style: vivid, natural
  • 1 image per request

Error Handling

The package provides detailed error messages for common issues:

try {
  const response = await client.complete('Hello');
} catch (error) {
  console.error('Error:', error.message);
  // Detailed error information from OpenAI API
}

Local Development & Testing

  1. Clone this repository
  2. Install dependencies: npm install
  3. Build the package: npm run build
  4. Set your API key: export OPENAI_API_KEY="your-key-here"
  5. Run tests: npm test

TypeScript Support

This package includes full TypeScript definitions:

import ChatGPT, { ChatMessage, ChatCompletionOptions } from 'chatgpt-api-wrapper';

const client = new ChatGPT({ apiKey: 'your-key' });

const messages: ChatMessage[] = [
  { role: 'user', content: 'Hello!' }
];

const options: ChatCompletionOptions = {
  model: ChatGPT.MODELS.GPT_4,
  messages,
  temperature: 0.7
};

Examples

Chatbot with Context

const conversation = [
  { role: 'system', content: 'You are a helpful coding assistant.' },
  { role: 'user', content: 'How do I create a REST API in Node.js?' }
];

const response = await client.chat({
  model: ChatGPT.MODELS.GPT_4,
  messages: conversation,
  maxTokens: 500
});

// Add assistant's response to conversation
conversation.push({
  role: 'assistant',
  content: response.choices[0].message.content
});

Batch Image Generation

const prompts = [
  'A cat wearing a space suit',
  'A robot playing piano',
  'A mountain landscape at dawn'
];

const images = await Promise.all(
  prompts.map(prompt => 
    client.generateImage({ prompt, model: 'dall-e-2' })
  )
);

images.forEach((img, i) => {
  console.log(`Image ${i + 1}: ${img.data[0].url}`);
});

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.