Vercel AI SDK chat UI components
For vendors outside the OpenAI-compat family (Anthropic, Google, Bedrock, 25+ more), bridge the
Vercel AI SDK. You bring your @ai-sdk/* package and hand its model to
createAiSdkProvider; the bridge maps streamText’s output to aparté’s event stream.
npm install @aparte/provider-ai-sdk @aparte/core ai @ai-sdk/anthropicai is a peer dependency pinned to the verified major (^7) — this bridge is the only aparté
module that touches the SDK’s types.
import { createAnthropic } from '@ai-sdk/anthropic';import { createAiSdkProvider } from '@aparte/provider-ai-sdk';import { aparteGlobalConfig, AparteDirectTransport } from '@aparte/core';
aparteGlobalConfig.registerAIProvider(createAiSdkProvider({ id: 'anthropic', name: 'Anthropic', models: [{ id: 'claude-sonnet-4-5', name: 'Claude Sonnet 4.5' }], languageModel: (modelId, auth) => createAnthropic({ apiKey: typeof auth === 'string' ? auth : auth?.apiKey, headers: { 'anthropic-dangerous-direct-browser-access': 'true' }, // BYOK from the browser })(modelId),}));
aparteGlobalConfig.setTransport(new AparteDirectTransport({ byok: true }));The languageModel factory receives the model id and the key/config your key-resolver produced —
rebuild the vendor provider per call for UI-driven BYOK, or ignore auth if your factory already
carries the key. The bridge owns its I/O through the SDK and honours the abort signal, so a user
“stop” cancels the underlying vendor call.
The options object is AiSdkProviderOptions. The bridge also exports its four shaping
functions on their own — toModelMessages, toToolSet, toToolChoice,
fullStreamToAparteEvents — which is what turns a server you already have into an aparté
backend: Keep the key server-side.
That route is yours to write, so the redaction is too: fullStreamToAparteEvents forwards the
SDK’s error part with the vendor’s own prose, and a vendor 401 quotes your key’s prefix, tail
and format — rewrite the error event to a fixed message before it leaves your server, as the
guide’s route does.