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

@dysporium-sdk/openai

v1.1.0

Published

OpenAI provider for Dysporium SDK

Readme

@dysporium-sdk/openai

OpenAI provider for Dysporium SDK - integrate OpenAI models with a simple, type-safe API.

Installation

npm install @dysporium-sdk/openai
# or
pnpm add @dysporium-sdk/openai

Note: This package includes all exports from @dysporium-sdk/core, so you only need to install this single package.

Quick Start

import { createOpenAI, generateText, streamText } from '@dysporium-sdk/openai';

const openai = createOpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

// Generate text
const result = await generateText({
  model: openai('gpt-4'),
  messages: [{ role: 'user', content: 'Hello!' }],
});

console.log(result.text);

Features

  • Full OpenAI API support (GPT-4, GPT-4o, GPT-3.5-turbo, etc.)
  • Streaming responses
  • Tool/function calling
  • JSON mode and structured outputs
  • Embeddings (text-embedding-3-small, text-embedding-3-large, etc.)
  • Automatic retries with exponential backoff
  • Full TypeScript support

Usage

Text Generation

import { createOpenAI, generateText } from '@dysporium-sdk/openai';

const openai = createOpenAI({ apiKey: 'your-api-key' });

const result = await generateText({
  model: openai('gpt-4o'),
  messages: [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: 'What is the capital of France?' },
  ],
  maxTokens: 100,
  temperature: 0.7,
});

console.log(result.text);
console.log(result.usage); // { promptTokens, completionTokens, totalTokens }

Streaming

import { createOpenAI, streamText } from '@dysporium-sdk/openai';

const openai = createOpenAI({ apiKey: 'your-api-key' });

const stream = await streamText({
  model: openai('gpt-4o'),
  messages: [{ role: 'user', content: 'Write a poem about coding' }],
});

for await (const chunk of stream) {
  process.stdout.write(chunk.text);
}

Tool Calling

import { createOpenAI, generateText } from '@dysporium-sdk/openai';

const openai = createOpenAI({ apiKey: 'your-api-key' });

const result = await generateText({
  model: openai('gpt-4o'),
  messages: [{ role: 'user', content: 'What is the weather in Paris?' }],
  tools: [
    {
      name: 'get_weather',
      description: 'Get current weather for a location',
      parameters: {
        type: 'object',
        properties: {
          location: { type: 'string', description: 'City name' },
        },
        required: ['location'],
      },
    },
  ],
});

if (result.toolCalls) {
  console.log(result.toolCalls);
}

Embeddings

import { createOpenAIEmbedding, embed, embedMany, cosineSimilarity } from '@dysporium-sdk/openai';

const embeddingModel = createOpenAIEmbedding({ apiKey: 'your-api-key' });

// Single embedding
const result = await embed({
  model: embeddingModel('text-embedding-3-small'),
  value: 'Hello world',
});

// Multiple embeddings
const results = await embedMany({
  model: embeddingModel('text-embedding-3-small'),
  values: ['Hello', 'World', 'Foo', 'Bar'],
});

// Compare embeddings
const similarity = cosineSimilarity(results.embeddings[0], results.embeddings[1]);

Supported Models

Language Models

  • gpt-5.1 - Latest model (November 2025)
  • gpt-5 - Advanced reasoning & multimodal (August 2025)
  • gpt-5-mini - Efficient GPT-5 variant
  • gpt-4.1 - Enhanced GPT-4 (April 2025)
  • gpt-4.1-mini - Fast and efficient
  • gpt-4.1-nano - Smallest and fastest
  • gpt-4o - Multimodal model
  • gpt-4o-mini - Fast and affordable

Codex Models (Code-optimized)

  • gpt-5.1-codex-max - Complex, long-horizon coding tasks
  • gpt-5.1-codex-mini - Efficient coding assistance

Embedding Models

  • text-embedding-3-small - Efficient embeddings
  • text-embedding-3-large - Higher quality embeddings
  • text-embedding-ada-002 - Legacy model

Configuration

const openai = createOpenAI({
  apiKey: 'your-api-key',
  baseURL: 'https://api.openai.com/v1', // Optional: custom base URL
  organization: 'org-xxx', // Optional: organization ID
  retry: {
    maxRetries: 3,
    initialDelay: 1000,
    maxDelay: 30000,
  },
});

License

MIT