> ## 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:

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

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

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

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

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

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

## Provider Initialization

Instantiate the Neosantara provider using `createOpenAICompatible`:

```typescript theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
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

<CodeGroup>
  ```typescript Single Shot (generateText) icon="js" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
  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":"ayu-dark","dark":"catppuccin-latte"}}
  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();
  ```
</CodeGroup>

## 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":"ayu-dark","dark":"catppuccin-latte"}}
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](/en/gateway/chat-completions/streaming)
* [Example Next.js Projects](https://github.com/neosantara-xyz/examples)
* [Model Catalog & Pricing](/en/gateway/models)


## Related topics

- [Streaming Responses](/en/gateway/chat-completions/streaming.md)
- [Chat Completions](/en/gateway/chat-completions.md)
- [Model Catalog](/en/gateway/models.md)
- [Integrations Overview](/en/integrations/overview.md)
