> ## Documentation Index
> Fetch the complete documentation index at: https://docs.salad.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Use Vercel AI SDK with SaladCloud

> Learn how to build AI-powered JavaScript and Next.js applications using the Vercel AI SDK with a self-hosted model on SaladCloud.

*Last Updated: May 18, 2026*

## Introduction

The [Vercel AI SDK](https://sdk.vercel.ai) 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.

The Vercel AI SDK works with SaladCloud in two ways:

* **[Salad AI Gateway](/ai-gateway/explanation/overview)** - no infrastructure to deploy or manage. Sign up for access,
  point your app at a single shared endpoint, and use your Salad API key directly. Currently in closed beta with monthly
  flat-rate access.
* **Self-hosted model** - deploy your own SaladCloud container group for full control over the model, hardware, and
  configuration. Still very easy to set up and use.

## Prerequisites

Before getting started, make sure you have:

* A [SaladCloud account](https://portal.salad.com)
* Node.js 18+ installed

## Step-by-Step Setup

### Step 1: Choose Your Backend

<Tabs>
  <Tab title="Salad AI Gateway">
    Salad AI Gateway is the fastest way to get started - no container groups to deploy, no cold starts to wait for.

    1. Sign up for early access at [salad.com/ai-gateway](https://salad.com/ai-gateway).
    2. Once approved, find your **Salad API key** in the [portal](https://portal.salad.com/api-key).

    Available models:

    | Model             | Description                                                              |
    | :---------------- | :----------------------------------------------------------------------- |
    | `qwen3.6-35b-a3b` | Qwen 3.6 35B-A3B - best for agentic tasks, coding, and complex reasoning |
    | `qwen3.6-27b`     | Qwen 3.6 27B - strong balance of capability and speed                    |
    | `qwen3.5-9b`      | Qwen 3.5 9B - fastest response times, suited for lighter tasks           |
  </Tab>

  <Tab title="Self-Hosted on SaladCloud">
    First, deploy an OpenAI-compatible LLM server on SaladCloud.

    * Go to the [SaladCloud portal](https://portal.salad.com) 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.6-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.6-35B-A3B](/container-engine/reference/recipes/qwen3.6-35b-a3b-llama-cpp) - A powerful Mixture of Experts
      model optimized for instruction-following tasks.

    Recipes for custom deployments (best for advanced users):

    * [llama.cpp](/container-engine/reference/recipes/llama-cpp) - Supports GGUF models
    * [sglang](/container-engine/reference/recipes/sglang) - High-performance inference
    * [vllm](/container-engine/reference/recipes/vllm) - Popular LLM serving framework
    * [ollama](/container-engine/reference/recipes/ollama) - Simple model management
    * [tgi](/container-engine/reference/recipes/tgi) - Hugging Face Text Generation Inference server

    After deployment, note your **API endpoint URL** (e.g., `https://your-endpoint.salad.cloud`).
  </Tab>
</Tabs>

### Step 2: Install the Dependencies

In your project directory, install the Vercel AI SDK and the OpenAI-compatible provider:

```bash theme={null}
npm install ai @ai-sdk/openai-compatible
```

The Vercel AI SDK uses ES modules. Make sure your `package.json` has `"type": "module"` set:

```bash theme={null}
npm pkg set type=module
```

To use environment variables for your API key and endpoint, also install `dotenv`:

```bash theme={null}
npm install dotenv
```

### Step 3: Configure the SaladCloud Provider

<Tabs>
  <Tab title="Salad AI Gateway">
    Store your credentials in a `.env` file:

    ```bash theme={null}
    SALAD_API_KEY=your-salad-api-key
    ```

    Create a provider instance pointing to the AI Gateway endpoint:

    ```javascript theme={null}
    import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
    import dotenv from 'dotenv'
    dotenv.config()

    const saladcloud = createOpenAICompatible({
      name: 'saladcloud',
      baseURL: 'https://ai.salad.cloud/v1',
      apiKey: process.env.SALAD_API_KEY,
    })
    ```

    No custom headers are needed - your Salad API key in `apiKey` is all that's required.
  </Tab>

  <Tab title="Self-Hosted on SaladCloud">
    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`:

    ```javascript theme={null}
    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):

    ```bash theme={null}
    SALAD_API_KEY=your-salad-api-key
    SALAD_BASE_URL=https://your-endpoint.salad.cloud/v1
    ```
  </Tab>
</Tabs>

### Step 4: Generate Text and Test the Connection

Use `generateText` to test that your setup works:

```javascript theme={null}
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.6-35b-a3b'),
  prompt: 'Explain distributed GPU computing in one paragraph.',
})

console.log(text)
```

Run it with:

```bash theme={null}
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:

```javascript theme={null}
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.6-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)
}
```
