I Built a Zero-Dependency Library That Unifies 42 LLM Providers Into One API #1
openchat-ai
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I Built a Zero-Dependency Library That Unifies 42 LLM Providers Into One API
Every LLM provider has its own SDK, its own error format, its own auth method.
OpenAI uses
fetchwith a Bearer token. Anthropic has@anthropic-ai/sdk. Ollama runs on localhost:11434 with a completely different API shape. Azure OpenAI requires a resource name and deployment ID. Google Gemini has yet another SDK.Switching providers means rewriting every integration. I've done this three times and decided: never again.
So I built
provider-kit— onechat()function that works across 42 providers. Zero dependencies. 21 kB.The Problem
I was building an AI chat application that needed to support multiple LLM backends. The requirements were:
The existing solutions were either:
I wanted something lightweight, zero-dependency, and JavaScript-native.
The Solution: provider-kit
That's it. No config files, no environment setup, no million-line
node_modules.One API for 42 Providers
Every provider returns the same response format:
{ content, model, usage }. No adapter code needed.Auto-Routing with Health Probes
The real differentiator is
createRouter. It periodically probes each model's availability and routes requests to the best one — in real time, with no restart.If GPT-4 is rate-limited, it automatically falls to GPT-4o-mini. If the network is down, it routes to local Ollama. When the external provider recovers, the next probe detects it and routing adjusts.
Consistent Error Handling
Every error is a
ProviderErrorwith a standard structure:rate_limitauthtimeoutserver_errorquotabad_requestnetworkObservability Built In
Wrap any provider with
createMonitorto track latency, errors, and token usage:Function Calling
The Numbers
How It Started
provider-kit started as a utility module inside a larger project called OpenChat Bridge — a P2P messaging + AI resident platform. After three rounds of refactoring, I realized the provider abstraction layer was the most valuable part. So I extracted it, polished it, and published it as a standalone package.
The entire process — from initial code to npm publish to GitHub release — took about a week of focused work, but the concepts had been brewing for months.
What's Next
provider-kit bench)Try It
And run the 60-second quickstart:
provider-kitWritten by the maintainer of provider-kit and fairy-guardian.
All reactions