How to fix: LLM API Called Directly From Client-Side Code
A client-side script calls the OpenAI or Anthropic API directly via fetch(), instead of proxying the request through a backend endpoint.
Why it matters
Calling the provider API from the browser requires embedding the API key in client-side code, where it is trivially extractable by anyone who views the page source, leading to quota theft and unexpected billing.
AI-scaffolded prototypes frequently start with a direct browser-to-provider fetch() call because it's the fastest way to get a demo working, and that call (and the embedded key) ships unchanged to production.
How to fix it
- 1Move the LLM API call to a backend route; the client should call your own API, never the provider's API directly.
- 2Revoke and reissue any API key that has been exposed in shipped client code.
- 3Add rate limiting and per-user quotas on your backend proxy endpoint.
Code examples
Proxy through your own backend
// Client
await fetch('/api/chat', { method: 'POST', body: JSON.stringify({ message }) });
// Server (app/api/chat/route.ts): the API key lives only here
const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });References
Detected automatically by VulnRadar. The check id is vibe-llm-api-called-from-client, stable across every scan so you can filter or diff on it.
More ai code checks
- LowGeneric Error Messages Leak No Context
- MediumTODO/FIXME Security Note in Response
- Higheval() Usage in Page Scripts
- HighSSL Certificate Verification Disabled
- HighMath.random() Used for Security Tokens
- CriticalHardcoded Credential in Authentication Logic
- CriticalJWT 'none' Algorithm Accepted
- CriticalSQL String Concatenation Pattern Detected
Questions
- How severe is LLM API Called Directly From Client-Side Code?
- VulnRadar rates this high severity in the ai code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id vibe-llm-api-called-from-client, which stays the same between runs so you can filter, diff, or gate CI on it.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.