You built a demo: a page with one text box that turns rough notes into a polished customer announcement, wired to a real model. You deploy it to a public address on a hosting service, so anyone with the link can open it, and move on. Twelve days later the model provider emails about unusual activity, and its usage dashboard shows tens of thousands of requests you never sent, still climbing while you watch. The engineer you ask for help does not open the dashboard. She opens your demo page, chooses View Source (the browser command that shows a page's code), and points at one line in the code every visitor's browser downloaded: your API key, readable by anyone who looked. Strangers sent those requests, and your account pays for them.
Frontend, what users see ended with the warning you ignored in that scene: frontend code is sent to every user's device, so anything inside it is public. In this chapter you see the line of code behind that bill, a version that cannot leak the key, and a test for which features belong on the half of the app users never see.
The exposed key, printed in full
Here are the two lines that matter in that demo page, as every browser received them. They are close to what an AI tool writes for a page that calls the model directly:
const KEY = "sk-ant-api03-8f3ab61c29d47e05";
sendToModel(KEY, userText);
An API key, from The journey of a request, is the secret string that tells a model provider whose account to bill; it works like a membership card. This one sits in plain text inside a page that is sent whole to every browser, because a browser cannot run code it has not received. The DevTools panel from the journey of a request shows the key going out with every request, and a stranger can copy the string between the quotation marks in under a minute. None of this is hacking: strangers are reading what you sent them. Once they copy the key, their requests are billed to your account, and automated scrapers, programs that read public web pages in bulk, search for exactly this mistake.
The version where the key stays on your server
You cannot hide the key anywhere inside the page, so the fix is a second computer. The page sends the user's text to a machine you control, and the key stays on that machine: your server's code reads it from a secret setting (an environment variable, from The Software Map), and no visitor ever downloads that code.
// in the page, delivered to every browser: no key anywhere
sendToMyServer(userText);
// on your server, in code no visitor ever receives
const KEY = readSecret("MODEL_KEY");
sendToModel(KEY, userText);
Every request now makes the two trips from The journey of a request: the frontend sends the input to your server, your server attaches the key and calls the model, and the response comes back through your server to the screen. The key travels only on the second trip, between machines you and the provider control, and never on a device you do not control.
In the drawing, the key in the browser is crossed out, because anyone can read what is sent to a browser. On your server the key sits in a locked box, and your server is the only machine that sends requests to the model API, the way the provider lets programs send requests to its models.
Three jobs only a server can do
Keeping secrets is the first of three jobs that a user's device cannot do and a server can.
Keeping secrets. You have just seen this job go wrong, and the fix: anything that must stay hidden can only live on a machine you control.
Holding what users share. Your phone can store your own photos, but it cannot hold everyone's photos and let each of you see the others'. Anything that must look the same to every user, such as the feed, the booking calendar, or the account balance, has to live in one place every device can reach. The backend is that shared place: it keeps the shared records in storage that only the backend can reach. Data, where information lives covers that storage.
Doing heavy work. Some jobs need more memory and processing than a phone has: searching millions of records, processing video, running the largest AI models. That last job runs on racks of GPUs: tall frames of stacked machines full of GPUs, specialized chips built for the huge amount of arithmetic a large model needs.
The backend is the software that runs on a server and does work in response to requests from frontends: it keeps secrets, holds what users share, and does heavy work.
Those three jobs also give you a test you will use all the time. When an AI tool asks where some logic (the code that works out what happens) should run, or proposes an architecture (a plan for where each piece of the app runs), ask three questions in order: does this need a secret, shared records, or heavy work?
In the drawing, a yes at any of the three tests sends the feature down to the BACKEND card. Three nos send it to the CLIENT card, which means it stays on the user's device.
Ask whether a feature needs a secret, shared records, or heavy work. If any answer is yes, put the logic on the backend; if all three answers are no, the feature can stay on the device.
The obvious objection: your phone already runs AI
The phone in your pocket now runs real AI without a server. Recent phones come with small built-in models that summarize notifications and tidy voice notes with the network off; you can see them work in airplane mode. So why send every AI feature through a server?
The models an app pays a provider to use are very different from the models built into a phone. On-device models are small by design, while the models that apps build on are orders of magnitude larger (each order of magnitude is a factor of ten) and run on those racks of GPUs. And even if a provider's model fit on the phone, the phone would need your key to use it, because the provider would still need to know whose account to bill, and that means writing the key back into code you deliver to every user. When a small on-device model really is enough for a feature, the three tests show it: every answer is no.
One AI feature, traced end to end
Duolingo's Explain My Answer feature, free to every learner since January 2026, uses this same route in a consumer app used at large scale. Miss an exercise and tap the button, and the app does not produce the explanation itself. It packages the exercise and your answer into a request to Duolingo's servers, which attach Duolingo's own credentials (the proof of which account pays the model provider), call an AI model, and send back an explanation of why your answer was wrong, kept within limits Duolingo sets.
Run the three tests, and the answer to all three is yes.
- Secret? Yes. The model credentials belong to Duolingo, and no learner's phone ever holds them.
- Shared? Yes. Course content and progress live in Duolingo's storage, which is why they follow you to a new phone.
- Heavy? Yes. The model that produces the explanation runs on a provider's racks, well past what the phone's built-in models can handle.
The phone sends the request and shows the result, while the server holds the key, calls the model, and keeps what comes back within set limits.
When you may not need a backend at all
If the three tests give a no for every feature of your idea, skip the backend entirely. A unit converter, a metronome, and a journaling app that keeps entries on the device are real, useful, and complete apps with no server behind them. Frontend-only apps ship faster and have fewer parts that can break while you sleep.
You may be tempted to build a backend anyway, for the accounts you might add later. Wait until a feature actually gets a yes on one of the three tests: adding a backend when a feature needs one is routine work, while running one you never needed is a cost you keep paying. Three nos for every feature is one of the best results a build can get, and you come back to this decision in Decide what goes in your first version when you scope your own website or app.
Try it now
This drill takes about ten minutes, and you spend nothing on either path.
No setup: Pick one feature of an app you used today, such as the like button in a social app or the AI summary in your meeting tool. Run the three tests and write one sentence saying where its logic must run and which test's answer put it there, for example "likes must be shared across users, so the count lives on the backend." That is the level of detail you need when you discuss architecture with a builder or a tool. If every answer is no, check your answer by using the feature in airplane mode.
With your tools: Open Claude Code, give it the idea from your idea file, and ask what would have to live on a server if the idea had one AI feature, sorted into secrets, shared records, and heavy work. The list it gives you is your backend inventory, the things your server would hold or do, and in the next chapters you learn the words for every item on it. In Codex or Cursor the move is the same: describe the idea and ask what a server would need to hold and why. If nothing is installed yet, the Setup Clinic gets you running.
Either way, add to the idea file. Run the three tests on the idea you have been considering and add the three answers, plus the backend inventory if you took the tooled path, to the idea file from Decode the technical questions that stop you. When you pick your first real build, those lines say whether it needs a server on day one.
Chapter Summary
- The backend is the software that runs on a server and does work in response to requests from frontends.
- An API key is the credential that tells a model provider whose account to bill, and a key placed in frontend code is delivered to everyone who loads the page.
- Reading the code a page delivers is not hacking, and automated scrapers search the web for exposed keys, so an exposed key leads to strangers spending money on your account.
- The safe route is the two trips: the frontend sends the input to your server, the server attaches the key and calls the model, and the answer comes back through your server. The key travels only on the second trip, from your server to the provider.
- A feature belongs on the backend when it needs something the user's device cannot provide: keeping secrets, holding what users share, or doing heavy work.
- Run the three tests (secret, shared, heavy) in order on every feature. If any answer is yes, put the logic on the server; if all three are no, it can stay on the device.
- Phones now run small AI models offline, but the models an app pays a provider for run on the provider's racks of GPUs, and your key must never be sent inside your pages anyway.
- Hiding the key is only half the job. An endpoint with no sign-in and no rate limit still lets strangers spend your budget, so decide who may call it and how often before it goes live.
- When every answer is no, shipping with no backend is a good result, and you can add a server later if a feature actually needs one.
- Next up is APIs, how systems talk to each other, which covers how one system sends requests to another in an agreed form.
Sources
- Duolingo blog and help center, the Explain My Answer feature, free for all users since January 2026 (last verified July 2026).
- OpenAI help center, best practices for API key safety (last verified July 2026).
- Anthropic API documentation, API key management (last verified July 2026).