Vercel AI SDK

What is Vercel AI SDK?

The Vercel AI SDK is a powerful and flexible open-source library designed to help developers build AI-powered user interfaces quickly and efficiently within modern JavaScript/TypeScript web applications.

Core Purpose:

  • Managing the state and user experience of AI interactions: Especially for streaming responses, which are crucial for responsive AI UIs.

  • Building common AI UI patterns: Such as chatbots, text completion fields, and content generation tools.

Sample implementation using nexos.ai

  • Setup typescript project

  • Install dependencies

  • Define environments NEXOS_API_KEY=team-api-key NEXOS_BASE_URL=https://api.nexos.ai/v1

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

dotenv.config();

let NEXOS_API_KEY = process.env.NEXOS_API_KEY
let NEXOS_BASE_URL= process.env.NEXOS_BASE_URL

if (!NEXOS_API_KEY || !NEXOS_BASE_URL) {
    throw new Error('Please set NEXOS_BASE_URL and NEXOS_API_KEY in your .env file');
}

const provider = createOpenAICompatible({
    name: 'nexos.ai',
    apiKey: NEXOS_API_KEY,
    baseURL: NEXOS_BASE_URL, // e.g. https://api.nexos.ai/v1
});

const { text } = await generateText({
    model: provider('Claude Haiku 4.5'), // or any other OpenAI-compatible model ID available to you 
    prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});

console.log(text);

You can use any open AI compatible model. To check what models are available for you, call Gateway API | nexos.ai documentationarrow-up-right You can use either nexos_model_idor id as model.

Last updated