Vercel AI SDK

Unlock the Power of AI

Access premium Vercel AI SDK content, tutorials, and tools reserved for our members.

Advanced AI Models

Get exclusive access to our cutting-edge AI models that integrate seamlessly with Vercel's infrastructure.

  • GPT-4 Turbo integration
  • Custom fine-tuned models
  • Multi-modal capabilities
AI

Advanced Prompt Engineering

Learn how to craft effective prompts for optimal AI responses.

45 min

SDK Integration Guide

Step-by-step guide to integrating the Vercel AI SDK in your projects.

1h 15min

Performance Optimization

Techniques to maximize the performance of your AI applications.

30 min

Join Our Exclusive Community

Connect with other developers, share insights, and get direct support from the Vercel AI team.

Premium Content Locked

This content is reserved for Vercel AI SDK members. Sign in or join now to access all features.

import { createOpenRouter } from '@openrouter/ai-sdk-provider'; import { streamText } from 'ai'; import { z } from 'zod'; export const getLasagnaRecipe = async (modelName: string) => { const openrouter = createOpenRouter({ apiKey: '${API_KEY_REF}', }); const response = streamText({ model: openrouter(modelName), prompt: 'Write a vegetarian lasagna recipe for 4 people.', }); await response.consumeStream(); return response.text; }; export const getWeather = async (modelName: string) => { const openrouter = createOpenRouter({ apiKey: '${API_KEY_REF}', }); const response = streamText({ model: openrouter(modelName), prompt: 'What is the weather in San Francisco, CA in Fahrenheit?', tools: { getCurrentWeather: { description: 'Get the current weather in a given location', parameters: z.object({ location: z .string() .describe('The city and state, e.g. San Francisco, CA'), unit: z.enum(['celsius', 'fahrenheit']).optional(), }), execute: async ({ location, unit = 'celsius' }) => { // Mock response for the weather const weatherData = { 'Boston, MA': { celsius: '15°C', fahrenheit: '59°F', }, 'San Francisco, CA': { celsius: '18°C', fahrenheit: '64°F', }, }; const weather = weatherData[location]; if (!weather) { return `Weather data for ${location} is not available.`; } return `The current weather in ${location} is ${weather[unit]}.`; }, }, }, }); await response.consumeStream(); return response.text; };