Anti-patternCodingIntermediate · 10 min

Exposing API keys in client-side code

Never embed your API key directly in browser or mobile application code.

Any modelParaphrased
Instead
Use ephemeral tokens obtained from a secure server endpoint for client-side API authentication.
Mistake

Including your main API key directly within client-side JavaScript or mobile application code.

Why

Exposing API keys in client-side code makes them vulnerable to theft and misuse, as this code is publicly accessible. Ephemeral tokens provide a more secure, temporary, and scoped alternative.

What it does and when to use it

Avoid embedding API keys in client-side code. Instead, use ephemeral tokens fetched from a server endpoint to maintain security for browser and mobile applications.

Why it works

Client-side code is inherently insecure as it can be inspected by users. API keys embedded here are easily compromised. Ephemeral tokens, generated server-side and with limited scope and duration, mitigate this risk.

When not to use it

This is always an anti-pattern for client-side code.

Sources and credit

First seen on Subvolts Jul 20, 2026. Updated Sep 11, 2026. Spotted a problem? Tell us.

Where it shows up
Related in the PlaybookPlaybook →

The Playbook: reusable how-tos, prompts, configs and tips pulled out of the news.

Questions people ask

Which AI tools does this work with?
Any current model. It was seen with in the sources.
Where did this come from?
xAI (xAI Docs: Guides). Subvolts collected, normalized and credited it; the link above opens the original.