AI

AI Setup

Easily configure and resolve AI models in VitNode using the native Vercel AI SDK.

// Image prompt: Modern minimalist illustration showing a sleek AI node connecting various LLM providers (OpenAI, Anthropic, Google) to a server core with glowing energy paths, dark UI theme.

VitNode brings AI powers straight into your backend via the built-in Vercel AI SDK. Configure your models once in buildApiConfig, grab them in any route handler using c.get("ai"), and call native AI SDK functions directly. Zero wrappers, zero hassle! 🚀

AI is completely optional — if you don't configure any models, VitNode won't touch any external services.

Quick Setup

Install AI SDK

Add ai (and optionally a provider package like @ai-sdk/anthropic) to your app or plugin:

# AI Gateway: use one key for Anthropic, OpenAI, Google & more!
pnpm i ai
# Talk directly to a provider with their dedicated SDK
pnpm i ai @ai-sdk/anthropic

Add API Key

Add your secret API key to .env:

.env
# AI Gateway (Recommended)
AI_GATEWAY_API_KEY=your_ai_gateway_api_key

# Or provider key (e.g., Anthropic)
# ANTHROPIC_API_KEY=your_anthropic_api_key

Configure Models

Define your model registry in buildApiConfig. The first model listed acts as the default!

src/vitnode.api.config.ts
export const vitNodeApiConfig = buildApiConfig({
  ai: {
    models: [
      { id: "default", name: "Claude Sonnet 5", model: "anthropic/claude-sonnet-5" },
      { id: "fast", name: "Claude Haiku 4.5", model: "anthropic/claude-haiku-4.5" },
    ],
    embeddingModels: [
      { id: "default", name: "Text Embedding 3 Small", model: "openai/text-embedding-3-small" },
    ],
    imageModels: [
      { id: "default", name: "GPT Image 1", model: "openai/gpt-image-1" },
    ],
  },
});
src/vitnode.api.config.ts
import { anthropic } from "@ai-sdk/anthropic";

export const vitNodeApiConfig = buildApiConfig({
  ai: {
    models: [
      { id: "default", name: "Claude Sonnet 5", model: anthropic("claude-sonnet-5") },
      { id: "fast", name: "Claude Haiku 4.5", model: anthropic("claude-haiku-4.5") },
    ],
  },
});

Model Options

Prop

Type

Ready to generate text or create embeddings? Check out the Usage guide!

On this page