For the complete documentation index, see llms.txt. This page is also available as Markdown.

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

Installation

npm install ai @ai-sdk/openai-compatible
# or
pnpm add ai @ai-sdk/openai-compatible
# or
yarn add ai @ai-sdk/openai-compatible

Configuration

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?