# Use the Vercel AI SDK with the i14 API

> Call Sugar Glider from the Vercel AI SDK with the OpenAI-compatible provider, including text generation and streaming.

Source: https://i14.ai/docs/integrations/vercel-ai-sdk/

The [Vercel AI SDK](https://ai-sdk.dev) is a TypeScript toolkit for building AI features. Its OpenAI-compatible provider works with the i14 API, so you can call Sugar Glider (`i14-sugarglider-nemotron3-super-120b-v1`) with `generateText` and `streamText`.

## Install

```bash
npm install ai @ai-sdk/openai-compatible
```

Export your API key, which you can create at [platform.i14.ai](https://platform.i14.ai/):

* macOS and Linux

  bash or zsh

  ```bash
  export I14_API_KEY="your_api_key_here"
  ```

* Windows

  PowerShell

  ```powershell
  $env:I14_API_KEY = "your_api_key_here"
  ```

## Generate text

```typescript
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";

const i14 = createOpenAICompatible({
  name: "i14",
  baseURL: "https://api.i14.ai/v1",
  apiKey: process.env.I14_API_KEY,
});

const { text, usage, finishReason } = await generateText({
  model: i14("i14-sugarglider-nemotron3-super-120b-v1"),
  prompt: "Explain the difference between a process and a thread in one paragraph.",
  maxOutputTokens: 8192,
});

console.log(text);
console.log(finishReason, usage);
```

## Stream text

```typescript
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { streamText } from "ai";

const i14 = createOpenAICompatible({
  name: "i14",
  baseURL: "https://api.i14.ai/v1",
  apiKey: process.env.I14_API_KEY,
});

const result = streamText({
  model: i14("i14-sugarglider-nemotron3-super-120b-v1"),
  system: "You are a helpful assistant.",
  prompt: "Write a short poem about the ocean.",
  maxOutputTokens: 8192,
});

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

process.stdout.write("\n");
console.log(await result.usage);
```

> **Caution**
>
> Always set `maxOutputTokens`. If you omit it, the i14 API stops after 100 tokens and `finishReason` is `"length"`. Sugar Glider thinks before it answers, and thinking tokens count toward `maxOutputTokens`.
