AI Tools Guide

AI API Key Security Rotation Guide

OpenAI/Gemini/Claude 等 AI API Key 被盗刷往往是放错了地方。讲清 key 只放服务端、用环境变量、绝不进前端和 git、设置用量上限、定期轮换,以及泄露后的应急步骤。

What is the problem?

OpenAI/Gemini/Claude 等 AI API Key 被盗刷往往是放错了地方。讲清 key 只放服务端、用环境变量、绝不进前端和 git、设置用量上限、定期轮换,以及泄露后的应急步骤。

Quick solution

Treat this as a GitHub tutorial issue. First confirm the environment, inputs, permissions, logs, and delivery boundary. Then use the linked deep guide for the full checklist before changing production code or promising a result.

Read the deep guide

Detailed steps

  1. 代码里用 `process.env.OPENAI_API_KEY` 读,不写死字符串;
  2. 给 AI API 的 key **绝不**加 `NEXT_PUBLIC_` / `VITE_` 前缀(加了就等于公开);
  3. 部署平台(Vercel / CI)在后台配同样的变量,本地 `.env` 不上传。
  4. 在 OpenAI / Anthropic / Google 后台设**月度用量上限 / 预算告警**,被刷也有天花板;
  5. 能力允许就用**受限权限的 key**(只给需要的范围);
  6. 不同项目用不同 key,方便单独吊销,互不牵连。

Commands or code

# .env.local —— 必须进 .gitignore
OPENAI_API_KEY=sk-xxxxx
ANTHROPIC_API_KEY=sk-ant-xxxxx

Risk notes

Confirm the real project environment, account permissions, platform rules, and output quality before delivery. Do not ship AI-generated changes without human review, and do not claim indexing, income, deployment success, or ranking improvements without measured evidence.