#193این ویدیو و متن آن به انگلیسی هستند.
API key safety: why your AI key must never reach the browser
An AI key hidden in your app or website is a key anyone can copy and charge to you. Learn where it belongs and why your own server has to sit in the middle.
با جزئیات
What an API key is
An API key is a long secret code that an AI provider gives you. Your software attaches it to every request it sends to the provider's AI, and the provider uses it for two things: to let the request in, and to charge the cost to your account. In practice, it is a password and a credit card rolled into one.
That is why this concept is a rule with no exceptions: the key never goes to the client. The client is whatever runs on the user's own device, such as your website in their browser or your app on their phone.
What the video shows
The video is about the mistake that puts strangers on your AI bill: shipping the key that unlocks an AI service inside your app or website. The safe version keeps the key on your own server, a computer you control. The user's device asks your server, your server asks the AI, and the answer travels back the same way. And because every request passes through your server, it can also keep track of what each user is spending.
An everyday example
Imagine a company with a taxi account. Reception could tape the account card to the front door so visitors can book their own rides. Within a week, half the street is riding on the company's account. The alternative is to keep the card at the desk. Visitors ask reception, reception books the taxi and notes who went where. Same taxis, same service, but now only the company can use the account, and it knows exactly who spent what.
Your server is the reception desk.
Where keys leak
Anything your website or app sends to the user's device can be opened and read by that user. That covers more places than people expect:
- Settings marked as visible to the browser. Many web tools let you flag a setting as public so the page can read it. A key stored that way is published.
- Values fixed into the code when the app is built. If the key is written into the package of code that visitors download, every visitor gets a copy.
- "Just for now". A temporary shortcut for a demo is still a public key for as long as it is live.
The course is blunt about the result: a key shipped inside that downloadable code ends up on a stranger's bill within days.
Why the server in the middle matters twice
Secrecy is the first reason. The second is accounting. If every user's device talked to the AI provider directly, the provider would see one customer, you, and one growing bill. Your server is the only point that knows which user sent which request, so it is the only place where you can measure what each user spends. Any per-user budget or usage count has to live there.
Why it matters
Adding AI to a product often starts with a quick test that works on the first try. The trouble is that a leaked key also works on the first try, for anyone who finds it. Keeping the key on the server costs one extra step and protects both your bill and your ability to know who is using what.
Learn it step by step in Chapter 14 of our free course AI From Scratch: Your First Production LLM Call: Streaming, Retries, Timeouts.
همچنین در
بیشتر از این فصل
#193
#194Finish reason: telling a finished AI answer from a cut-off one
#195Error triage: which AI errors deserve a retry and which never do
#196Exponential backoff: why a retry should wait twice as long each time
#197Thundering herd: when retrying apps move in lockstep and jam a server
#198Concurrency gate: letting fewer requests in made everything faster
متن با کمک AI و بر اساس فصل 14 از دوره رایگان ما نوشته شده است.