Skip to content
Dashboard

How to build scalable AI applications

Sr. Content Engineer

Best practices for infrastructure, data, and development.

Link to headingChoosing the right provider

Link to headingBuilding for the future of AI

import { generateText } from "ai";
import { anthropic } from "@ai-sdk/anthropic";
const { text } = await generateText({
model: anthropic("claude-3-5-sonnet-20240620"),
prompt: "What is the best way to architect an AI application?",
});

Link to headingThird-party, fine-tuning, or in-house models

Link to headingData cleansing and management

Preparing data for AI isn’t a straight shot—it’s a cycle of refinement.Preparing data for AI isn’t a straight shot—it’s a cycle of refinement.Preparing data for AI isn’t a straight shot—it’s a cycle of refinement.Preparing data for AI isn’t a straight shot—it’s a cycle of refinement.
Preparing data for AI isn’t a straight shot—it’s a cycle of refinement.

Link to headingRetrieval-augmented generation (RAG) techniques

Link to headingSimplified implementation with Vercel

The quickest way to build and secure AI features.

There’s no need to wait for your current platform to catch up. Build intelligent, user-centric applications that deliver exceptional experiences.

Get Started

Link to headingChoosing the right infrastructure

Vercel serves as the intersection between AI, your backend data, and your user-facing frontend.Vercel serves as the intersection between AI, your backend data, and your user-facing frontend.Vercel serves as the intersection between AI, your backend data, and your user-facing frontend.Vercel serves as the intersection between AI, your backend data, and your user-facing frontend.
Vercel serves as the intersection between AI, your backend data, and your user-facing frontend.

Link to headingOptimizing AI application performance

Link to headingStreaming

app/ai/route.ts
import { openai } from "@ai-sdk/openai";
import { convertToCoreMessages, streamText } from "ai";
// Allow streaming responses up to 30 seconds
export const maxDuration = 30;
export async function POST(req: Request) {
// Extract the `messages` from the body of the request
const { messages } = await req.json();
// Call the language model
const result = await streamText({
model: openai("gpt-4o"),
messages: convertToCoreMessages(messages),
});
// Respond with the stream
return result.toDataStreamResponse();
}

Link to headingCaching

app/cached-ai/route.ts
import { openai } from "@ai-sdk/openai";
import { convertToCoreMessages, formatStreamPart, streamText } from "ai";
import kv from "@vercel/kv";
// Allow streaming responses up to 30 seconds
export const maxDuration = 30;
// simple cache implementation, use Vercel KV or a similar service for production
const cache = new Map<string, string>();
export async function POST(req: Request) {
const { messages } = await req.json();
// come up with a key based on the request:
const key = JSON.stringify(messages);
// Check if we have a cached response
const cached = await kv.get(key);
if (cached != null) {
return new Response(formatStreamPart("text", cached), {
status: 200,
headers: { "Content-Type": "text/plain" },
});
}
// Call the language model:
const result = await streamText({
model: openai("gpt-4o"),
messages: convertToCoreMessages(messages),
async onFinish({ text }) {
// Cache the response text:
await kv.set(key, text);
await kv.expire(key, 60 * 60);
},
});
// Respond with the stream
return result.toDataStreamResponse();
}

Link to headingWhat will your AI journey look like?

Bring any questions.

Our AI engineers can answer your migration or complex infrastructure questions and recommend best practices for your AI app at scale.

Contact Us