Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
271 changes: 271 additions & 0 deletions docs/adapters/nebius.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
---
title: Nebius Token Factory
id: nebius-adapter
order: 5
---

The Nebius Token Factory adapter provides access to various LLMs hosted on Nebius Token Factory, including DeepSeek, Llama, Qwen, and more. Nebius Token Factory offers an OpenAI-compatible API, making it easy to use these models with TanStack AI.

## Installation

```bash
npm install @tanstack/ai-nebius
```

## Basic Usage

```typescript
import { chat } from "@tanstack/ai";
import { nebiusText } from "@tanstack/ai-nebius";

const stream = chat({
adapter: nebiusText("deepseek-ai/DeepSeek-R1-0528"),
messages: [{ role: "user", content: "Hello!" }],
});
```

## Basic Usage - Custom API Key

```typescript
import { chat } from "@tanstack/ai";
import { createNebiusChat } from "@tanstack/ai-nebius";

const adapter = createNebiusChat(
"deepseek-ai/DeepSeek-R1-0528",
"your-api-key-here"
);

const stream = chat({
adapter,
messages: [{ role: "user", content: "Hello!" }],
});
```

## Configuration

```typescript
import { createNebiusChat } from "@tanstack/ai-nebius";

// With explicit API key
const adapter = createNebiusChat("deepseek-ai/DeepSeek-R1-0528", "your-api-key");

// With custom base URL (optional, defaults to Nebius endpoint)
const adapter = createNebiusChat(
"deepseek-ai/DeepSeek-R1-0528",
"your-api-key",
{ baseURL: "https://api.tokenfactory.nebius.com/v1/" }
);
```

## Available Models

Nebius Token Factory offers a variety of models. You can use any model name as a string, but here are some popular options:

### DeepSeek Models
- `deepseek-ai/DeepSeek-R1-0528` - DeepSeek R1 reasoning model
- `deepseek-ai/DeepSeek-V3-0324` - DeepSeek V3 model

### Llama Models
- `meta-llama/Meta-Llama-3.1-70B-Instruct` - Llama 3.1 70B
- `meta-llama/Meta-Llama-3.1-8B-Instruct` - Llama 3.1 8B
- `meta-llama/Meta-Llama-3.1-405B-Instruct` - Llama 3.1 405B

### Qwen Models
- `Qwen/Qwen2.5-72B-Instruct` - Qwen 2.5 72B
- `Qwen/Qwen2.5-7B-Instruct` - Qwen 2.5 7B
- `Qwen/Qwen2.5-32B-Instruct` - Qwen 2.5 32B

