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

multi-ai-client

v1.3.6

Published

Unified AI SDK for OpenAI, Claude, Gemini and Mistral

Readme

multi-ai-client

A powerful, production-ready unified AI SDK for JavaScript & TypeScript.

Interact with multiple AI providers using one clean API:

OpenAI · Claude (Anthropic) · Gemini · Mistral

Build AI applications faster with:

✅ Unified API
chat() + stream()
✅ Real-time streaming (AsyncIterator)
✅ Smart retry system
✅ Rate limit handling
✅ TypeScript support
✅ Extensible architecture


npm downloads license typescript


✨ Why multi-ai-client?

Every AI provider has a different API.

Different:

  • request formats
  • authentication methods
  • streaming implementations
  • response formats
  • SDK logic

That means:

❌ more complexity
❌ duplicated code
❌ harder maintenance

multi-ai-client solves this problem by exposing one unified API for every provider.

Write your code once.

Switch providers anytime.


🚀 Features

🤖 Unified API

One interface for:

  • OpenAI
  • Claude (Anthropic)
  • Gemini
  • Mistral

No provider-specific code.


💬 Unified Chat API

Simple and consistent API across providers.

await ai.chat("Explain quantum computing")

⚡ Real-Time Streaming

Built-in streaming with AsyncIterator.

for await (const chunk of ai.stream(prompt)) {
  console.log(chunk.content)
}

🔄 Smart Retry System

Automatically retries failed requests.

Supports:

  • 429
  • 500
  • 502
  • 503
  • 504

Built-in exponential backoff for reliability.


🚦 Rate Limit Handling

Automatically detects:

retry-after

No manual retry logic required.


🧠 TypeScript First

Fully typed API.

Autocomplete support included.


📦 Lightweight

Fast and minimal architecture.


🔌 Extensible Architecture

Designed for future extensibility:

  • plugins
  • custom providers
  • middleware
  • caching
  • templates

📦 Installation

npm install multi-ai-client

⚡ Quick Start

import { AIClient } from "multi-ai-client"

const ai = new AIClient({
  apiKey: process.env.OPENAI_API_KEY!,
  provider: "openai"
})

const response =
  await ai.chat(
    "Explain artificial intelligence simply"
  )

console.log(response)

🔌 Supported Providers

OpenAI

new AIClient({
  apiKey: "YOUR_KEY",
  provider: "openai"
})

Recommended models

  • gpt-4o
  • gpt-4o-mini
  • gpt-4-turbo

Claude (Anthropic)

new AIClient({
  apiKey: "YOUR_KEY",
  provider: "anthropic"
})

Recommended models

  • claude-3-5-sonnet
  • claude-3-opus

Gemini

new AIClient({
  apiKey: "YOUR_KEY",
  provider: "gemini"
})

Recommended models

  • gemini-1.5-pro
  • gemini-1.5-flash

Mistral

new AIClient({
  apiKey: "YOUR_KEY",
  provider: "mistral"
})

Recommended models

  • mistral-large-latest
  • open-mistral-7b

💬 Chat Example

import { AIClient } from "multi-ai-client"

const ai = new AIClient({
  apiKey: process.env.OPENAI_KEY!,
  provider: "openai"
})

const response =
  await ai.chat(
    "Write a short story about AI",
    {
      temperature: 0.7,
      maxTokens: 300
    }
  )

console.log(response)

⚡ Streaming Example

Real-time AI responses using AsyncIterator.

import { AIClient } from "multi-ai-client"

const ai = new AIClient({
  apiKey: process.env.OPENAI_KEY!,
  provider: "openai"
})

for await (
  const chunk of ai.stream(
    "Tell me a story about space"
  )
) {
  process.stdout.write(
    chunk.content
  )
}

🧠 Stream Output Format

Each chunk follows a unified format across all providers.

{
  content: "Hello",
  done: false
}

Final chunk:

{
  content: "",
  done: true
}

🔄 Switching Providers

Change providers instantly without rewriting your application logic.

OpenAI

provider: "openai"

Claude

provider: "anthropic"

Gemini

provider: "gemini"

Mistral

provider: "mistral"

Example:

const ai = new AIClient({
  apiKey: process.env.API_KEY!,
  provider: "anthropic"
})

const response =
  await ai.chat(
    "Explain black holes"
  )

console.log(response)

⚙️ Chat Options

Customize your AI responses.

await ai.chat(
  "Explain AI",
  {
    model: "gpt-4o-mini",

    temperature: 0.7,

    maxTokens: 500,

    retry: {
      attempts: 5,
      delay: 1000
    }
  }
)

Available Options

| Option | Type | Description | |--------|------|-------------| | model | string | Model to use | | temperature | number | Creativity level | | maxTokens | number | Maximum output tokens | | retry | object | Smart retry configuration |


🔄 Smart Retry Example

Production-ready retry system.

const response =
  await ai.chat(
    "Explain React",
    {
      retry: {
        attempts: 3,
        delay: 1000
      }
    }
  )

Automatically handles:

  • temporary provider failures
  • network instability
  • API overload

Includes:

✅ exponential backoff
✅ automatic retries
✅ provider recovery


🚦 Rate Limit Handling Example

When a provider returns:

429 Too Many Requests

multi-ai-client automatically reads:

retry-after

and retries safely.

No extra logic required.


🏗 Architecture

AIClient
 ├── OpenAI
 ├── Claude (Anthropic)
 ├── Gemini
 └── Mistral

Each provider is internally isolated while exposing:

chat()
stream()

through one consistent API.


🔮 Roadmap

Completed

  • ✅ Unified API
  • ✅ Multi-provider support
  • chat()
  • stream()
  • ✅ AsyncIterator streaming
  • ✅ Smart Retry System
  • ✅ Rate Limiting Handling
  • ✅ TypeScript support

Coming Soon

  • 🧩 Prompt Templates
  • 🔌 Plugin System for Custom Providers
  • ⚡ Token-Level Streaming Parsing
  • 💾 Intelligent Cache Layer
  • 🌐 Custom API Endpoints
  • 🛠 Middleware Support

🛠 Development

npm install
npm run build

📄 License

MIT © Guillaume SERE


⭐ Support

If you like this project:

  • ⭐ Star the repository
  • 📦 Try the package
  • 🐛 Report issues
  • 💡 Suggest features

Feedback is always appreciated.