Skip to main content
@repo/ai connects your app to multiple AI providers through the Vercel AI SDK and AI Gateway. It includes model routing, agent creation, prompt management, and cost tracking.

Usage

Create a chat agent with tools:
packages/ai/agent/chat.ts
import { createChatAgent, tool, z } from "@repo/ai/agent";

const agent = createChatAgent({ token }, {
  weather: tool({
    description: "Get the weather for a location",
    parameters: z.object({ city: z.string() }),
    execute: async ({ city }) => `72°F in ${city}`,
  }),
});

Gateway

The gateway routes requests to Anthropic, OpenAI, Google, and other providers through a single API:
packages/ai/gateway/index.ts
import { gateway } from "@repo/ai/gateway";
import { generateText } from "ai";

const { text } = await generateText({
  model: gateway("anthropic/claude-sonnet-4.6"),
  prompt: "Explain monorepos in one sentence.",
});

Models

Pre-configured model constants and provider options:
packages/ai/models/index.ts
import { CLAUDE_SONNET, GEMINI_FLASH, CHAT_MODELS } from "@repo/ai/models";
Available models include Claude Sonnet 4.6, Claude Haiku 4.5, GPT-4o, GPT-4o Mini, Gemini 3 Flash, and Gemini 3 Pro. Each model has thinking/reasoning options pre-configured for its provider.

Prompts

Shared system prompts for chat and title generation:
packages/backend/convex/chat/api/title.ts
import { SYSTEM_PROMPT } from "@repo/ai/prompts";
import { generateChatTitle } from "@repo/ai/prompts/title";

const title = await generateChatTitle("How do I deploy to Vercel?");
Add Perplexity-powered web search as a tool (requires PERPLEXITY_API_KEY):
packages/ai/tools/search.ts
import { getSearchTool } from "@repo/ai/tools/search";

const search = getSearchTool();

Environment Variables

VariableDescription
AI_GATEWAY_API_KEYVercel AI Gateway API key
AI_GATEWAY_URLGateway endpoint (defaults to https://ai-gateway.vercel.sh/v3)
PERPLEXITY_API_KEYPerplexity API key for web search (optional)

Learn More