multi-ai-client
v1.3.6
Published
Unified AI SDK for OpenAI, Claude, Gemini and Mistral
Maintainers
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
✨ 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:
429500502503504
Built-in exponential backoff for reliability.
🚦 Rate Limit Handling
Automatically detects:
retry-afterNo 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-4ogpt-4o-minigpt-4-turbo
Claude (Anthropic)
new AIClient({
apiKey: "YOUR_KEY",
provider: "anthropic"
})Recommended models
claude-3-5-sonnetclaude-3-opus
Gemini
new AIClient({
apiKey: "YOUR_KEY",
provider: "gemini"
})Recommended models
gemini-1.5-progemini-1.5-flash
Mistral
new AIClient({
apiKey: "YOUR_KEY",
provider: "mistral"
})Recommended models
mistral-large-latestopen-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 Requestsmulti-ai-client automatically reads:
retry-afterand retries safely.
No extra logic required.
🏗 Architecture
AIClient
├── OpenAI
├── Claude (Anthropic)
├── Gemini
└── MistralEach 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.
