Module 84: AI APIs

Lesson 2 of 5 · 15–25 minutes

Keys

🏠The everyday picture

A company credit card with no limit, handed to a stranger, is a disaster. API keys are exactly that: anyone holding yours can spend your money.

📘What it really is

🖱️Try it

Create an Express route POST /v1/assistant/ask in your backend that requires login, accepts { question } (validated with Zod: a string of at most 2,000 characters), calls the model with your system prompt, and returns the answer. Add a per-user rate limit (for example, 20 a minute). Confirm the key exists only in your backend's environment, and that the frontend has no trace of it.

✅Quick check

Why must the browser never call the AI API directly with your key?

Show the answer

Anyone could read the key from the frontend and use it at your expense.

Why rate-limit the assistant route per user?

Show the answer

Every request costs money, and one user (or attacker) could otherwise run up a large bill.

← PreviousHow AI APIs work
ProLearners Assist