---
title: "Chapter 01: Environment Setup"
description: "Install mise, bun, and get your OpenRouter API key. The foundation for everything."
type: lesson
order: 1
chapter: "01-setup"
---

# Chapter 01: Environment Setup

## What We're Doing

We're setting up a reproducible development environment using `mise` (a version manager), `bun` (a fast TypeScript runtime), and getting an API key for OpenRouter so we can talk to LLMs.

## Step 1: Install mise

[mise](https://mise.jdx.dev/getting-started.html) manages your development environment. It's like `asdf` or `nvm` but faster and simpler.

Open a terminal and run:

```bash
curl https://mise.run | sh
```

You may need to restart your terminal afterward. Verify it's working:

```bash
mise --version
```

## Step 2: Install bun

With mise installed, getting bun is a single command:

```bash
mise use bun
```

This installs the latest version of bun and makes it available in your shell. Verify:

```bash
bun --version
```

## Step 3: Get an OpenRouter API Key

[OpenRouter](https://openrouter.ai/) is an API gateway that gives you access to hundreds of models through a single API key. Instead of managing separate keys for Anthropic, Google, and OpenAI, you have one key that routes to all of them.

1. Go to [openrouter.ai/settings/keys](https://openrouter.ai/settings/keys)
2. Create an account
3. Add a credit card if required (you'll spend maybe $1–5 for this entire tutorial)
4. Create a new API key

Save the key in a `.env` file in your project directory:

```bash
echo 'OPENROUTER_API_KEY=sk-or-v1-your-key-here' > .env
```

**Never commit `.env` to git.** Make sure it's in your `.gitignore`.

## Step 4: Choose Your Model

Set the model you want to use:

```bash
echo 'AGENT_MODEL=google/gemini-3-pro-preview' >> .env
```

Alternative: if you prefer Claude, use `anthropic/claude-opus-4.5`.

As of this writing, Gemini 3 Pro Preview and Opus 4.5 work best for this tutorial. But feel free to experiment — one of the benefits of OpenRouter is that swapping models is just changing an environment variable.

## Step 5: Create mise.toml

Create a `mise.toml` to lock in your tool versions:

```toml
[tools]
bun = "latest"
```

## Step 6: Create a Project Directory

```bash
mkdir weekend-coding-agent
cd weekend-coding-agent
```

Copy your `.env` and `mise.toml` into this directory.

## What We Have Now

```
weekend-coding-agent/
├── .env              # OPENROUTER_API_KEY and AGENT_MODEL
├── .gitignore        # includes .env
└── mise.toml         # bun version locked
```

You're ready to write your first agent. Let's go.

---

## The Source Files (for Reference)

The complete project structure is available at `src/`. Here's what we're building toward:

```
src/
├── index.ts           # Entry point with REPL
├── agent.ts           # Core agent loop (runTurn)
├── lib/
│   ├── api.ts         # OpenRouter client, model stats
│   ├── logger.ts      # JSONL session logging
│   ├── readline.ts    # Terminal input handling
│   └── types.ts       # Message, CompletionResponse interfaces
```

But we'll build everything step by step. The agent will help.

---

[← Part 1 Index](/build-ai-coding-agent/01-setup/) · [Next: Chapter 02 →](/build-ai-coding-agent/01-setup/02-bootstrap/)
