AI SDK compatible Yandex provider
  • TypeScript 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-02-02 13:56:01 +03:00
.github/workflows Remove publish workflow 2026-01-31 14:37:06 +03:00
src Fix trancsript 2026-02-02 13:56:01 +03:00
.gitignore Add image model 2026-01-31 16:17:45 +03:00
.npmignore Start chat 2026-01-31 00:16:45 +03:00
biome.json Add more actions 2026-01-31 03:04:05 +03:00
bun.lock Fix node internal functions 2026-01-31 03:10:13 +03:00
LICENSE Add licence 2026-01-31 00:26:57 +03:00
package.json Fix trancsript 2026-02-02 13:56:01 +03:00
README.md Add embeddings model 2026-01-31 16:44:38 +03:00
tsconfig.json Use node types in tsconfig 2026-01-31 03:11:24 +03:00

Yandex AI Provider for Vercel's AI SDK

Table of Contents

Installation

npm

npm install yandex-ai

bun

bun add yandex-ai

YandexChatModel

Basic Example

import { YandexChatModel } from "./chat";
import { generateText } from "ai";

const chatModel = new YandexChatModel("yandexgpt-lite", {
  folderId,
  secretKey,
});

const { text } = await generateText({
  model: chatModel,
  prompt: "Hello!",
});

console.log(text);

Agent

import { YandexChatModel } from "./chat";
import { ToolLoopAgent, tool } from "ai";
import type { SharedV3ProviderOptions } from "@ai-sdk/provider";
import { z } from "zod";

const chatModel = new YandexChatModel("yandexgpt-lite", {
  folderId,
  secretKey,
});

const getUserTool = tool({
  description: "Retrieves information about a user",
  inputSchema: z.object({
    userId: z.string(),
  }),
  execute: async ({ userId }) => {
    return {
      id: userId,
      name: "Ivan",
      age: 30,
    };
  },
});

const agent = new ToolLoopAgent({
  model: chatModel,
  tools: {
    getUser: getUserTool,
  },
  instructions: "Respond to users in a friendly manner",
  providerOptions: {
    parallelToolCalls: true,
  } satisfies YandexChatProviderOptions as unknown as SharedV3ProviderOptions,
});

const { text } = await agent.generateText({
  prompt: "Hi! Get me information about the user with id 12345",
});

console.log(text);

Streaming

import { YandexChatModel } from "./chat";
import { streamText } from "ai";

const chatModel = new YandexChatModel("yandexgpt-lite", {
  folderId,
  secretKey,
});

const { textStream } = await streamText({
  model: chatModel,
  prompt: "Hello!",
});

for await (const text of textStream) {
  console.log(text);
}

YandexSpeechModel

export const speechModel = new YandexSpeechModel({
	folderId: folderId,
	secretKey: sk,
});

const generateOptions: YandexSpeechGenerateOptions<"ermil"> = {
	model: speechModel,
	voice: "ermil",
	text: "Привет! Меня зовут Ermil.",
	outputFormat: "mp3",
	instructions: "neutral",
};

const res = await generateSpeech(generateOptions);

await fs.writeFile("test.mp3", res.audio.uint8Array);

YandexImageModel

export const imageModel = new YandexImageModel("yandex-art/latest", {
	folderId: folderId,
	secretKey: sk,
});

const res = await generateImage({
	model: imageModel,
	prompt: "Draw me a cat",
	aspectRatio: "16:9",
});

await fs.writeFile("cat.png", res.image.uint8Array);

YandexEmbeddingModel

export const embeddingModel = new YandexEmbeddingModel(
	"text-search-doc/latest",
	{
		folderId,
		secretKey,
	},
);

const res = await embed({
	model: embeddingModel,
	value: "Hello world!",
});

console.log(res.embedding);