Course contentsShow
← AI Engineering
Lesson 1478 of 1,88636. Security in AI SystemsFree lesson

Client-Side vs Server-Side Keys

Understanding when to use server-side API keys versus client-facing credentials and proxy patterns.

Client-Side vs Server-Side Keys

What you'll learn: Where API keys should live—and why exposing them in the browser can be catastrophic for AI applications.

The Front Door vs Back Door Problem

Think of your AI application like a building with two entrances. The client-side (browser, mobile app) is your public-facing front door—anyone can walk through and inspect everything. The server-side (your backend) is the restricted back office where sensitive operations happen.

Client-Side Keys: The Danger Zone

When you embed API keys directly in client-side code—whether in JavaScript, mobile apps, or any user-facing interface—you're essentially publishing them publicly. Anyone can:

  • Open browser DevTools and extract your keys
  • Decompile mobile apps to find hardcoded credentials
  • Use your keys to rack up unlimited API costs
  • Access your AI models without restriction

Never put production API keys in client-side code. Even obfuscation or "hiding" them in compiled code doesn't work—determined users will find them.

Server-Side Keys: The Secure Pattern

The correct approach: keep API keys on your server and use a proxy pattern. Your client calls your backend endpoint, which then authenticates the request, applies rate limiting, and forwards legitimate requests to the AI service using the secret key.

User → Your API (authenticated) → AI Service (with secret key)

This architecture lets you:

  • Control who accesses your AI services
  • Monitor and limit usage per user
  • Rotate keys without updating client code
  • Apply additional security layers (scoping, filtering)

Public vs Private Keys

Some services offer read-only or restricted "publishable keys" for client-side use. These are safe for browsers but have limited capabilities. Always reserve full-privilege keys for server-side use only.

Key Takeaway: Client-side code is inherently public—never trust it with powerful API keys. Use server-side proxies to protect credentials and maintain control over AI service access.