AI SDK
The AI SDK is a free open-source library that gives you the tools you need to build AI-powered products. It's compatible with a large selection of providers and models, and has a large selection of additional community supported providers being added regularly.
Prerequisites
In order to use the AI Gateway with any AI SDK powered app you will need to complete these steps first:
-
Create a new provider in the AI Gateway for the provider you want to use with AI SDK
-
Create a new app to use specifically with AI SDK and assign it to the team you created
-
Copy the API URL and API Key shown at the top of the app page
Configure the AI SDK
To route all AI SDK requests through Zuplo instead of directly to the API of the
chosen provider, you must set baseURL in the SDK configuration to point to
your app's API URL with /v1 appended. The app page in the Zuplo Portal shows
the URL, which ends in the app's ID.
Additionally, you will need to change the value of apiKey to the API key of
the app you have configured in Zuplo.
Models are referenced as providerName/model, where providerName is the
provider name configured in your gateway. By default an app can reach any model
offered by the providers configured for the Zuplo project. To limit it to a
curated set, add the
Model Filtering
policy to the app—it applies separate rules to completions (generateText,
streamText) and embeddings (embed), and rejects a capability it doesn't
configure.
Each provider package appends its own operation path to baseURL, so pick the
model factory that targets an endpoint the gateway serves:
/v1/chat/completions for OpenAI-compatible requests, /v1/messages for
Anthropic, /v1/embeddings, and /v1/responses for OpenAI only. The examples
below use the right factory for each provider.
OpenAI
Code
Anthropic
Pass the app's API key as authToken, not apiKey. The provider sends apiKey
as the x-api-key header, which the gateway doesn't read, while authToken is
sent as Authorization: Bearer. Setting both throws an InvalidArgumentError.
Code
The @ai-sdk/google provider speaks Gemini's native protocol: it posts to a
{model}:generateContent path and authenticates with the x-goog-api-key
header, neither of which the AI Gateway serves. Use the
OpenAI-compatible provider
instead—the AI Gateway translates OpenAI-format requests to Google upstream.
Code
Mistral
Code
xAI
Call xai.chat(...) rather than xai(...). The bare callable targets xAI's
Responses API, and the gateway serves /v1/responses for the OpenAI provider
only—an xAI model sent there returns a 400.
Code
Provider options the gateway doesn't forward
On the OpenAI-shaped endpoints (/v1/chat/completions, /v1/embeddings, and
/v1/responses) the gateway rebuilds the upstream request from a per-provider
parameter list instead of forwarding your body as-is. Standard AI SDK settings—
messages, temperature, topP, maxOutputTokens, stopSequences, tools,
toolChoice, responseFormat, presencePenalty, and frequencyPenalty—are
forwarded. Options outside that list are dropped without a warning. For example,
seed and providerOptions.mistral.safePrompt don't reach Mistral, and
temperature is capped at Mistral's maximum of 1.
Anthropic is different: /v1/messages is a native passthrough, so
@ai-sdk/anthropic requests reach Anthropic unchanged apart from the model and
credential, which the gateway sets from your app configuration.