SDK overview
One package, five entry points. Install only the peer deps you actually use.
@cleverrouter/sdk is the one package you need. Inside, five entry
points wrap the same gateway differently — pick the one your stack
already uses.
bun add @cleverrouter/sdk@alphaPick an entry
OpenAI SDK
For everything that already speaks openai. Drop-in baseURL
swap plus typed helpers on the side.
Vercel AI SDK
generateText, streamText, tool() and generateObject against
EU models.
Mastra
Plug into new Agent({ model: cr('...') }) with memory and tools.
React hooks
useChat() and useCompletion() for client-side chat UIs.
Edge runtime
No OpenAI-SDK import, no node:* modules. Cloudflare Workers,
Vercel Edge, Deno Deploy.
What's in the box
Peer dependencies are optional
You only install the peers you actually use. The SDK declares them as
optional, so bun install won't drag the OpenAI SDK in for an
edge-only deployment.
| Route | Add |
|---|---|
OpenAI SDK (openai) | bun add openai |
| Vercel AI SDK | bun add ai @ai-sdk/openai-compatible |
| Mastra | bun add @mastra/core |
| React hooks | bun add react |
| Edge runtime | nothing extra |
Typed helpers on every cr instance
Even without the OpenAI SDK, every CleverRouter endpoint has a typed helper:
import { createCleverRouter } from '@cleverrouter/sdk';
const cr = createCleverRouter({ apiKey: process.env.CLEVERROUTER_API_KEY! });
await cr.chat({ model: 'mistral/mistral-small-3.2', messages: [...] });
await cr.stream({ model: '...', messages: [...] });
await cr.embed(['hello', 'world'], { model: 'cohere/embed-v4' });
await cr.rerank({ query: '...', documents: [...] });
await cr.transcribe(file, { language: 'en' });
await cr.listModels({ kind: 'chat' });All of them:
- Are typed end-to-end.
- Throw typed errors (
CRAuthError,CRRateLimitError,CRTimeoutError, …). - Honour retry/timeout config — see Retry & timeout.
- Accept
AbortSignalfor cancellation.
Provider pinning and strategy
Set defaults at construction:
const cr = createCleverRouter({
apiKey: process.env.CLEVERROUTER_API_KEY!,
provider: 'scaleway',
strategy: 'fastest',
});Or override per call:
await cr.chat(
{ model: 'meta/llama-3.3-70b', messages },
{ provider: 'tensorix', strategy: 'cheapest' },
);Full reference: Provider pinning.
Versioning
The SDK is on the alpha npm tag while we're pre-1.0.0. Pin
explicitly:
bun add @cleverrouter/sdk@alphaBundle size
~39.5 KB minified for the main entry. The edge entry drops the OpenAI SDK import and is significantly smaller.
Related
- Migrate from OpenAI — two-line diff.
- React hooks — security pattern for client keys.
- Edge runtime — Cloudflare Workers, Vercel Edge.