Use Vercel AI SDK with TokenMaster

In the Vercel AI SDK, use the OpenAI-compatible provider so every call goes to Chat Completions.

You will need

  • An API key starting with tm- (Console → API keys) — Get an API key
  • Base URL: https://tokenmaster.store/v1
  • A model ID, e.g. deepseek/deepseek-v4-pro (see the model list)

Setup

  1. Install: npm i ai @ai-sdk/openai-compatible.
  2. Create the provider with TokenMaster's base URL and call any model ID.
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { generateText } from 'ai';

const tokenmaster = createOpenAICompatible({
  name: 'tokenmaster',
  baseURL: 'https://tokenmaster.store/v1',
  apiKey: process.env.TOKENMASTER_API_KEY,
  includeUsage: true,
});

const { text } = await generateText({
  model: tokenmaster('deepseek/deepseek-v4-pro'),
  prompt: 'Write a haiku about the sea.',
});

Good to know

  • If you use createOpenAI from @ai-sdk/openai instead, provider.chat('model-id') is recommended. The default provider('model-id') uses the Responses API, which TokenMaster also accepts (stateless: set store: false in provider options).
  • Not available through TokenMaster: image generation, speech, rerank, the Assistants API, and OpenAI-hosted tools. Chat Completions, the Responses API (stateless), the Anthropic Messages API and embeddings are available.

Checked against Vercel AI SDK ai 7 / @ai-sdk/openai-compatible 3 on 2026-10-19. Menu names can change between versions.

Troubleshooting

  • 401 / invalid API key — check the key was copied in full and has not been deleted in the console.
  • 404 — the base URL is wrong. It must end in /v1 unless the guide says otherwise.
  • Model not found / not available — use the exact ID from the model list (vendor/model, lowercase). Some vendors are not available in every region.
  • Errors mentioning /responses — the tool is using OpenAI's Responses API. TokenMaster accepts it, but statelessly (no previous_response_id) and without OpenAI-hosted tools; if the tool relies on those, switch it to Chat Completions as noted above.
  • 402 / insufficient balance — top up in the console; requests are refused rather than run up a debt.

SDKs & frameworks

All integration guides → · All model prices →