APIs & Keys
Every AI API works the same way: send a request, get a response. The details change, the pattern doesn't. Store API keys securely using environment variables and .env files. Make an LLM API call using both the Anthropic Python SDK and raw HTTP. Compare SDK-based and raw HTTP request/response formats for debugging. Identify and handle common API errors including authentication and rate limits. Starting from Phase 11, you'll call LLM APIs (Anthropic, OpenAI, Google). In Phase 13-16 you'll build agents that use these APIs in loops. You need to know how API keys work, how to store them safely, and how to make your first API call. Every API call has: An endpoint (URL). An API key (authentication). A request body (what you want). A response body (what you get back). Never put API keys in code. Use environment variables. Or use a .env file (add it to .gitignore): LLMMODEL selects the Anthropic model id, and the default is the un-dated Sonnet alias. Other providers (OpenAI, Google, and others) follow the same pattern of a key plus a model id, but each has its own SDK, endpoint, and request/response schema. This is what the SDKs do under the hood. Understanding the raw HTTP call helps when debugging. For this course: You don't need all of them right now. Set them…
APIs & Keys: Every AI API works the same way: send a request, get a response. The details change, the pattern doesn't. Store API keys securely using…
This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.
Browse the complete course catalog or open this lesson on GitHub.