Vercel AI SDK
The Vercel AI SDK is a TypeScript toolkit for building AI-powered applications. Connect it to TensorX using the OpenAI-compatible provider.
Prerequisites
Node.js 18+
TensorX API key from app.tensorx.ai
Installation
npm install ai @ai-sdk/openai-compatible
# or
pnpm add ai @ai-sdk/openai-compatible
# or
yarn add ai @ai-sdk/openai-compatibleConfiguration
Create Provider Instance
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
const tensorx = createOpenAICompatible({
name: 'tensorx',
apiKey: process.env.TENSORX_API_KEY,
baseURL: 'https://api.tensorx.ai/v1',
});Environment Variables
Create a .env.local file:
Usage Examples
Text Generation
Streaming Text
Chat Completions
Structured Output
Next.js Integration
API Route (App Router)
React Component
Tool Calling
Model selection
Call GET /v1/models with your TensorX API key and use one of the returned IDs. If the integration depends on a capability or token limit, query GET /v1/model/info before selecting the model. See Models for examples.
Troubleshooting
API connection errors
Verify your configuration:
Streaming not working
Ensure you're using streamText instead of generateText and returning toDataStreamResponse().
Resources
Last updated
Was this helpful?

