Skip to main content

Vercel AI SDK connector

nuroute-ai-sdk is the official Vercel AI SDK provider for NuRoute. generateText, streamText, and everything else in the AI SDK route through your NuRoute gateway, the same way you'd plug in @ai-sdk/openai or @ai-sdk/anthropic.

How it works​

nuroute-ai-sdk is built on @ai-sdk/openai-compatible, since the gateway's /v1/chat/completions endpoint already speaks OpenAI's chat completions format. That means it inherits solid, well-tested request/response/streaming handling for free, rather than reimplementing the AI SDK's model interface from scratch — this package only adds NuRoute's own defaults (NUROUTE_API_KEY/NUROUTE_BASE_URL env vars, normalizing a bare gateway URL to include /v1) and threads NuRoute-specific options through via the AI SDK's standard providerOptions mechanism (see Forcing a provider below).

Install​

npm install nuroute-ai-sdk ai

Quick start​

import { createNuRoute } from 'nuroute-ai-sdk';
import { generateText } from 'ai';

const nuroute = createNuRoute({
apiKey: 'aicp-...',
baseURL: 'https://your-nuroute-gateway',
});

const { text } = await generateText({
model: nuroute('auto'), // NuRoute's routing engine picks the best model
prompt: 'Write a haiku about distributed systems.',
});

apiKey/baseURL default to the NUROUTE_API_KEY/NUROUTE_BASE_URL environment variables if you omit them: createNuRoute() with no arguments works in an environment where those are set.

With nuroute('auto'), Artemis Task picks the model for each request.

Streaming​

import { streamText } from 'ai';

const { textStream } = streamText({
model: nuroute('auto'),
prompt: 'Tell me a short story.',
});

for await (const chunk of textStream) {
process.stdout.write(chunk);
}

Forcing a provider​

Pin a specific upstream provider via providerOptions, together with a specific model ID to pin both. With model: 'auto', no router runs: the provider serves the first model it lists.

await generateText({
model: nuroute('claude-sonnet-4-6'),
prompt: 'Hello!',
providerOptions: { nuroute: { provider: 'anthropic' } },
});

Which models can I use?​

The same catalog as everywhere else. See Providers & Models for the full list, and the dashboard's Model Catalog tab for the live view (providers your admin has connected platform-wide, plus any you've connected yourself via BYOK).

What's not supported​

Only chat completions — no embeddings, image, or completion models, since the gateway doesn't expose those today.