Why Managers Should Care About Where the api_key Lives
Let me start with a real-world scenario: a team member, for debugging convenience, hardcoded an API Key directly into the code and committed it to the repository. Later, when the repository had to be opened up to an outsourcing vendor for secondary development, the Key had to be invalidated and reissued across the board, and every service using that Key had to have its configuration updated. Half a day gone — but the bigger loss was this: during that unknown window of time, how many people had access to that Key? Nobody could say.
As an independent developer or small team lead, you may not have a dedicated security team, but that's precisely why key management must be process-driven and institutionalized, rather than relying on everyone's self-discipline.
My approach is simple, just one hard rule: Keys never go into code, never into repositories, never into chat tools — they only go into environment variables. And to support this rule, we also consolidated the underlying layer — instead of having everyone apply for their own Keys from each provider, we unified everything through ThisToken.AI's multi-model gateway, so the whole team only manages one Key.
The Overall Approach
Compare before and after the change:
| Item | Before | After |
|---|---|---|
| Number of Keys | One per model provider | One for the gateway |
| Key storage | Scattered across each person's local config | Unified environment variable injection |
| Switching models | Change code, swap SDKs | Change one model name parameter |
| Employee departure | Check and revoke in each provider's console | Disable in one place on the gateway side |
For managers, this means three things: repeatable processes, well-defined collaboration boundaries, and controllable risk.
Step 1: Register and Get an API Key
- Open ThisToken.AI and complete registration;
- Go to the console and create an API Key;
- For billing on model calls, refer to the official pricing page — don't rely on secondhand information circulating online;
- Store the Key in an environment variable, and do not store it in any
.pyfile.
One suggestion: create separate Keys for different purposes (production, testing, dedicated to a specific member), so you have something to work with later when doing audits and revocations.
Step 2: Environment Variable Injection
macOS / Linux:
export THISTOKEN_API_KEY="sk-your-key"Windows PowerShell:
setx THISTOKEN_API_KEY "sk-your-key"For team collaboration, I recommend putting the variable name into the project's README and .env.example (variable names only, no values), so newcomers know what to configure right after cloning, without having to ask you.
Step 3: Get Your First Piece of Code Running
Using Python and the official OpenAI SDK as an example:
import os
from openai import OpenAI
# Key 只从环境变量读取,代码里没有任何明文密钥
client = OpenAI(
api_key=os.environ["THISTOKEN_API_KEY"],
base_url="https://api.thistoken.ai/v1",
)
resp = client.chat.completions.create(
model="gpt-4o-mini", # 模型名以网关文档支持的列表为准
messages=[
{"role": "system", "content": "你是一个简洁的中文技术助手。"},
{"role": "user", "content": "用一句话解释什么是API网关。"},
],
)
print(resp.choices[0].message.content)Note three key points:
api_keycomes fromos.environ, not a string literal;base_url="https://api.thistoken.ai/v1"— this single line is the entire change needed to switch from connecting directly to OpenAI to using the gateway. Because the gateway is compatible with the OpenAI protocol, there's no need to change SDKs;- Switching models only requires changing the
modelparameter, with no changes to the code structure.
Once this runs, each team member's environment variables are in place, and the same code can run on anyone's machine. This is what "collaboration with boundaries" means: code belongs to code, credentials belong to the environment.
Step 4: Three Leak-Prevention Measures Managers Should Implement
1. Repository-side interception. Add a secret-scanning step to CI (such as gitleaks), so even if someone accidentally writes a Key into the code, the commit will be blocked. Rules need tooling to back them up.
2. Add .env to .gitignore. Many leaks aren't intentional — they're the result of a blanket git add .
3. Regular rotation + immediate revocation upon departure. Since the entire team connects through the single gateway entry point, rotating a Key only requires updating the environment variable, without touching any business code — this is exactly the management dividend brought by consolidating multiple providers into a single entry point.
On Cost and Auditing
After unifying through the gateway, all calls are concentrated on the console side — who called which model, when, and how much was consumed, it's all recorded. For managers, this is more valuable than the unit price savings — when there's a budget anomaly, you're at the scene of the crime, instead of finding out only when the bill arrives. Refer to the official pricing page for specific billing rules.
Conclusion
Moving Keys from code into environment variables is a governance action with minimal change and huge payoff. Combined with a unified gateway, you solve three things at once: a narrowed key leakage surface, zero code changes for switching between multiple models, and auditable API call behavior.
If you're planning to do this for your team, you can start by registering an account, getting a Key, and running the code above — you'll see results in five minutes: https://api.thistoken.ai/register
---
Every example in this post runs with a single API key — get yours at https://api.thistoken.ai/register and start in minutes.
Vous voulez essayer Token.AI ?
Créez une API Key au niveau du projet, activez les canaux dans la console et configurez le routage, les budgets et les journaux d'audit.
注册 ThisToken.AI 并获取 API Key