To see all available models, check the [Nebius Token Factory documentation](https://docs.tokenfactory.nebius.com/ai-models-inference/overview).

## Example: Chat Completion

```typescript
import { chat, toStreamResponse } from "@tanstack/ai";
import { nebiusText } from "@tanstack/ai-nebius";

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

const stream = chat({
adapter: nebiusText("deepseek-ai/DeepSeek-R1-0528"),
messages,
});

return toStreamResponse(stream);
}
```

## Example: With Tools

```typescript
import { chat, toolDefinition } from "@tanstack/ai";
import { nebiusText } from "@tanstack/ai-nebius";
import { z } from "zod";

const getWeatherDef = toolDefinition({
name: "get_weather",
description: "Get the current weather",
inputSchema: z.object({
location: z.string(),
}),
});

const getWeather = getWeatherDef.server(async ({ location }) => {
// Fetch weather data
return { temperature: 72, conditions: "sunny" };
});

const stream = chat({
adapter: nebiusText("deepseek-ai/DeepSeek-R1-0528"),
messages,
tools: [getWeather],
});
```

**Note:** Tool support varies by model. Models like DeepSeek R1, Llama 3.1, and Qwen 2.5 generally have good tool calling support.

## Model Options

Nebius supports various provider-specific options compatible with OpenAI's chat completions API:

```typescript
const stream = chat({
adapter: nebiusText("deepseek-ai/DeepSeek-R1-0528"),
messages,
modelOptions: {
temperature: 0.7,
top_p: 0.9,
max_tokens: 1000,
presence_penalty: 0.5,
frequency_penalty: 0.5,
stop: ["END"],
},
});
```

### Available Options

```typescript
modelOptions: {
// Sampling
temperature: 0.7, // 0-2, controls randomness
top_p: 0.9, // 0-1, nucleus sampling

// Generation
max_tokens: 1000, // Maximum tokens to generate
stop: ["END"], // Stop sequences (string or array)

// Penalties
presence_penalty: 0.5, // -2.0 to 2.0
frequency_penalty: 0.5, // -2.0 to 2.0

// Advanced
logit_bias: {}, // Logit bias map
user: "user-123", // User identifier
}
```

## Summarization

Summarize long text content:

```typescript
import { summarize } from "@tanstack/ai";
import { nebiusSummarize } from "@tanstack/ai-nebius";

const result = await summarize({
adapter: nebiusSummarize("deepseek-ai/DeepSeek-R1-0528"),
text: "Your long text to summarize...",
maxLength: 100,
style: "concise", // "concise" | "bullet-points" | "paragraph"
});

console.log(result.summary);
```

## Getting Started with Nebius Token Factory

### 1. Create an Account

Visit [Nebius Token Factory](https://tokenfactory.nebius.com) and sign up using your Google or GitHub account.

### 2. Get an API Key

- Navigate to the **API keys** section in your dashboard
- Click on **Create API key**
- Provide a name for the key
- Save the generated API key securely

### 3. Set Environment Variable

```bash
NEBIUS_API_KEY=your-api-key-here
```

## Environment Variables

Optionally set the API key in environment variables:

```bash
NEBIUS_API_KEY=your-api-key-here
```

The adapter will automatically detect `NEBIUS_API_KEY` from:
- `process.env` (Node.js)
- `window.env` (Browser with injected env)

## API Reference

### `nebiusText(model, config?)`

Creates a Nebius text/chat adapter using environment variables.

**Parameters:**
- `model` - The model name (e.g., 'deepseek-ai/DeepSeek-R1-0528')
- `config.apiKey?` - Optional API key (if not provided, uses NEBIUS_API_KEY env var)
- `config.baseURL?` - Optional base URL (defaults to Nebius endpoint)

**Returns:** A Nebius text adapter instance.

### `createNebiusChat(model, apiKey, config?)`

Creates a Nebius text/chat adapter with an explicit API key.

**Parameters:**
- `model` - The model name
- `apiKey` - Your Nebius API key
- `config.baseURL?` - Optional base URL

**Returns:** A Nebius text adapter instance.

### `nebiusSummarize(model, config?)`

Creates a Nebius summarization adapter using environment variables.

**Returns:** A Nebius summarize adapter instance.

### `createNebiusSummarize(model, apiKey, config?)`

Creates a Nebius summarization adapter with an explicit API key.

**Returns:** A Nebius summarize adapter instance.

## Benefits of Nebius Token Factory

- ✅ **Multiple Models** - Access to DeepSeek, Llama, Qwen, and more
- ✅ **OpenAI-Compatible** - Familiar API interface
- ✅ **Cost-Effective** - Competitive pricing for inference
- ✅ **Scalable** - Enterprise-grade infrastructure
- ✅ **Easy Integration** - Drop-in replacement for OpenAI-compatible workflows

## Limitations

- **Image Generation**: Nebius Token Factory does not support image generation. Use OpenAI or Gemini for image generation.
- **Model Availability**: Available models may vary. Check the [Nebius documentation](https://docs.tokenfactory.nebius.com/ai-models-inference/overview) for current offerings.

## Next Steps

- [Getting Started](../getting-started/quick-start) - Learn the basics
- [Tools Guide](../guides/tools) - Learn about tools
- [Other Adapters](./openai) - Explore other providers

4 changes: 4 additions & 0 deletions docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@
{
"label": "Ollama",
"to": "adapters/ollama"
},
{
"label": "Nebius Token Factory",
"to": "adapters/nebius"
}
]
},
Expand Down
8 changes: 8 additions & 0 deletions knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
"packages/typescript/ai-openai": {
"ignore": ["src/tools/**"]
},
"packages/typescript/ai-solid": {
"tsdown": false,
"ignore": ["tsdown.config.ts"]
},
"packages/typescript/ai-vue": {
"tsdown": false,
"ignore": ["tsdown.config.ts"]
},
"packages/typescript/ai-vue-ui": {
"ignoreDependencies": [
"@crazydos/vue-markdown",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"format": "prettier --experimental-cli --ignore-unknown '**/*' --write",
"generate-docs": "node scripts/generate-docs.ts && pnpm run copy:readme",
"sync-docs-config": "node scripts/sync-docs-config.ts",
"copy:readme": "cp README.md packages/typescript/ai/README.md && cp README.md packages/typescript/ai-devtools/README.md && cp README.md packages/typescript/ai-client/README.md && cp README.md packages/typescript/ai-gemini/README.md && cp README.md packages/typescript/ai-ollama/README.md && cp README.md packages/typescript/ai-openai/README.md && cp README.md packages/typescript/ai-react/README.md && cp README.md packages/typescript/ai-react-ui/README.md && cp README.md packages/typescript/react-ai-devtools/README.md && cp README.md packages/typescript/solid-ai-devtools/README.md",
"copy:readme": "cp README.md packages/typescript/ai/README.md && cp README.md packages/typescript/ai-devtools/README.md && cp README.md packages/typescript/ai-client/README.md && cp README.md packages/typescript/ai-gemini/README.md && cp README.md packages/typescript/ai-ollama/README.md && cp README.md packages/typescript/ai-openai/README.md && cp README.md packages/typescript/ai-react/README.md && cp README.md packages/typescript/ai-react-ui/README.md && cp README.md packages/typescript/react-ai-devtools/README.md && cp README.md packages/typescript/solid-ai-devtools/README.md ",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add @tanstack/ai-nebius to the copy:readme script.

The copy:readme script copies the root README.md to all adapter packages, but the new @tanstack/ai-nebius package is not included in the list. This means the README won't be copied to the new package during the build process.

🔎 Proposed fix
-    "copy:readme": "cp README.md packages/typescript/ai/README.md && cp README.md packages/typescript/ai-devtools/README.md && cp README.md packages/typescript/ai-client/README.md && cp README.md packages/typescript/ai-gemini/README.md && cp README.md packages/typescript/ai-ollama/README.md && cp README.md packages/typescript/ai-openai/README.md && cp README.md packages/typescript/ai-react/README.md && cp README.md packages/typescript/ai-react-ui/README.md && cp README.md packages/typescript/react-ai-devtools/README.md && cp README.md packages/typescript/solid-ai-devtools/README.md ",
+    "copy:readme": "cp README.md packages/typescript/ai/README.md && cp README.md packages/typescript/ai-devtools/README.md && cp README.md packages/typescript/ai-client/README.md && cp README.md packages/typescript/ai-gemini/README.md && cp README.md packages/typescript/ai-nebius/README.md && cp README.md packages/typescript/ai-ollama/README.md && cp README.md packages/typescript/ai-openai/README.md && cp README.md packages/typescript/ai-react/README.md && cp README.md packages/typescript/ai-react-ui/README.md && cp README.md packages/typescript/react-ai-devtools/README.md && cp README.md packages/typescript/solid-ai-devtools/README.md ",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"copy:readme": "cp README.md packages/typescript/ai/README.md && cp README.md packages/typescript/ai-devtools/README.md && cp README.md packages/typescript/ai-client/README.md && cp README.md packages/typescript/ai-gemini/README.md && cp README.md packages/typescript/ai-ollama/README.md && cp README.md packages/typescript/ai-openai/README.md && cp README.md packages/typescript/ai-react/README.md && cp README.md packages/typescript/ai-react-ui/README.md && cp README.md packages/typescript/react-ai-devtools/README.md && cp README.md packages/typescript/solid-ai-devtools/README.md ",
"copy:readme": "cp README.md packages/typescript/ai/README.md && cp README.md packages/typescript/ai-devtools/README.md && cp README.md packages/typescript/ai-client/README.md && cp README.md packages/typescript/ai-gemini/README.md && cp README.md packages/typescript/ai-nebius/README.md && cp README.md packages/typescript/ai-ollama/README.md && cp README.md packages/typescript/ai-openai/README.md && cp README.md packages/typescript/ai-react/README.md && cp README.md packages/typescript/ai-react-ui/README.md && cp README.md packages/typescript/react-ai-devtools/README.md && cp README.md packages/typescript/solid-ai-devtools/README.md"
🤖 Prompt for AI Agents
In package.json around line 36, the "copy:readme" npm script omits the new
@tanstack/ai-nebius package so README.md isn't copied there; update the script
to include "packages/typescript/ai-nebius/README.md" in the chain of cp commands
(add an additional "&& cp README.md packages/typescript/ai-nebius/README.md" in
the appropriate position) so the root README is copied into the new package
during the build.

"changeset": "changeset",
"changeset:publish": "changeset publish",
"changeset:version": "changeset version && pnpm install --no-frozen-lockfile && pnpm format"
Expand Down
12 changes: 12 additions & 0 deletions packages/typescript/ai-nebius/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# @tanstack/ai-nebius

## 0.2.0

### Minor Changes

- Initial release of Nebius Token Factory adapter for TanStack AI
- Text/chat adapter with streaming support
- Summarization adapter
- Tool/function calling support
- OpenAI-compatible API using `https://api.tokenfactory.nebius.com/v1/`
- Support for DeepSeek, Llama, Qwen models
25 changes: 25 additions & 0 deletions packages/typescript/ai-nebius/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# @tanstack/ai-nebius

Nebius Token Factory adapter for TanStack AI.

## Installation

```bash
npm install @tanstack/ai-nebius
```

## Usage

```typescript
import { chat } from '@tanstack/ai'
import { nebiusText } from '@tanstack/ai-nebius'

const stream = chat({
adapter: nebiusText('deepseek-ai/DeepSeek-R1-0528'),
messages: [{ role: 'user', content: 'Hello!' }],
})
```

## Documentation

See the [Nebius Token Factory adapter documentation](../../../docs/adapters/nebius.md) for full details.
Loading
Loading