Use TeamoRouter with the Vercel AI SDK

The Vercel AI SDK (ai package) talks to TeamoRouter through its OpenAI-compatible provider: set the base URL to TeamoRouter, pass your TeamoRouter API key, and use any model ID from our catalog. Your generateText, streamText and tool code stays the same.

New accounts start with a $0 balance — top up before your first request. Top up from $5. If a request returns 402 (400 on the OpenAI format) with "wallet balance is insufficient", your balance is empty — your base URL and key are fine. Top up and retry.

1. Install and configure

Create an API key in the TeamoRouter dashboard and put it in an environment variable:

bash
npm install ai @ai-sdk/openai-compatible zod
export TEAMOROUTER_API_KEY=sk-teamo-...

Create the provider once and reuse it:

ts
// teamorouter.ts
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';

export const teamorouter = createOpenAICompatible({
  name: 'teamorouter',
  baseURL: 'https://api.teamorouter.cn/v1',
  apiKey: process.env.TEAMOROUTER_API_KEY,
  includeUsage: true, // also return token usage when streaming
});
Setting Value
Base URL https://api.teamorouter.cn/v1
API key sk-teamo-..., sent as Authorization: Bearer
Model ID The ID from our catalog, with no vendor/ prefix, e.g. deepseek-flash

Model IDs you can use:

Available model IDs10 models

DeepSeekDeepSeek6

  • deepseek-flash
  • deepseek-flash-free
  • deepseek-v4-flash-vision-exp
  • deepseek-v4-pro
  • deepseek-v4-flash
  • deepseek-v4-flash-free

ZhipuGLM4

  • glm-5.3-flash
  • glm-5.3-flash-free
  • glm-5.3
  • glm-5.2

2. generateText and streamText

ts
import { generateText, streamText } from 'ai';
import { teamorouter } from './teamorouter';

const { text, usage } = await generateText({
  model: teamorouter('deepseek-flash'),
  prompt: 'Explain what an API gateway does in one sentence.',
});
console.log(text, usage);

const result = streamText({
  model: teamorouter('deepseek-flash'),
  prompt: 'Write a haiku about latency.',
});
for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}

3. Tool calling

ts
import { generateText, tool, stepCountIs } from 'ai';
import { z } from 'zod';
import { teamorouter } from './teamorouter';

const { text } = await generateText({
  model: teamorouter('deepseek-flash'),
  tools: {
    getWeather: tool({
      description: 'Get the current temperature for a city',
      inputSchema: z.object({ city: z.string() }),
      execute: async ({ city }) => ({ city, temperatureC: 22 }),
    }),
  },
  stopWhen: stepCountIs(3), // let the model call the tool, then answer
  prompt: 'What is the weather in Shanghai right now?',
});
console.log(text);

Errors you may see

Status Meaning Fix
401 Missing or wrong API key Check TEAMOROUTER_API_KEY and that the key starts with sk-teamo-
402 (400 on the OpenAI format) with "wallet balance is insufficient" Balance is $0 Top up and retry
400 model_not_available Model ID not in our catalog, or it has a vendor/ prefix Use an ID from the list above, without the prefix

For the raw HTTP endpoints, streaming and caching details, see the API integration guide.

Ready? Three steps to startLog in to the console · top up · create an API key
DiscordGet community help instantly