Create an API key
- Sign in to the LaoZhang API console.
- Open token management.
- Select a name, group, credit limit, or other restrictions currently available in the console.
- Copy the new key and store it securely.
- Validate the endpoint, model, and billing group with a minimal request.
Recommended storage
Environment variable
Set the key as an environment variable, then read it in code. The Python example uses the OpenAI SDK (pip install openai):
echo, debug logs, or exception messages.
Limit each token
When you create or edit a token, you can set four limits:- Quota matters most. If a token with unlimited quota leaks, you can lose your entire balance. A quota is only a spending cap and doesn’t reserve any of your balance; all tokens draw from the same account balance.
- IP allowlist takes your server’s public egress IP, as a single address or a CIDR range such as
203.0.113.0/24. Home and office connections change their egress IP, and every call fails once it changes, so use a quota there instead. - Allowed models rejects any model not on the list. Use IDs exactly as they appear in the model catalog. For everyday use and testing, leave it empty so switching models doesn’t require a console change.
prod-image-service. Then you can disable one without affecting the rest. Never embed a server API key in a browser, mobile app, or public client.
Group, fallback groups, and billing mode: what’s the difference?
When you create a token, its group, fallback groups, and billing mode are three separate settings. Usage first (按量优先) is a billing mode, not a group.- Whenever the primary group can serve the requested model, the primary group handles the request. Adding a fallback group doesn’t send requests there.
- To use a model or billing method that only an official-forward group offers, such as token-based billing for official-forward GPT Image, create a token whose primary group is that group. Setting it only as a fallback group isn’t enough.
- Usage first is the right billing mode in most cases. See token billing modes for the models each mode can call, and token groups and multipliers for what each group is for.
Keep keys out of these places
-
Repositories: a key committed to Git stays in the history even after you delete the file. Add
.envto.gitignoreand scan before you commit: - Docs, screenshots, and logs: console screenshots, terminal recordings, and error logs can all contain a full key, so use placeholders in examples. Public repositories are scanned by bots around the clock, and leaked keys can be abused quickly.
- Conversations with AI tools: a key pasted into an AI coding tool usually stays in plain text in local session history and file snapshots. Give AI tools a separate short-lived token with a small quota, delete it when the task is done, and never hand over a production key.
Rotate and revoke
Rotate or revoke immediately when:- a key appears in Git, logs, screenshots, tickets, or public messages;
- unexplained requests or balance changes occur;
- employee, contractor, or system access changes;
- a dependency, server, or deployment credential is compromised;
- support or security personnel request action.
- Create a new key and validate it in a controlled environment.
- Update the server-side secret.
- Observe calls using the new key.
- Revoke the old key.
- Review call logs for the affected period.
Investigate unexplained usage
If a token shows calls you don’t recognize:1
Find where the key went
Search for the key in chat history, repositories and their commit history, and environment variables on deployment and CI platforms. Most unexplained usage turns out to be an old configuration that’s still running.
2
Disable it if you can't find the source
Disable the token in token management. Tokens are independent, so disabling one doesn’t affect the others; create a replacement once you know you need it.
3
Trace the caller in call logs
Filter call logs by the token and look at the models, times, and source IPs. Watch for models you don’t use, calls outside your working hours, and volumes that don’t match your traffic.
4
Lock down the account
Change the account password and limit who can sign in to the console. Staff who only need to check usage don’t need console access.
API key vs. personal access token
Normal model calls use an API key. Account endpoints such as balance and log export use a personal access token (starts withnap_); the two credentials are not interchangeable. The old system AccessToken was retired on November 9, 2026, so create a personal access token under Security & Access in your personal settings; see Create a personal access token.