Skip to content
agenoverse
Workflows

Set up your workspace and make your first call

Install what you need, keep your API key out of your code, and send a first message to a model from your own machine. About twenty minutes, and every later lesson builds on it.

Lesson 2 of 5Build your first AI agent

Updated

Reviewed

  • Level: Beginner
  • 25 min to complete

// Before you start

This guide builds on this one:

Nothing here is clever, which is the point. You are building a small, reliable base: the right tools installed, a secret kept safe, and one successful call to a model.

Install Node.js#

The examples use TypeScript. Install Node.js 20 or newer, then check the version in a new terminal window.

bash
winget install OpenJS.NodeJS.LTS# close the terminal, open a new one, then:node --version

Note

Prefer Python? Lesson 3 has every example in both languages. Everything else, including this setup, works the same.

Get an API key and keep it out of your code#

Create an account with a model provider and make an API key. This path uses the Anthropic API; the ideas work with any provider. A key is a password that costs you money if it leaks, so it never goes in a file you might share or commit.

Put it in an environment variable instead. Your code reads it from there, and the SDK looks for the name ANTHROPIC_API_KEY automatically.

bash
# PowerShell. Lasts for this window only:$env:ANTHROPIC_API_KEY = "paste-your-key-here"# Or save it for every new window:setx ANTHROPIC_API_KEY "paste-your-key-here"

Heads up

If you ever paste a key into a chat, a screenshot or a public repository, treat it as leaked: delete it in the provider's dashboard and make a new one. Do it straight away, not later.

Create the project#

bash
mkdir notes-agent && cd notes-agentnpm init -ynpm pkg set type=modulenpm install @anthropic-ai/sdknpm install -D tsx typescript @types/node

Make your first call#

Create a file called hello.ts and paste this in. It sends one message and prints the reply.

hello.ts
import Anthropic from '@anthropic-ai/sdk'const client = new Anthropic() // reads ANTHROPIC_API_KEY from your environmentconst reply = await client.messages.create({  model: 'claude-sonnet-5-5',  max_tokens: 200,  messages: [{ role: 'user', content: 'Say hello in five words.' }],})const block = reply.content[0]console.log(block.type === 'text' ? block.text : block)

Run it with npx tsx hello.ts. If you see five friendly words, your setup works and you can stop worrying about it for the rest of the path.

Note

Model names change over time. If you get a "model not found" error, check the provider's current model list and swap the name in the code. Nothing else needs to change.

// Try it

Break it on purpose

Errors are much less scary when you have seen them before. Make this one happen deliberately:

  1. Open a new terminal window, so the key you set earlier is gone.
  2. Run npx tsx hello.ts again.
  3. Read the error message. What is it telling you, in your own words?
Show a solution

You should see an authentication error: the SDK could not find an API key, so the provider refused the request. Nothing is wrong with your code.

Fix it by setting ANTHROPIC_API_KEY again in that window (or use setx / your shell profile so every new window has it). Remember that a variable set with setx only appears in windows opened afterwards.

Before you move on#

Your setup, done

Was this guide helpful?

These guides stay current because readers tell us what is off. One tap is plenty.