HomeFoundationsWhat is an API?
beginner8 min read· Module 1, Lesson 6

🔌What is an API?

The bridge between your code and Claude — explained simply

What is an API?

Think of an API as a waiter in a restaurant:

  1. You (the customer) look at the menu and decide what you want
  2. The waiter (API) takes your order to the kitchen
  3. The kitchen (Claude's servers) prepares your food
  4. The waiter (API) brings your food back to you

You never go into the kitchen yourself. The waiter handles all communication between you and the kitchen. That's exactly what an API does — it's the middleman between your code and Claude.

How it Works in Practice

Your Code → sends a request → Claude's API → Claude processes it → sends response back → Your Code

What's in an API Request?

When you talk to Claude's API, you send a structured message with these parts:

PartWhat It IsExample
ModelWhich Claude to useclaude-opus-4-7
MessagesWhat you want to say/ask"Explain APIs to me"
Max TokensMaximum length of response1024
API KeyYour unique passwordsk-ant-api03-...

What's in an API Response?

Claude sends back a structured response:

JSON
{ "content": [ { "type": "text", "text": "An API is like a waiter..." } ], "model": "claude-opus-4-7", "usage": { "input_tokens": 12, "output_tokens": 150 } }

What Are Tokens?

Tokens are how AI measures text. A token is roughly:

  • 1 token ≈ ¾ of a word (English)
  • "Hello, world!" = ~3 tokens
  • 100 tokens ≈ 75 words
  • 1000 tokens ≈ 750 words

Why does this matter? You pay based on tokens used:

  • Input tokens — what you send to Claude
  • Output tokens — what Claude sends back
  • Output tokens cost more than input tokens

Your API Key — Your Secret Password

An API Key is like a password that identifies you:

  • It looks like: sk-ant-api03-abcdef123456...
  • You get it from the Anthropic Console (we'll set this up next)
  • NEVER share it — anyone with your key can use your account
  • NEVER put it in your code — use environment variables

REST API Basics

Claude uses a REST API, which means:

  • Communication happens over HTTPS (secure internet)
  • You send HTTP requests (like visiting a website, but from code)
  • Data is formatted as JSON (a way to structure data)

Don't worry if these terms are new — we'll learn by doing in the next lessons!

Next up: We'll set up your development environment and get your API key.