Loading...

Docs · Integrations

Vercel AI SDK with TopxAI: createOpenAI, createAnthropic and openai-compatible

Create an AI SDK provider with baseURL https://ai.topxea.com/v1 and a TopxAI key, then use generateText or streamText with any catalogue model.

The AI SDK's provider packages accept a baseURL, so TopxAI is one create… call away.

@ai-sdk/openai

import { createOpenAI } from '@ai-sdk/openai'
import { generateText } from 'ai'

const topxai = createOpenAI({
  baseURL: 'https://ai.topxea.com/v1',
  apiKey: process.env.TOPXAI_API_KEY,
})

const { text } = await generateText({
  model: topxai.chat('claude-sonnet-5-5'),
  prompt: 'Say hello in one sentence.',
})

topxai.chat(id) uses Chat Completions and serves every text model except Jev. topxai.responses("gpt-6.1-sol") uses the Responses API, which TopxAI serves for the GPT models, grok-4.7, deepseek-flash-Abliterated and kimi-k3.1-pro (the latter two use stateless requests). topxai.image("gpt-image-2.5-sunburst") generates images, billed per picture.

@ai-sdk/anthropic

import { createAnthropic } from '@ai-sdk/anthropic'

const claude = createAnthropic({
  baseURL: 'https://ai.topxea.com/v1',
  apiKey: process.env.TOPXAI_API_KEY,
})

const { text } = await generateText({
  model: claude('claude-opus-5-5'),
  prompt: 'Say hello in one sentence.',
})

This package's base URL ends in /v1 (it appends /messages), unlike the Anthropic Python SDK, which takes the origin.

@ai-sdk/openai-compatible

For a provider object without OpenAI-specific options:

import { createOpenAICompatible } from '@ai-sdk/openai-compatible'

const topxai = createOpenAICompatible({
  name: 'topxai',
  baseURL: 'https://ai.topxea.com/v1',
  apiKey: process.env.TOPXAI_API_KEY,
})
const model = topxai('kimi-k3.1-pro')

Notes

If it fails

Models: claude-sonnet-5-5, gpt-6.1-sol · Models & pricing

Related

Previous: LangChain with TopxAI: ChatTopxAI from the langchain-topxai package · Next: LiteLLM with TopxAI: proxy config and the Python SDK

Other languages: 简体中文