Project Setup: SDKs, Keys, and Your First API Call
Set up a TypeScript project, store your API key safely, and make your first model call — with a Python equivalent for every step.
Every agent you've used so far — Claude Code, ChatGPT, Cursor — is, underneath, a program making API calls to a language model in a loop. In this module you'll write that program yourself, one piece at a time, until you have a real agent that reads and writes files, browses the web, calls APIs, streams its progress, and recovers from errors.
This first lesson gets the foundation right: a clean TypeScript project, an API key stored where it can't leak, and your first successful call to Claude. It's ten minutes of setup that saves you hours of confusing errors later. Every step has a Python equivalent, so you can follow along in either language.
What you're building in this module
Over six lessons you'll grow one project, my-agent, from a single API call into a capable agent. Each lesson extends the code from the previous one, so keep the same folder throughout.
| Lesson | What you add | Main file |
|---|---|---|
| 1. Project setup | A working project and your first model call | src/hello.ts |
| 2. A minimal agent loop | The loop: call model, run tools, repeat | src/agent.ts |
| 3. Adding real tools | Files, web pages, and a weather API | src/tools.ts |
| 4. Streaming and UX | Live output in a terminal and a web page | src/cli.ts, src/server.ts |
| 5. Errors and stop conditions | Retries, tool errors, limits, and budgets | src/agent.ts |
| 6. Using an agent SDK | The same agent, rebuilt on the Claude Agent SDK | src/sdk-agent.ts |
You'll use the Anthropic API directly through its official TypeScript SDK, @anthropic-ai/sdk. If you've read Tools and Function Calling, you already know the concepts. This module turns them into code you own.
You need Node.js 22 or newer (check with node --version); Node 20 reached end of life in April 2026, and the --env-file flag you'll use below needs a modern Node anyway and a terminal. If you set up your toolkit in Setting Up Your Agent Toolkit, you're ready.