Skip to main content
Last Updated: March 27, 2026

Introduction

The Vercel AI SDK is a popular framework for building AI-powered applications in JavaScript and TypeScript. It provides a unified interface for text generation, streaming, structured output, and tool calling - and includes an @ai-sdk/openai-compatible package for connecting to any OpenAI-compatible endpoint, including SaladCloud. Using the Vercel AI SDK with SaladCloud lets you:
  • Build production apps powered by self-hosted models at SaladCloud’s per-hour pricing
  • Stream responses to chat interfaces with built-in streaming support
  • Use any framework - Next.js, Express, Hono, plain Node.js, or any other JavaScript runtime

Prerequisites

Before getting started, make sure you have:

Step-by-Step Setup

Step 1: Deploy an LLM Recipe on SaladCloud

First, deploy an OpenAI-compatible LLM server on SaladCloud.
  • Go to the SaladCloud portal and create an account if you do not already have one.
  • Create an organization or choose an existing one, then click “Deploy a container group”.
  • Select an LLM recipe. The Qwen3.5-35B-A3B (llama.cpp) recipe is a strong choice for general-purpose app development. On the recipe page, provide a name and deploy - the rest is preconfigured with recommended settings.
  • Once deployed, your endpoint will be live and serving an OpenAI-compatible API.
Available recipes: Ready-to-deploy recipes (best for less technical users):
  • qwen3.5-35B-A3B - A powerful Mixture of Experts model optimized for instruction-following tasks.
Recipes for custom deployments (best for advanced users):
  • llama.cpp - Supports GGUF models
  • sglang - High-performance inference
  • vllm - Popular LLM serving framework
  • ollama - Simple model management
  • tgi - Hugging Face Text Generation Inference server
After deployment, note your API endpoint URL (e.g., https://your-endpoint.salad.cloud).

Step 2: Install the Dependencies

In your project directory, install the Vercel AI SDK and the OpenAI-compatible provider:
npm install ai @ai-sdk/openai-compatible
The Vercel AI SDK uses ES modules. Make sure your package.json has "type": "module" set:
npm pkg set type=module
To use environment variables for your API key and endpoint, also install dotenv:
npm install dotenv

Step 3: Configure the SaladCloud Provider

Create a provider instance pointing to your SaladCloud endpoint. If you set SaladCloud to authenticate, you need to do that via the Salad-Api-Key request header - pass it through the headers option rather than apiKey:
import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
import dotenv from 'dotenv'
dotenv.config()

const saladcloud = createOpenAICompatible({
  name: 'saladcloud',
  baseURL: process.env.SALAD_BASE_URL,
  headers: {
    'Salad-Api-Key': process.env.SALAD_API_KEY,
  },
})
Store your credentials in a .env file (never hardcode secrets):
SALAD_API_KEY=your-salad-api-key
SALAD_BASE_URL=https://your-endpoint.salad.cloud/v1

Step 4: Generate Text and Test the Connection

Use generateText to test that your setup works:
import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
import { generateText } from 'ai'
import dotenv from 'dotenv'
dotenv.config()

const saladcloud = createOpenAICompatible({
  name: 'saladcloud',
  baseURL: process.env.SALAD_BASE_URL,
  headers: {
    'Salad-Api-Key': process.env.SALAD_API_KEY,
  },
})

const { text } = await generateText({
  model: saladcloud('qwen3.5-35b-a3b'),
  prompt: 'Explain distributed GPU computing in one paragraph.',
})

console.log(text)
Run it with:
node test.js
If you see a response, your setup is complete.

Streaming Chat Responses

Use streamText for chat interfaces that display responses as they are generated:
import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
import { streamText } from 'ai'
import dotenv from 'dotenv'
dotenv.config()
const saladcloud = createOpenAICompatible({
  name: 'saladcloud',
  baseURL: process.env.SALAD_BASE_URL,
  headers: {
    'Salad-Api-Key': process.env.SALAD_API_KEY,
  },
})

const result = streamText({
  model: saladcloud('qwen3.5-35b-a3b'),
  messages: [
    { role: 'system', content: 'You are a helpful coding assistant.' },
    { role: 'user', content: 'How do I read a file in Python?' },
  ],
})

for await (const chunk of result.textStream) {
  process.stdout.write(chunk)
}