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@alpha

Pick an entry

What's in the box

(default)

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.

RouteAdd
OpenAI SDK (openai)bun add openai
Vercel AI SDKbun add ai @ai-sdk/openai-compatible
Mastrabun add @mastra/core
React hooksbun add react
Edge runtimenothing 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 AbortSignal for 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@alpha

Bundle size

~39.5 KB minified for the main entry. The edge entry drops the OpenAI SDK import and is significantly smaller.