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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@varlabs/ai.openai

v0.1.7

Published

AI sdk for interfacing with AI models

Readme

@varlabs/ai.openai

A comprehensive, type-safe OpenAI provider for the @varlabs/ai SDK.

Features

  • Complete API Coverage - Support for all OpenAI API endpoints including:

    • Text generation (ChatGPT, GPT-4, etc.)
    • Image generation (DALL-E models)
    • Audio processing (speech synthesis and transcription)
    • Embeddings
    • Function calling
    • Structured output
  • Type Safety - Fully typed interfaces for all API endpoints and models with proper type inference.

  • Streaming Support - First-class support for streaming responses from OpenAI.

  • Custom Tools Integration - Easy integration with custom tools and function calling.

  • Advanced Features - Support for file search, web search, reasoning, and more.

Installation

npm install @varlabs/ai.openai

# or

yarn add @varlabs/ai.openai

# or

pnpm add @varlabs/ai.openai

Usage

Basic Usage

import { createAIClient } from '@varlabs/ai';
import openAiProvider from '@varlabs/ai.openai';

const client = createAIClient({
  providers: {
    openai: openAiProvider({
      config: {
        apiKey: 'your-api-key',
        baseUrl: 'https://api.openai.com/v1' // optional, defaults to this value
      }
    })
  }
});

// Text generation
const response = await client.openai.text.create_response({
  model: 'gpt-4o',
  input: 'Tell me a joke about programming.'
});

// Image generation
const image = await client.openai.images.create({
  model: 'dall-e-3',
  prompt: 'A robot writing code in a futuristic office'
});

// Audio transcription
const transcription = await client.openai.speech.transcribe_audio({
  model: 'whisper-1',
  file: audioFile //blob or file object
});

Streaming Responses

const stream = await client.openai.text.stream_response({
  model: 'gpt-4o',
  input: 'Write a short story about AI.',
});

// Handle the stream
for await (const chunk of stream) {
  // Process each chunk of the response
  console.log(chunk);
}

Using Custom Tools

import { customTool } from '@varlabs/ai.openai';

const response = await client.openai.text.create_response({
  model: 'gpt-4o',
  input: 'What\'s the weather in New York?',
  custom_tools: {
    get_weather: customTool({
      description: 'Get current weather for a location',
      parameters: {
        type: 'object',
        properties: {
          location: { type: 'string' }
        },
        required: ['location']
      },
      execute: async (params) => {
        // Implementation to fetch weather data
        return { temperature: 72, conditions: 'sunny' };
      }
    })
  }
});

Structured Output

const response = await client.openai.text.create_response({
  model: 'gpt-4o',
  input: 'Extract the name and age from: John Doe is 30 years old',
  structured_output: {
    name: 'PersonInfo',
    schema: {
      type: 'object',
      properties: {
        name: { type: 'string', description: 'Full name of the person' },
        age: { type: 'number', description: 'Age in years', required: false }
      },
    }
  }
});

API Reference

The provider implements all OpenAI API endpoints through the following structure:

  • text - Text generation and chat models

    • create_response - Generate text responses
    • get_response - Get a previously generated response
    • delete_response - Delete a response
    • list_input_item_list - List items for a response
  • images - Image generation models

    • create - Create images
    • edit - Edit existing images
    • generate_variations - Create variations of images
  • speech - Audio processing models

    • generate_audio - Generate speech from text
    • transcribe_audio - Transcribe audio to text
    • translate_audio - Translate audio to English text
  • embedding - Embedding models

    • embed - Create embeddings for text

License

MIT © Hamza Varvani