Domdhi logoDOMDHI.OS
BACK_TO_COURSE

How APIs Work

Keys: Who You Are and What You Can Touch

Two Questions, Two Error Codes

Most business APIs ask two things about every request:

  1. Who are you? Get it wrong and you get a 401.
  2. Are you allowed to do this? Get it wrong and you get a 403.

Here's a real one. This site has an API. Ask it for the course list without a key and it says no (response trimmed):

{
  "success": false,
  "error": {
    "code": "UNAUTHORIZED",
    "message": "Missing or malformed Authorization header.",
    "remedy": "Include Authorization: Bearer <key> header in your request."
  }
}

That's a good error. It says what's wrong and how to fix it. Plenty of vendors give you a number and a shrug.

The Two Common Setups

  • API key: one long secret string, sent with every request. Simple. Anyone who has it is you.
  • OAuth: you approve an app, it gets a token that usually expires, and often a second token to get a new one. More moving parts. The common failure is an integration that works today and dies when the token runs out, because nobody built the renewal.

What to Check When AI Builds It

  • The key is not in the code. It lives in an environment variable or a secret store.
  • The key goes in a header, not the web address. Addresses end up in logs.
  • The key can only do the job. A report needs read access. Nothing else.
  • The key never gets printed in logs or error messages.
  • Don't paste a live key into a chat. AI can write the code without it.
WARNING

If a key was ever saved into version control, deleting the line doesn't fix it. The history still has it. Cancel the key and make a new one. GIT 101 explains why history sticks around.

QUIZ

You're building a weekly call report. What access should its key have?

Sign in to track lesson progress and earn a certificate.SIGN IN TO SAVE PROGRESS