> ## 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.

> ## Agent Instructions
> For autonomous tasks, use live SaladCloud API responses for current state, availability, quotas, models, and other dynamic values. Use current OpenAPI specifications where provided for paths, schemas, required fields, and enums. Never invent endpoints, fields, prices, availability, quotas, models, or state. Prefer API workflows over Portal steps. Read before changing and never expose credentials, signed media URLs, prompts, or sensitive outputs. Retry only safe or idempotent operations with bounded backoff, honoring Retry-After. Verify every write with a read. Stop rather than repeat an uncertain non-idempotent or billable request. AI Gateway uses an organization-specific Bearer key and live /v1/models discovery. Do not delete, cancel, stop, or reduce capacity without explicit user intent. Bind shared operation IDs to the selected product path. Treat Container Engine instances as interruptible and local state as ephemeral. Install the SaladCloud skills (npx skills add https://docs.salad.com), start from the salad skill and /agents/overview; docs MCP: https://docs.salad.com/mcp.

# Use Vercel AI SDK with SaladCloud

> Build JavaScript and Next.js applications with AI SDK 7, the SaladCloud provider, and Salad AI Gateway or a self-hosted model.

*Last Updated: September 17, 2026*

## Introduction

The [Vercel AI SDK](https://ai-sdk.dev/docs/introduction) provides a shared interface for building AI-powered JavaScript
and TypeScript applications. For AI SDK 7, use the published
[SaladCloud provider](https://github.com/SaladTechnologies/ai-sdk-provider) to connect to Salad AI Gateway. For
self-hosted OpenAI-compatible servers, use `@ai-sdk/openai-compatible` instead.

> [!NOTE]
>
> This is a direct connection to SaladCloud using the AI SDK library, not a connection through the hosted Vercel AI
> Gateway. You do not need a Vercel account or Vercel API key.

The Vercel AI SDK works with SaladCloud in two ways:

* **[Salad AI Gateway](https://docs.salad.com/ai-gateway/explanation/overview.md)** - no infrastructure to deploy or manage. Available in beta
  with [pay-per-token billing](https://docs.salad.com/ai-gateway/reference/pricing.md). Connect to the shared endpoint using your
  organization-specific AI Gateway API key.
* **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 22 or newer installed

## Step-by-Step Setup

### Step 1: Choose Your Backend

> [tab] 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 in to the [SaladCloud portal](https://portal.salad.com).
> 2. Follow [Pay-Per-Token Onboarding](https://docs.salad.com/ai-gateway/tutorials/pay-per-token-onboarding.md) to add credits and create your
>    organization's **AI Gateway API key**.
>
> This guide uses `qwen3.6-35b-a3b`.

> [tab] 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](https://docs.salad.com/container-engine/reference/recipes/qwen3.6-35b-a3b-llama-cpp.md) - A powerful Mixture of Experts
>   model optimized for instruction-following tasks.
>
> Recipes for custom deployments (best for advanced users):
>
> * [llama.cpp](https://docs.salad.com/container-engine/reference/recipes/llama-cpp.md) - Supports GGUF models
> * [sglang](https://docs.salad.com/container-engine/reference/recipes/sglang.md) - High-performance inference
> * [vllm](https://docs.salad.com/container-engine/reference/recipes/vllm.md) - Popular LLM serving framework
> * [ollama](https://docs.salad.com/container-engine/reference/recipes/ollama.md) - Simple model management
> * [tgi](https://docs.salad.com/container-engine/reference/recipes/tgi.md) - 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 a new project directory, initialize an ES module project. If you already have a project, keep its existing
configuration and adapt the examples to its module system.

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

Install the packages for your chosen backend:

> [tab] Salad AI Gateway
>
> ```bash theme={null}
> npm install ai@7 @saladtechnologies-oss/ai-sdk-provider@^0.2.0
> ```
>
> Version `0.2.0` of the SaladCloud provider implements the AI SDK 7 provider interface. Do not use it with
> `ai@6` or older.

> [tab] Self-Hosted on SaladCloud
>
> ```bash theme={null}
> npm install ai@7 @ai-sdk/openai-compatible@3
> ```

### Step 3: Configure the SaladCloud Provider

> [tab] Salad AI Gateway
>
> Create a `.env` file with your organization's **AI Gateway API key**:
>
> ```bash theme={null}
> SALAD_CLOUD_API_KEY=your-ai-gateway-api-key
> ```
>
> Create `provider.js`:
>
> ```javascript provider.js theme={null}
> import { saladCloud } from '@saladtechnologies-oss/ai-sdk-provider'
>
> export const model = saladCloud('qwen3.6-35b-a3b')
> ```
>
> The provider reads `SALAD_CLOUD_API_KEY` and defaults to `https://ai.salad.cloud/v1`. You do not need to supply a
> base URL or custom headers. A regular SaladCloud API key is not a substitute for an AI Gateway key.

> [tab] Self-Hosted on SaladCloud
>
> Create a `.env` file for your container group:
>
> ```bash theme={null}
> SALAD_API_KEY=your-saladcloud-api-key
> SALAD_BASE_URL=https://your-endpoint.salad.cloud/v1
> ```
>
> Create `provider.js`. This example assumes Container Gateway authentication is enabled; omit `headers` if your
> deployment does not use it. If your model server requires additional authentication, configure that separately.
>
> ```javascript provider.js theme={null}
> import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
>
> const saladcloud = createOpenAICompatible({
>   name: 'saladcloud',
>   baseURL: process.env.SALAD_BASE_URL,
>   headers: {
>     'Salad-Api-Key': process.env.SALAD_API_KEY,
>   },
> })
>
> export const model = saladcloud('qwen3.6-35b-a3b')
> ```
>
> Replace the model ID with the one served by your deployment. Unlike AI Gateway, Container Gateway uses the
> `Salad-Api-Key` header when authentication is enabled.

Add `.env` and `.env.local` to your project's `.gitignore`. Keep the key on the server: do not expose it in browser code
or a `NEXT_PUBLIC_` environment variable. In Next.js, run the provider inside a server-side route or action and store
`SALAD_CLOUD_API_KEY` in `.env.local` or your hosting platform's secret settings.

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

Create `test.js`. This example works with either `provider.js` above:

```javascript test.js theme={null}
import { generateText } from 'ai'
import { model } from './provider.js'

const { text } = await generateText({
  model,
  prompt: 'Explain distributed GPU computing in one paragraph.',
})

console.log(text)
```

Run it with:

```bash theme={null}
node --env-file=.env test.js
```

If you see a response, your setup is complete.

### Streaming Chat Responses

Create `stream.js` to display text as it is generated:

```javascript stream.js theme={null}
import { streamText } from 'ai'
import { model } from './provider.js'

const result = streamText({
  model,
  instructions: 'You are a helpful coding assistant.',
  prompt: 'How do I read a file in Python?',
})

for await (const chunk of result.textStream) {
  process.stdout.write(chunk)
}
process.stdout.write('\n')
```

```bash theme={null}
node --env-file=.env stream.js
```

## Troubleshooting

* **Unsupported model version:** check `npm ls ai @saladtechnologies-oss/ai-sdk-provider`. Use `ai@7` with SaladCloud
  provider `0.2.0`.
* **Missing API key or HTTP 401:** load `.env` with `--env-file` and use an organization-specific AI Gateway key in
  `SALAD_CLOUD_API_KEY`. For self-hosted deployments, check the separate `Salad-Api-Key` header configuration.
* **Unexpected endpoint:** remove an old `SALAD_CLOUD_BASE_URL` override if you intend to use the shared AI Gateway.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.