Use the Vercel AI SDK with Fabric AI Gateway
You can send Vercel AI SDK traffic through Fabric AI Gateway by creating a provider instance with a gateway route as its base URL and your gateway key as a header. The Vercel AI SDK is a TypeScript library, so this topic has TypeScript examples only. It shows you how to configure the OpenAI and Anthropic providers and confirm that requests arrive.
Prerequisites
Before you begin, make sure you have the following:
- The
aipackage, and@ai-sdk/openaior@ai-sdk/anthropic. - A route for an OpenAI or Anthropic connection. For the steps, see Connect an LLM provider.
- A gateway key for the route. Send it in the
fg-api-keyheader, which every route accepts, unless its Key Auth instance is an older one that sets aheaderslist. In that case, send the key in one of the listed headers, and ask your admin which. For more information, see Authenticate and send a request. - The base URL of the route. In the console, select LLMs > Routes, find the route, and then select Copy LLM base URL.
Keep the gateway key in an environment variable:
Configure the OpenAI provider
Create an OpenAI provider with the route’s base URL followed by /v1:
fabric.chat() uses the Chat Completions endpoint, /v1/chat/completions.
Configure the Anthropic provider
The Anthropic provider’s base URL includes /v1, so use the route’s base URL followed by /v1:
In both examples, replace BASE_URL with the URL that you copied. Use a model that the connection allows.
The providers require an API key, but you don’t need a real provider key. When it forwards the request, the gateway adds the key saved on the connection in place of the provider’s key header, so any placeholder value works.
Treat the gateway key as a secret. Don’t commit it to source control.
Confirm that requests pass through the gateway
To confirm that the SDK uses the gateway, do the following:
- Run your code. A successful request prints the model’s reply.
- In the Fabric console, select Traces. To see traces from every namespace, select Admin, and then select Traces.
- Find the request on the route.
If the request returns 401 Unauthorized, check that the fg-api-key header carries a key for this route. For more information, see Troubleshoot authentication errors.
Next steps
- To use the OpenAI SDK directly, see Use the OpenAI SDK with Fabric AI Gateway.
- To use the Anthropic SDK directly, see Use the Anthropic SDK with Fabric AI Gateway.
- To review token usage by model, see Review analytics.

