Vercel AI SDK
Vercel AI SDK is a TypeScript toolkit for building AI application flows, including text generation, streaming UI responses, tool calls, and structured output. In AISIX deployments, the application can keep using AI SDK helpers while the model provider configuration points to the gateway.
The OpenAI provider package lets Vercel AI SDK call a custom base URL with an API key. Use that provider when a TypeScript application should send Responses API requests through AISIX.
This guide uses the AI SDK core package with @ai-sdk/openai. You will create an OpenAI provider that points at AISIX and use an AISIX model alias from application code.
Prerequisites
Before starting, prepare the following:
- A TypeScript project for the application.
- A running AISIX gateway with the proxy listener available.
- An AISIX caller API key.
- A model alias the caller API key can access through the Responses API.
If AISIX is already deployed for your organization, obtain the gateway URL, model alias, and caller API key from the team that manages it. Otherwise, follow the Open-Source AISIX Gateway Quickstart or AISIX Cloud Quickstart, or contact API7 for Hybrid Cloud access.
Configure Vercel AI SDK
Install the AI SDK packages if the application does not already include them:
npm install ai @ai-sdk/openai
Set the values that the application will use:
# Replace with your values
export AISIX_BASE_URL="http://127.0.0.1:3000/v1"
export AISIX_API_KEY="YOUR_CALLER_API_KEY"
export AISIX_MODEL="gpt-4o-prod"
Create an OpenAI provider for AISIX:
import { createOpenAI } from "@ai-sdk/openai";
import { generateText } from "ai";
const aisix = createOpenAI({
apiKey: process.env.AISIX_API_KEY,
baseURL: process.env.AISIX_BASE_URL,
});
async function main() {
const { text } = await generateText({
model: aisix.responses(process.env.AISIX_MODEL ?? "gpt-4o-prod"),
prompt: "Write one sentence about model governance.",
});
console.log(text);
}
main();
The model value is the AISIX model alias, not the upstream provider model ID. AISIX governs the model request path: it authenticates the caller API key, resolves the alias, applies configured policies, records telemetry, and dispatches the request to the provider behind the alias. The application still owns UI streaming, tool orchestration, and response handling.
The OpenAI provider in AI SDK also supports Chat Completions through aisix.chat(...), and the @ai-sdk/openai-compatible provider remains useful for broad OpenAI-compatible chat integrations.
Verify the Integration
Run the application from the shell where the AISIX environment variables are set.
When the request succeeds, verify the following results:
- The application prints generated text.
- AISIX records a successful
POST /v1/responsesrequest for the selected model alias.
If you use the AISIX Cloud control plane, verify the request in the AISIX gateway logs. For standalone gateways, use your configured logs, metrics, or upstream provider logs.
If the request fails, first confirm that the caller API key can access the selected model alias and that baseURL points to the AISIX proxy API root with /v1.
This guide uses Responses-backed text generation. Validate any other AI SDK helper, such as streaming, tool calling, or structured output, before relying on gateway policy or telemetry for that path.
Next Steps
- Responses API: review gateway-facing Responses behavior.
- OpenAI-Compatible API: use Chat Completions when a workflow needs broad OpenAI-compatible support.
- Streaming: confirm streaming behavior before using streamed UI responses.
- Tool Calling: review OpenAI-compatible tool-call behavior through AISIX.