1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
17 small wins to finish your pathNext lesson →
Installation and setup
The AI SDK comes from npm as a core package plus one package per model provider. Groq and Google each have a provider package and a free key.
ai, zod, @ai-sdk/openai and tsx
This course needs Node.js 20 or later. zod describes schemas for tools and typed output, @ai-sdk/openai is the OpenAI provider, and tsx runs a TypeScript file directly: every lesson is a file run with npx tsx file.ts.
node --version
npm install ai zod @ai-sdk/openai
npm install --save-dev tsxA provider package for a free modelOptional
The course uses a stand-in model from lesson 4, so no key is needed to follow along. A real model means installing its provider package and setting the variable it reads; lesson 3 shows the error when that variable is missing.
npm install @ai-sdk/groq| Provider | Key | Variable | Package and model |
|---|---|---|---|
| Groq | Free, console.groq.com/keys | GROQ_API_KEY | @ai-sdk/groq, groq("openai/gpt-oss-120b") |
| Gemini | Free, aistudio.google.com/apikey | GOOGLE_GENERATIVE_AI_API_KEY | @ai-sdk/google, google("gemini-2.5-flash") |
| OpenRouter | Free models end in :free, openrouter.ai/keys | OPENROUTER_API_KEY | @openrouter/ai-sdk-provider, openrouter("google/gemma-4-31b-it:free") |
| OpenAI | Paid, platform.openai.com/api-keys | OPENAI_API_KEY | @ai-sdk/openai, openai("gpt-4.1-mini") |
export GROQ_API_KEY=gsk_...import { generateText } from "ai";
import { groq } from "@ai-sdk/groq";
const { text } = await generateText({
model: groq("openai/gpt-oss-120b"),
prompt: "Say hello",
});
console.log(text);Next.js loads .env.local for you and keeps it out of git; a plain script needs the variable exported first.
Try it yourself
- Run
npm ls aiand check the installed version.
Little by little, you're building something great.