Use BigModel.io with the Vercel AI SDK

Use BigModel.io from the Vercel AI SDK with @ai-sdk/openai-compatible or @ai-sdk/anthropic. Both take https://bigmodel.io/v1 as baseURL. generateText, streamText and tools.

On this page
  1. Install
  2. OpenAI-compatible provider
  3. Anthropic provider
  4. Streaming
  5. Tool calling
  6. Verify the setup
  7. Troubleshooting
  8. Related

The Vercel AI SDK reaches BigModel.io through two providers. @ai-sdk/openai-compatible works with any key; @ai-sdk/anthropic needs a key whose group serves /v1/messages.

Provider baseURL Endpoint called
@ai-sdk/openai-compatible https://bigmodel.io/v1 /v1/chat/completions
@ai-sdk/anthropic https://bigmodel.io/v1 /v1/messages

Unlike the Anthropic SDK, @ai-sdk/anthropic's default baseURL already includes /v1, so use https://bigmodel.io/v1 here, not the root.

Copy model IDs from the model catalog; availability depends on the key's group. Run this code on the server (route handler, server action, script), never in the browser, so the key stays private.

bash
export BIGMODEL_API_KEY="sk-..."

#Install

bash
npm install ai @ai-sdk/openai-compatible @ai-sdk/anthropic zod

#OpenAI-compatible provider

TypeScript
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";

const bigmodel = createOpenAICompatible({
  name: "bigmodel",
  baseURL: "https://bigmodel.io/v1",
  apiKey: process.env.BIGMODEL_API_KEY,
  includeUsage: true,
});

const { text, usage } = await generateText({
  model: bigmodel("glm-5.3"),
  prompt: "Explain vector databases in three sentences.",
});
console.log(text, usage);

includeUsage: true asks for token usage on streamed responses as well. If you rely on JSON schema output, check Structured output before setting supportsStructuredOutputs.

#Anthropic provider

TypeScript
import { createAnthropic } from "@ai-sdk/anthropic";
import { generateText } from "ai";

const bigmodelAnthropic = createAnthropic({
  baseURL: "https://bigmodel.io/v1",
  apiKey: process.env.BIGMODEL_API_KEY, // sent as x-api-key; use authToken for Bearer
});

const { text } = await generateText({
  model: bigmodelAnthropic("glm-5.3"),
  prompt: "Explain vector databases in three sentences.",
});
console.log(text);

#Streaming

TypeScript
import { streamText } from "ai";

const result = streamText({
  model: bigmodel("glm-5.3"),
  prompt: "Write a haiku about latency.",
});
for await (const delta of result.textStream) {
  process.stdout.write(delta);
}

In a Next.js route handler, return result.toTextStreamResponse() instead of looping.

#Tool calling

Tools are sent in the provider's native format and forwarded to the model. Whether a model calls them depends on the model.

TypeScript
import { generateText, tool } from "ai";
import { z } from "zod";

const result = await generateText({
  model: bigmodel("glm-5.3"),
  prompt: "What's the weather in Hangzhou?",
  tools: {
    getWeather: tool({
      description: "Get the current weather for a city",
      inputSchema: z.object({ city: z.string() }),
      execute: async ({ city }) => `Sunny in ${city}`,
    }),
  },
});
console.log(result.toolCalls, result.toolResults);

inputSchema is the AI SDK 5 name; older 4.x releases call it parameters.

#Verify the setup

Run the generateText example. A reply with a non-zero usage means the base URL and key work. The request should appear in Usage with endpoint /v1/chat/completions (or /v1/messages for the Anthropic provider).

#Troubleshooting

404 with @ai-sdk/anthropic. Either baseURL is the root (https://bigmodel.io), so the SDK calls /messages, or the key's group is Chat Completions only (... platform only supports /v1/chat/completions). Use https://bigmodel.io/v1, or switch to @ai-sdk/openai-compatible.

404 with @ai-sdk/openai-compatible. baseURL is missing /v1.

401 INVALID_API_KEY or API_KEY_REQUIRED. BIGMODEL_API_KEY is not set in the server runtime (check your hosting provider's environment variables).

503 No available accounts: no available accounts supporting model: .... The model ID is wrong or not in the key's group. Copy it from the model catalog.

usage is empty when streaming. Set includeUsage: true on createOpenAICompatible.

403 INSUFFICIENT_BALANCE or 429. Top up in Billing; for 429 see Limits & rate limits.

Updated · View as Markdown