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
streamText, tool calling andOutput.objectstructured output work as with the provider's own endpoint. For Claude, TopxAI passes the schema to Anthropic's structured outputs: number bounds and array lengths in a Zod schema reach Claude as a hint in the description instead of being enforced (the SDK still validates the result), andz.record,z.any, recursive schemas and tuples get a 400 that says which part of the schema Claude cannot take.- With
@ai-sdk/openai-compatible, setsupportsStructuredOutputs: trueforOutput.object. Without it the SDK sendsjson_objectand no schema, whatever the model. usageon the result carries the token counts TopxAI returns; the charge itself is in the usage log.
If it fails
- 401: the key is wrong or was pasted with a space. 402: the balance is empty. 403: the model id is not sold here or is not on this key's route. See Common error responses.
- The model works in curl but not in the tool: that page lists the usual causes, one per tool.
Models: claude-sonnet-5-5, gpt-6.1-sol · Models & pricing
Related
- Connect your SDK
- Create an API key and choose a route
- The model works in curl but not in my tool
- Common error responses
- LangChain with TopxAI: ChatTopxAI from the langchain-topxai package
- LiteLLM with TopxAI: proxy config and the Python SDK
- TopxAI vs Vercel AI Gateway: list price with no markup, or half of it
- Claude Sonnet 5.5 API pricing
- GPT-6.1 Sol API pricing
Previous: LangChain with TopxAI: ChatTopxAI from the langchain-topxai package · Next: LiteLLM with TopxAI: proxy config and the Python SDK
Other languages: 简体中文