You will then install the model provider of your choice.
npm install @ai-sdk/openai
@/index.ts (Node.js Runtime)
import { generateText } from'ai';import { openai } from'@ai-sdk/openai'; // Ensure OPENAI_API_KEY environment variable is setasyncfunctionmain() {const { text } =awaitgenerateText({ model:openai('gpt-4-turbo'), system:'You are a friendly assistant!', prompt:'Why is the sky blue?', });console.log(text);}main();
AI SDK UI
The AI SDK UI module provides a set of hooks that help you build chatbots and generative user interfaces. These hooks are framework agnostic, so they can be used in Next.js, React, Svelte, Vue, and SolidJS.
We've built templates that include AI SDK integrations for different use cases, providers, and frameworks. You can use these templates to get started with your AI-powered application.