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

# Vercel AI SDK

> Official Runcrate provider for the Vercel AI SDK — generateText, streamText, generateImage

export const RuncrateStyles = () => {
  if (typeof document !== 'undefined' && !document.getElementById('runcrate-overrides')) {
    const s = document.createElement('style');
    s.id = 'runcrate-overrides';
    s.textContent = `
      /* Match Runcrate's rounding scale (--radius: 0.75rem) */
      .rounded-sm { border-radius: 0.5rem !important; }   /* 8px */
      .rounded-md { border-radius: 0.625rem !important; } /* 10px */
      .rounded-lg { border-radius: 0.75rem !important; }  /* 12px */
      .rounded-l-sm { border-top-left-radius: 0.5rem !important; border-bottom-left-radius: 0.5rem !important; }
      .rounded-r-sm { border-top-right-radius: 0.5rem !important; border-bottom-right-radius: 0.5rem !important; }
      .rounded-l-md { border-top-left-radius: 0.625rem !important; border-bottom-left-radius: 0.625rem !important; }
      .rounded-r-md { border-top-right-radius: 0.625rem !important; border-bottom-right-radius: 0.625rem !important; }
      .rounded-l-lg { border-top-left-radius: 0.75rem !important; border-bottom-left-radius: 0.75rem !important; }
      .rounded-r-lg { border-top-right-radius: 0.75rem !important; border-bottom-right-radius: 0.75rem !important; }

      /* Cards: never pure white in light mode */
      .card { background-color: #fcfcfc !important; border-radius: 0.75rem !important; }
      html.dark .card { background-color: #141414 !important; }

      /* Docs hero box */
      .rc-hero { background-color: #fcfcfc; border: 1px solid #e0e0e0; }
      html.dark .rc-hero { background-color: #141414; border-color: #242424; }
      html.dark .rc-hero h1 { color: #f5f5f5; }

      /* Runcrate scrollbar — thin, transparent track, hide-until-hover thumb */
      ::-webkit-scrollbar { width: 6px; height: 6px; background-color: transparent; }
      ::-webkit-scrollbar-track { background-color: transparent; }
      ::-webkit-scrollbar-thumb { background-color: rgba(155, 155, 155, 0.5); border-radius: 10px; transition: opacity 0.3s ease; opacity: 0; }
      ::-webkit-scrollbar-thumb:hover { background-color: rgba(155, 155, 155, 0.7); }
      *:hover::-webkit-scrollbar-thumb,
      *:focus::-webkit-scrollbar-thumb,
      *:active::-webkit-scrollbar-thumb { opacity: 1; }
      * { scrollbar-width: thin; scrollbar-color: rgba(155, 155, 155, 0.5) transparent; }
    `;
    document.head.appendChild(s);
  }
  return null;
};

<RuncrateStyles />

The `@runcrate/ai` package is a Runcrate provider for the [Vercel AI SDK](https://ai-sdk.dev). Use it to build AI-powered applications with `generateText`, `streamText`, `generateImage`, structured output, and tool calling — all backed by Runcrate's 140+ open-source models.

## Installation

```bash theme={"theme":"github-dark"}
npm install @runcrate/ai ai
```

Requires `ai` v6+ and Node.js 18+.

## Quick Start

```typescript theme={"theme":"github-dark"}
import { runcrate } from '@runcrate/ai';
import { generateText } from 'ai';

const { text } = await generateText({
  model: runcrate('deepseek-ai/DeepSeek-V3'),
  prompt: 'Explain quantum computing in simple terms.',
});

console.log(text);
```

Set the `RUNCRATE_API_KEY` environment variable, or pass `apiKey` directly when creating the provider.

## Configuration

```typescript theme={"theme":"github-dark"}
import { createRuncrate } from '@runcrate/ai';

const runcrate = createRuncrate({
  apiKey: 'rc_live_...',                       // or RUNCRATE_API_KEY env var
  baseURL: 'https://api.runcrate.ai/v1',      // default
  headers: { 'X-Custom-Header': 'value' },    // optional
});
```

A default instance is also exported for convenience:

```typescript theme={"theme":"github-dark"}
import { runcrate } from '@runcrate/ai';
// Uses RUNCRATE_API_KEY env var automatically
```

***

## Text Generation

### Basic

```typescript theme={"theme":"github-dark"}
import { runcrate } from '@runcrate/ai';
import { generateText } from 'ai';

const { text } = await generateText({
  model: runcrate('deepseek-ai/DeepSeek-V3'),
  prompt: 'What is the capital of France?',
});
```

### Streaming

```typescript theme={"theme":"github-dark"}
import { runcrate } from '@runcrate/ai';
import { streamText } from 'ai';

const result = streamText({
  model: runcrate('deepseek-ai/DeepSeek-V3'),
  prompt: 'Write a short story about a robot.',
});

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

### Chat Messages

```typescript theme={"theme":"github-dark"}
const { text } = await generateText({
  model: runcrate('meta-llama/Llama-4-Scout'),
  messages: [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: 'What is the capital of France?' },
  ],
});
```

## Structured Output

```typescript theme={"theme":"github-dark"}
import { runcrate } from '@runcrate/ai';
import { generateText, Output } from 'ai';
import { z } from 'zod';

const { output } = await generateText({
  model: runcrate('deepseek-ai/DeepSeek-V3'),
  output: Output.object({
    schema: z.object({
      name: z.string(),
      ingredients: z.array(z.string()),
      steps: z.array(z.string()),
    }),
  }),
  prompt: 'Generate a recipe for chocolate chip cookies.',
});
```

## Image Generation

```typescript theme={"theme":"github-dark"}
import { runcrate } from '@runcrate/ai';
import { generateImage } from 'ai';

const { image } = await generateImage({
  model: runcrate.imageModel('black-forest-labs/FLUX.1-schnell'),
  prompt: 'A futuristic cityscape at sunset',
  size: '1024x768',
});

console.log(image.base64);
```

## Embeddings

```typescript theme={"theme":"github-dark"}
import { runcrate } from '@runcrate/ai';
import { embed } from 'ai';

const { embedding } = await embed({
  model: runcrate.embeddingModel('BAAI/bge-large-en-v1.5'),
  value: 'The quick brown fox jumps over the lazy dog',
});
```

## Model Methods

| Method                              | Returns          | Description                                 |
| ----------------------------------- | ---------------- | ------------------------------------------- |
| `runcrate(modelId)`                 | `LanguageModel`  | Chat model (shorthand for `chatModel`)      |
| `runcrate.chatModel(modelId)`       | `LanguageModel`  | Chat model for `generateText`, `streamText` |
| `runcrate.completionModel(modelId)` | `LanguageModel`  | Completion model                            |
| `runcrate.imageModel(modelId)`      | `ImageModel`     | Image generation model for `generateImage`  |
| `runcrate.embeddingModel(modelId)`  | `EmbeddingModel` | Embedding model for `embed`, `embedMany`    |

***

## When to Use Which SDK

| SDK                 | Best For                                                                              |
| ------------------- | ------------------------------------------------------------------------------------- |
| **`@runcrate/ai`**  | Next.js/React apps using the Vercel AI SDK — `useChat`, `streamText`, `generateImage` |
| **`@runcrate/sdk`** | Full platform access — instances, storage, billing, and inference in one client       |
| **OpenAI SDK**      | Drop-in compatibility — just change the base URL                                      |
