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

@sha3/openai

v2.0.0

Published

Openai library wrapper

Readme

OpenAI TypeScript Client

TypeScript License: MIT npm version

A modern, type-safe TypeScript client for interacting with the OpenAI API. This library provides a clean, intuitive interface for working with OpenAI's powerful language models, including GPT-4 and others.

✨ Features

  • Type-Safe - Built with TypeScript for enhanced developer experience
  • Simple API - Clean, intuitive methods for common operations
  • Flexible Configuration - Customize model parameters and token limits
  • Promise-based - Async/await support for all operations
  • Comprehensive Error Handling - Clear error messages and status codes

🚀 Quick Start

Installation

npm install @your-org/openai
# or
yarn add @your-org/openai

Basic Usage

import { OpenAI } from '@your-org/openai';

// Initialize the client
const openai = new OpenAI({
  apikey: 'your-api-key',
  model: 'gpt-4',
  systemPrompt: 'You are a helpful assistant.',
  maxNumberOfInputTokens: 4096,
  maxNumberOfOutputTokens: 1024
});

// Process a prompt
async function getResponse() {
  try {
    const response = await openai.processPrompt("Tell me about TypeScript", {
      temperature: 0.7,
      user: 'user-123'
    });
    
    console.log(response);
  } catch (error) {
    console.error('Error processing prompt:', error);
  }
}

getResponse();

📖 Documentation

Initialization

const openai = new OpenAI({
  apikey: string;                 // Required: Your OpenAI API key
  systemPrompt?: string;          // Optional: Initial system prompt
  model: string;                  // Required: Model to use (e.g., 'gpt-4')
  maxNumberOfInputTokens?: number; // Optional: Max input tokens (default: 4096)
  maxNumberOfOutputTokens?: number; // Optional: Max output tokens (default: 1024)
});

Methods

loadSystemPrompt(prompt: string): void

Loads a system prompt and encodes it into tokens.

processPrompt(prompt: string, options: ProcessPromptOptions): Promise<ProcessPromptResponse>

Processes a user prompt and returns the model's response.

Types

ProcessPromptOptions

{
  temperature?: number;           // Controls randomness (0.0 to 1.0)
  user?: string;                  // Unique user identifier
  // Additional options...
}

ProcessPromptResponse

{
  id: string;                    // Completion ID
  created: number;                // Creation timestamp
  model: string;                 // Model used
  choices: Array<{
    message: CompletionMessage;
    finish_reason: string;
    index: number;
  }>;
  usage: {
    prompt_tokens: number;
    completion_tokens: number;
    total_tokens: number;
  };
}

🔧 Configuration

Environment Variables

OPENAI_API_KEY=your_api_key_here
OPENAI_DEFAULT_MODEL=gpt-4

Runtime Configuration

All configuration options can be passed to the constructor or set via environment variables.

💡 Examples

Chat Completion

const response = await openai.processPrompt("What's the weather like?", {
  temperature: 0.8,
  max_tokens: 150
});

Streaming Responses

// Example of streaming implementation would go here
// This depends on your specific streaming requirements

📊 Pricing

Pricing is based on the official OpenAI pricing model. For the most up-to-date information, refer to:

🤝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • OpenAI for their amazing API
  • The TypeScript community for their support
  • All contributors who help improve this project