> ## 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 Mastra with SaladCloud

> Build a Mastra agent using the SaladCloud AI SDK provider and Salad AI Gateway.

*Last Updated: September 17, 2026*

[Mastra](https://mastra.ai) is a framework for building AI agents and workflows. Connect an agent directly to
[Salad AI Gateway](/ai-gateway/explanation/overview) using the published SaladCloud AI SDK provider and
`qwen3.6-35b-a3b`. AI Gateway is in beta with [pay-per-token billing](/ai-gateway/reference/pricing).

## Prerequisites

* Node.js 22.13.0 or newer
* A [SaladCloud account](https://portal.salad.com), credits, and an organization-specific AI Gateway API key from
  [Pay-Per-Token Onboarding](/ai-gateway/tutorials/pay-per-token-onboarding)

## Step 1: Install the Packages

In a new project directory:

```bash theme={null}
npm init -y
npm pkg set type=module
npm install @mastra/core@^1.67.0 @saladtechnologies-oss/ai-sdk-provider@^0.2.0
```

For an existing project, keep its configuration and install the packages in that project. Mastra added support for AI
SDK 7 model providers in `@mastra/core` version `1.47.0`; this guide uses the newer `1.67.0` release line. See
[Mastra's AI SDK 7 support documentation](https://mastra.ai/blog/ai-sdk-v7-support).

## Step 2: Set Your API Key

Create `.env`:

```bash theme={null}
SALAD_CLOUD_API_KEY=your-ai-gateway-api-key
```

Add `.env` to `.gitignore`. Keep this key server-side and do not use your regular SaladCloud API key in its place. The
SaladCloud provider supplies the Gateway endpoint and Bearer authentication automatically.

## Step 3: Create the Agent

Create `agent.js`:

```javascript agent.js theme={null}
import { Agent } from '@mastra/core/agent'
import { saladCloud } from '@saladtechnologies-oss/ai-sdk-provider'

export const agent = new Agent({
  id: 'salad-assistant',
  name: 'Salad Assistant',
  instructions: 'You are a helpful assistant. Give clear, concise answers.',
  model: saladCloud('qwen3.6-35b-a3b'),
})
```

<Note>
  Pass the model object returned by `saladCloud(...)`. Do not replace it with the string `salad-cloud/qwen3.6-35b-a3b`:
  the models.dev listing does not currently add SaladCloud to Mastra's built-in model registry. This direct SDK setup
  does not depend on that registry.
</Note>

## Step 4: Generate a Response

Create `test.js`:

```javascript test.js theme={null}
import { agent } from './agent.js'

const result = await agent.generate('Explain distributed GPU computing in one paragraph.')
console.log(result.text)
```

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

You should see the model's answer in the terminal. Requests are billed to your SaladCloud organization.

## Stream a Response

Create `stream.js`:

```javascript stream.js theme={null}
import { agent } from './agent.js'

const result = await agent.stream('Give three practical uses for an AI coding assistant.')
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

* **Unknown provider or model:** use `saladCloud('qwen3.6-35b-a3b')` as shown, not a model-router string.
* **Unsupported model version:** upgrade `@mastra/core` to the version range above. The SaladCloud `0.2.0` package uses
  the AI SDK 7 provider interface.
* **Missing API key or HTTP 401:** check that `.env` contains `SALAD_CLOUD_API_KEY`, run Node with `--env-file=.env`,
  and use your organization's AI Gateway key.
