Security & Best Practices

How to keep your game economy secure in production.

API Key Management

  • Server-side only. Never expose your API key in client-side code (browser, mobile app). Proxy requests through your backend.
  • Environment variables. Store keys in GAMEPLAYGEN_API_KEY, never in source code or git.
  • Rotate if compromised. If a key is leaked, create a new game and migrate. Keys cannot be rotated (yet).
  • One key per game. Each game gets its own API key at creation time. Keys are scoped to that game only.
typescript
// ✅ Server-side proxy (Next.js API route)
// app/api/economy/route.ts
export async function POST(req: Request) {
  const body = await req.json();
  const res = await fetch("https://gameplaygen.com/api/economy/grant", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${process.env.GAMEPLAYGEN_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(body),
  });
  return Response.json(await res.json());
}

// ❌ Never do this in client-side code:
// const eco = new GameEconomy({ apiKey: "gg_live_sk_..." }); // EXPOSED!

Cross-Game Isolation

Each API key is scoped to a single game. A key for Game A cannot read or modify Game B's economy. Player IDs (externalId) are also game-scoped — player_42in Game A is completely separate from player_42 in Game B.

Exploit Prevention

  • Server-authoritative. All economy mutations happen server-side. Players cannot grant themselves currency.
  • Balance checks. Spend and purchase operations verify sufficient balance before executing. No negative balances.
  • maxBalance caps. Set a ceiling per currency to prevent overflow exploits.
  • Atomic purchases. Item purchases deduct currency and add the item in one transaction — no partial state.
  • AI Advisor monitoring. The advisor continuously checks for anomalous patterns (sudden gold spikes, unusual transaction frequency).

Audit Trail

Every transaction is permanently recorded with:

  • Timestamp — when it happened
  • Type — grant, spend, transfer, or purchase
  • Amount & currency — what moved
  • Player — who was involved
  • Metadata — your custom context (reason, quest ID, etc.)
  • Request ID — for debugging and support

Access the full audit trail via the GET /transactions endpoint or the real-time feed on the dashboard.

Rate Limiting

Rate limiting is applied per-player via the anti-cheat system (not per API key). Each player has configurable limits per action type (e.g. 60 operations/minute for standard actions, 10/minute for crafting).

Exceeding the limit returns 429 Too Many Requests and creates an audit flag. See the Anti-Cheat documentation for details on configuring thresholds.