Joel Stevick

Introduction · section 6 of 8

What you need before Chapter 1

Four things, none of which takes long, and one more that can wait.

1. Node.js 20 or newer, and npm. Check with node --version; if it prints something starting with v20. or higher, you have what the examples need. The examples use TypeScript throughout and are run with tsx, which compiles and runs a .ts file in one step with no build directory to manage.

2. An Anthropic account and an API key. An API key is a secret string that identifies your account to Anthropic’s servers. Create one at console.anthropic.com under API Keys. It begins with sk-ant- and it is shown to you exactly once, so copy it somewhere safe immediately.

Put it in your shell environment rather than in a file you might commit:

export ANTHROPIC_API_KEY="sk-ant-..."

While you are in the console, set a spending limit under Billing. Working through every chapter and re-running the examples a few times each costs a few dollars rather than a few hundred; five dollars is comfortably more than enough. Chapter 11 runs twelve questions through the whole pipeline at once and says what that costs before you run it.

Warning: A key committed to a public repository is found and used by automated scanners within minutes, and you are billed for what they do with it. Never write the key into a source file, not even temporarily. Every example ahead reads the key from the environment for that reason.

3. A project directory. Everything you build lives in one folder:

mkdir ask-pipeline && cd ask-pipeline
npm init -y
npm install @anthropic-ai/sdk
npm install --save-dev typescript tsx @types/node

Anthropic publishes an SDK, a software development kit, as @anthropic-ai/sdk: a library wrapping its HTTP interface in ordinary TypeScript functions. Chapter 1 walks through each field of the first call one at a time.

Then replace the generated package.json with this one.

Listing: package.json

{
  "name": "ask-pipeline",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "tsx --test ask/*.test.ts",
    "typecheck": "tsc --noEmit"
  },
  "dependencies": {
    "@anthropic-ai/sdk": "^0.124.0"
  },
  "devDependencies": {
    "@types/node": "^20.14.0",
    "tsx": "^4.16.0",
    "typescript": "^5.5.0"
  }
}

Then run npm install once more, and add a TypeScript configuration beside it.

Listing: tsconfig.json

{
  "compilerOptions": {
    "target": "ES2022",
    "lib": ["ES2022"],
    "module": "nodenext",
    "moduleResolution": "nodenext",
    "types": ["node"],
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "noEmit": true
  },
  "include": ["ask/**/*.ts"]
}

4. Somewhere to put it. Run git init in that directory now, and add one file before you commit anything, or every later diff arrives buried in node_modules/.

Listing: .gitignore

node_modules/

5. A Cloudflare account, when you reach Chapter 5. That chapter finds laws by meaning, which needs a model that turns text into numbers, and the one the deployed pipeline uses runs on Cloudflare’s Workers AI. A free account is enough. Without one, the stage does not exist, the pipeline finds laws by their words alone, and every chapter after 5 still runs: that is the rule Chapter 10 is about, met one chapter early.