# Vercel AI SDK

Use the [AI SDK](https://ai-sdk.dev/) with its OpenAI-compatible provider to
generate and stream text from Aurora. This connects directly to Aurora; a
Vercel AI Gateway account is not required.

> Available Inference endpoint: `https://ai.aur.lu/v1` (Aurora).

## Install and prepare

In a Node.js project:

```bash
npm install ai @ai-sdk/openai-compatible
export AURORA_API_TOKEN="<your-token>"
```

Create the token using [Getting started](https://docs.aur.lu/docs/inference/getting-started). Use a Node.js
version supported by your installed packages. Keep this provider in server-side
code so the token is not exposed to the browser.

## Generate text

Save as `aurora-ai.mjs`:

```javascript
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { generateText } from 'ai';

const apiKey = process.env.AURORA_API_TOKEN;
if (!apiKey) throw new Error('Set AURORA_API_TOKEN before running this script');

const aurora = createOpenAICompatible({
  name: 'aurora',
  baseURL: 'https://ai.aur.lu/v1',
  apiKey,
  includeUsage: true,
});

const result = await generateText({
  model: aurora.chatModel('deepseek/deepseek-v4-flash'),
  prompt: 'Say hello in one sentence.',
});

console.log(result.text);
console.log(result.usage);
```

```bash
node aurora-ai.mjs
```

Expect a greeting and usage metadata. `chatModel` explicitly selects Chat
Completions. The `name` labels the local provider; the model ID has no `aurora/`
or `openai/` prefix. The base URL includes `/v1`.

## Stream text

Change the `ai` import to `import { streamText } from 'ai';`, then replace the
`generateText` call and output statements with:

```javascript
const result = streamText({
  model: aurora.chatModel('deepseek/deepseek-v4-flash'),
  prompt: 'Explain streaming in three sentences.',
});

for await (const text of result.textStream) {
  process.stdout.write(text);
}
console.log();
console.log(await result.usage);
```

`includeUsage: true` requests token usage in streamed responses. For a server
route, use the AI SDK response helper appropriate to your frontend protocol;
plain text streams and AI SDK UI message streams are different formats.

## Troubleshooting

- **Unexpected `/responses` request:** Use `@ai-sdk/openai-compatible` and
  `chatModel` as shown. Do not rely on another adapter's default API selection.
- **Tools or structured output fail:** Check the selected model's capabilities
  before enabling tools or `supportsStructuredOutputs`. The provider package's
  feature list is broader than Aurora's documented endpoint set.
- **Dependency type errors:** Install compatible versions of `ai` and its
  provider package together and check their peer dependency requirements.
- **Missing usage:** Keep `includeUsage: true` and consume the stream to completion.

See [shared troubleshooting](https://docs.aur.lu/docs/inference/integrations#troubleshooting) and the
[AI SDK OpenAI-compatible reference](https://ai-sdk.dev/providers/openai-compatible-providers).
