The primary risk: Key exposure in client-side applications

The fastest way to build an AI feature is to call the OpenAI SDK directly from the mobile app or browser frontend. However, this pattern is a major vulnerability. Since client-side code is entirely public, any API key embedded in a mobile APK or JavaScript bundle is easily extracted.

Attackers use basic static analysis or proxy interception to capture your sk-... keys. Once they have your key, they can:

We recommend routing all LLM requests through a backend proxy that handles authorization, request sanitization, and rate limits.

Failure example

A production key ships inside a mobile bundle

A key inside a compiled JavaScript asset can be extracted from the application package. Treat the key as exposed, revoke it, inspect its usage, and move all model calls behind an authenticated server route.

Building a secure OpenAI proxy

Instead of calling OpenAI directly from client-side code, implement a secure backend route. The client calls your backend, and your backend forwards the sanitized request to OpenAI.

This allows you to control exactly how the API key is used:

// SECURE: Backend proxy using Express
app.post('/api/chat', async (req, res) => {
  // 1. Verify user session
  if (!req.session.userId) {
    return res.status(401).json({ error: "Unauthorized" });
  }

  // 2. Rate limit requests per user
  const limitReached = await checkRateLimit(req.session.userId);
  if (limitReached) {
    return res.status(429).json({ error: "Too many requests" });
  }

  // 3. Forward request to OpenAI securely
  const response = await openai.chat.completions.create({
    model: "gpt-4o-mini",
    messages: [{ role: "user", content: req.body.message }]
  });

  res.json(response);
});

Restricting OpenAI Project Keys

If you are using OpenAI in production, do not use a single administrator API key. OpenAI supports Project and Organization Keys.

Set up isolated keys for each environment (staging vs production) and assign them limited permissions. For instance, your staging API key should not have the rights to modify training data or delete custom models.

Configure hard billing limits in your OpenAI dashboard. Set up notifications to alert your engineering team if usage spikes unexpectedly.

OpenAI API Security Checklist

To make sure your integration is secure, follow these steps:

  1. No Keys in Frontend Code: Never allow sk-... strings to exist in client-side codebases.
  2. Rotate exposed keys: Revoke a key after any leak, staff change, log exposure, or repository commit.
  3. Validate the request: Enforce allowed models, input size, file type, tool choice, and output limits on the server.

Test the full OpenAI request path

  1. Search every shipped asset. Inspect web bundles, source maps, mobile packages, desktop apps, logs, crash reports, and public repositories for API keys and project IDs.
  2. Test proxy authentication. Call the proxy without a session, with an expired token, and with another tenant’s account. The proxy must reject the request before it sends data upstream.
  3. Test server controls. Change the model, tool name, tool arguments, file ID, vector store ID, output size, and streaming option. The server must use an allowlist tied to the user’s role and tenant.
  4. Test cost controls. Send parallel requests, retry completed requests, and hold streams open. Rate limits need user, tenant, IP, and project boundaries.
  5. Test stored resources. Try to read or delete files, threads, assistants, batches, and fine-tuning resources created by another test tenant.
  6. Test tool calls. Use harmless inputs that ask the model to call a tool with another user’s record ID. The application must authorize the tool on the server after the model chooses it.

Keep sanitized proxy requests, upstream request IDs, project audit logs, rate-limit results, resource ownership records, and the revoked key record. Do not store prompts, files, or model output in test evidence unless the review requires them.

Let Simpa Labs audit your API integrations

We specialize in identifying exposed credentials and API logic vulnerabilities. We will review your mobile app binaries, check your backend proxies, and verify your rate limit setups to keep your infrastructure safe.

Book an API Security Review