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

# Vercel AI SDK

> Connect Neosantara language models to Next.js, React, and TypeScript applications with the Vercel AI SDK.

The [Vercel AI SDK](https://ai-sdk.dev/?utm_source=neosantara-docs\&utm_medium=referral) is a unified TypeScript library for building reactive AI web applications. It supports token streaming, conversational UI hooks, and structured output extraction.

## Setup

Install the core SDK and the OpenAI-compatible adapter:

```bash npm icon="terminal" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
npm i ai @ai-sdk/openai-compatible
```

```bash pnpm icon="terminal" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
pnpm add ai @ai-sdk/openai-compatible
```

```bash bun icon="terminal" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
bun add ai @ai-sdk/openai-compatible
```

```bash Bash / zsh icon="terminal" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
export NEOSANTARA_API_KEY="nsk_your_api_key_here"
```

```env .env icon="file-code" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
NEOSANTARA_API_KEY=nsk_your_api_key_here
```

```powershell PowerShell icon="terminal" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
$env:NEOSANTARA_API_KEY="nsk_your_api_key_here"
```

## Provider Initialization

Instantiate the Neosantara provider using `createOpenAICompatible`:

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';

export const neosantara = createOpenAICompatible({
  name: 'neosantara',
  apiKey: process.env.NEOSANTARA_API_KEY,
  baseURL: 'https://api.neosantara.xyz/v1',
});
```

## Text Generation and Streaming

```typescript Single Shot (generateText) icon="js" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { generateText } from 'ai';

const neosantara = createOpenAICompatible({
  name: 'neosantara',
  apiKey: process.env.NEOSANTARA_API_KEY,
  baseURL: 'https://api.neosantara.xyz/v1',
});

const { text, usage } = await generateText({
  model: neosantara('gemini-3.8-flash'),
  prompt: 'Explain microservices architecture in 3 concise sentences.',
});

console.log(text);
console.log('Token usage:', usage);
```

```typescript Terminal Streaming (streamText) icon="js" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { streamText } from 'ai';

const neosantara = createOpenAICompatible({
  name: 'neosantara',
  apiKey: process.env.NEOSANTARA_API_KEY,
  baseURL: 'https://api.neosantara.xyz/v1',
});

const result = streamText({
  model: neosantara('deepseek-v4.1-flash'),
  prompt: 'Provide 3 core clean architecture principles for TypeScript backends.',
});

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

## Next.js App Router Route (`app/api/chat/route.ts`)

Return a standard data stream response compatible with the frontend `useChat` hook:

```typescript app/api/chat/route.ts theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { streamText } from 'ai';

const neosantara = createOpenAICompatible({
  name: 'neosantara',
  apiKey: process.env.NEOSANTARA_API_KEY,
  baseURL: 'https://api.neosantara.xyz/v1',
});

export async function POST(req: Request) {
  const { messages } = await req.json();

  const result = streamText({
    model: neosantara('deepseek-v4.1-flash'),
    messages,
  });

  return result.toDataStreamResponse();
}
```

## Vercel AI SDK Method Comparison

| Method | Return Type | Common Use Cases |
| :- | :- | :- |
| `generateText` | Full text Promise | Background processing, batch jobs, webhook workers |
| `streamText` | Async text stream | Chat completion endpoints, Next.js streaming UIs |
| `generateObject` | Zod-validated Object | Strict JSON parsing, automated entity extraction |

## Next Steps

* [Streaming Documentation](https://docs.neosantara.xyz/en/gateway/chat-completions/streaming.md)
* [Example Next.js Projects](https://github.com/neosantara-xyz/examples)
* [Model Catalog & Pricing](https://docs.neosantara.xyz/en/gateway/models.md)


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