A key in front-end code
Take your time, follow the code and check your understanding.
The codeLLM API basics
// runs in the browser
fetch("https://api.example-llm.com/v1/chat/completions", {
method: "POST",
headers: { Authorization: "Bearer sk-live-abc123" },
body: JSON.stringify({ model: "m", messages })
});Your answer4 min · no timer
Show solution and explanation
Code that ships to a browser can be inspected, including request headers. Keep provider keys on a server you control and let the browser call that server, with your own limits and authentication.
Anyone who opens developer tools can copy the key. Call your own server, which holds the key.