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

# Vercel AI SDK

> Next.js and Node.js streaming via OpenAI-compatible provider

<Error>
  This page contains an unverified test date marked in <span style="color:red">red</span>. Needs verification (Vijay, Adam, Alex, Product/Legal).
</Error>

# Vercel AI SDK

Use the AI SDK's OpenAI-compatible provider to call Radium from Node.js or server-side code in a Next.js application.

## Before you start

You need:

* Node.js 22 or newer
* npm
* A Radium API key

<Warning>
  Radium calls must run on the server. Never expose the key through browser code or a `NEXT_PUBLIC_*` environment variable.
</Warning>

## 1. Create a project and install the packages

```bash theme={null}
mkdir radium-vercel-ai-sdk && cd radium-vercel-ai-sdk
npm init -y
npm pkg set type=module
npm install ai @ai-sdk/openai-compatible
```

## 2. Set your Radium credentials

<CodeGroup>
  ```bash macOS or Linux theme={null}
  export RADIUM_API_KEY="your-radium-api-key"
  export RADIUM_MODEL="hal-1.0"
  ```

  ```powershell Windows PowerShell theme={null}
  $env:RADIUM_API_KEY = "your-radium-api-key"
  $env:RADIUM_MODEL = "hal-1.0"
  ```
</CodeGroup>

## 3. Create main.mjs

```javascript theme={null}
import { generateText } from "ai";
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";

if (!process.env.RADIUM_API_KEY) {
    throw new Error("Set RADIUM_API_KEY before running this program.");
}

const radium = createOpenAICompatible({
    name: "radium",
    apiKey: process.env.RADIUM_API_KEY,
    baseURL: "https://api.radium.cloud/v1",
});

const { text } = await generateText({
    model: radium.chatModel(process.env.RADIUM_MODEL ?? "hal-1.0"),
    system: "Follow the user's instruction exactly.",
    prompt: "Reply with exactly: Radium connected.",
    maxOutputTokens: 512,
    temperature: 0,
});

if (!text?.trim()) {
    throw new Error("Radium returned no visible text.");
}
console.log(`RADIUM_RESPONSE: ${text.trim()}`);
```

<Note>
  The base URL must include `/v1`. The provider adds `/chat/completions` itself.
</Note>

## 4. Run it

```bash theme={null}
node main.mjs
```

Expected output:

```
RADIUM_RESPONSE: Radium connected.
```

## Choose a model

```bash theme={null}
export RADIUM_MODEL="clarke-1.0"  # or hal-1.0 or tycho-1.0
node main.mjs
```

## Migrate an existing AI SDK application

Create the provider once:

```javascript theme={null}
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";

const radium = createOpenAICompatible({
    name: "radium",
    apiKey: process.env.RADIUM_API_KEY,
    baseURL: "https://api.radium.cloud/v1",
});
```

Then replace the model supplied to `generateText`, `streamText`, or your server route:

```javascript theme={null}
const model = radium.chatModel("hal-1.0");
```

Your prompts and server-side AI SDK handlers can remain unchanged.

## Streaming

Use `streamText` for token-by-token streaming:

```javascript theme={null}
import { streamText } from "ai";

const result = streamText({
    model: radium.chatModel("clarke-1.0"),
    prompt: "Write a haiku about clouds.",
});

for await (const delta of result.textStream) {
    process.stdout.write(delta);
}
```

## Tool calling

The Vercel AI SDK supports tool calling with Radium via the same `tools` parameter:

```javascript theme={null}
import { generateText, tool } from "ai";
import { z } from "zod";

const { toolResults } = await generateText({
    model: radium.chatModel("hal-1.0"),
    prompt: "What is the weather in San Francisco?",
    tools: {
        weather: tool({
            description: "Get the weather for a location",
            parameters: z.object({
                city: z.string().describe("The city name"),
            }),
            execute: async ({ city }) => {
                return { temperature: 72, conditions: "sunny" };
            },
        }),
    },
});
```

## Troubleshooting

| Problem | Fix |
| - | - |
| Node version errors | Use Node.js 22 or newer for the pinned packages |
| Authentication errors | Verify `RADIUM_API_KEY` in the server process |
| `404` | Use the exact base URL and one of the listed model IDs |
| Browser key exposure | Move the call into a server route or server action |
| Provider compatibility warning | Update both `ai` and `@ai-sdk/openai-compatible` together so they use compatible current releases |

## Validation

<Check>
  These instructions were verified with Node.js 24.1.0, `ai@7.0.71`, and `@ai-sdk/openai-compatible@3.0.33` on <span style="color:red">August 20, 2026</span>. You do not need those exact package versions.
</Check>

Text generation and multi-step tool calling passed cleanly with `hal-1.0`, `clarke-1.0`, and `tycho-1.0`.

## Next steps

<CardGroup cols={2}>
  <Card title="API quickstart" icon="bolt" href="/quickstart">Call Radium directly</Card>
  <Card title="Tool calling" icon="wrench" href="/core-concepts/tool-calling">The tool\_use and tool\_result contract</Card>
</CardGroup>


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