How to investigate a suspected API key leak: locate and disable the leaked key, identify anomalous periods from usage and billing, confirm call behavior with audit and inference logs, review management operations in ActionTrail, then complete damage assessment, evidence collection, and rotation.
Investigation approach
If the leak is confirmed, go to the API key management page first and reset or delete the leaked key to stop the loss, then follow the steps on this page to assess the impact; if the leak is uncertain, start with the usage check in step 2.
A leak investigation answers five questions, each mapped to a console information source:
Question to answer | Where to look | What you get |
|---|---|---|
Which key leaked? Who created it? What is its current status? | API key management page | Key ID, masked key, description, owning account, creation time; reset, edit, delete, and cost viewing actions |
How much was this key called, and how much did it cost? | Model usage, cost overview, and bills | Call counts, token usage, daily usage curves, and amounts grouped by API key |
Where did the calls come from, which models were called, and did they succeed? | Audit logs | Request ID, time, model, token usage, latency, status code, and error code; filterable by API key |
What was the input and output of the calls? | Inference logs (must be enabled in advance) | Complete prompts and responses (up to 128K) |
Which management operations has the key gone through? | ActionTrail | Operation event records at the console and OpenAPI level |
Step 1: Locate and disable the leaked key
Go to the Alibaba Cloud Model Studio API Key page and select a region in the upper-right corner: keys are independent per region and cannot be used across regions.
When the leak is confirmed, prioritize resetting or deleting the key to stop the loss immediately; editing to narrow permissions only fits situations where the leak is uncertain and you need an observation window. Locate the key in the API key list and use the actions in its row:
- Reset: issues a new value for the key, and the old value stops working immediately.
- Edit: narrows permissions (IP whitelist, model scope); see API key leak prevention best practices.
- Delete: takes effect immediately and is irreversible.
- View costs: jumps to the cost and usage view of the key.
- Creating a new key does not automatically invalidate the old key; the old key must be handled separately.
- Do not put the new key back into an environment that has not finished being investigated, or you are handing over the new credential again.
Step 2: Check usage and costs to identify anomalous periods
The most direct signal of a leak is calls or costs that should not exist. On the Model Studio console, choose Cost and Usage > Model Usage, set the grouping dimension to API Key, and compare the usage of each key to spot the anomalous one at a glance:
- Time granularity: minute (up to 1 day), hour (up to 7 days), day (up to 31 days), and month (up to 12 months); use hourly granularity to locate sudden high-cost calling.
- Data delay: call counts are delayed by less than 1 minute, token usage and costs by about 10 minutes; recent abuse may appear later, so do not rule out suspicion just because no data shows yet.
- Detail rows offer View costs for the associated amounts; for cost overview and bill accounting, see View cost overview and Query bills.
Step 3: Check call logs to confirm call behavior
Model Studio call logs fall into two categories with different capability boundaries; distinguish them during investigation.
Audit logs
Audit logs are enabled by default and stored on the platform side with no configuration required, making them the primary investigation tool. View them on the model monitoring page:
- Recorded fields: Request ID, time, model, token usage, latency, status, and error code, but not input or output content.
- Filtering and search: filter by time (up to 30 days), model, API key ID, status, and inference type, or search by Request ID.
- Usage: confirm whether the key's calls within the leak window match expected behavior, such as large volumes of 4xx/5xx, abnormal calling rhythms, or calls to unfamiliar models.
Inference logs
Inference logs contain complete prompts and responses plus intermediate steps (up to 128K). They must be enabled in advance under data delivery and delivered to your own log service (SLS; enabling involves cloud product authorization and log service costs), and only apply to future data: historical calls before enabling cannot be traced back, and logs generated while delivery is off are not backfilled. For enabling and regional availability, see Enable inference logs. If inference logs were not enabled, earlier calls can only be investigated through the field-level information in audit logs.
Tracing boundaries
The platform can help verify anomalous behavior based on call logs, but the calling IP, model, and time information is usually insufficient to directly confirm the actual user or the original leak channel; further tracing requires evidence from your code repositories, servers, terminals, and third-party services. The deliverable of an investigation is an evidence chain and impact assessment, not an attribution conclusion; for illegal activities, preserve evidence in accordance with the law and handle it through appropriate channels.
Step 4: Review management operation history
Lifecycle operations on API keys such as creation and deletion are aggregated in Alibaba Cloud ActionTrail. Go to the ActionTrail event query page and filter by service (Model Studio) and time range:
- Look up the key's creation events to confirm who created the key and when, verifying ownership.
- Look up the key's deletion events to confirm whether anyone deleted keys around the leak window, for example an attacker or insider attempting to erase traces.
Step 5: Damage assessment, evidence collection, and recovery
- Summarize the damage: combine the anomalous window (usage curves), call sources and statuses (audit logs), and amounts (bills) into an impact conclusion.
- Define the impact scope: assess by the key's authorization scope. Holding a Model Studio API key is not equivalent to holding the account password or full cloud resource permissions; the actual impact is limited to the authorized calling scope of the key. Note that a Model Studio API key and an Alibaba Cloud AccessKey (AK) are different credentials: if an AK leaked, follow the RAM AK handling process instead.
- Preserve masked evidence: when saving screenshots and Request ID lists, mask key values and account IDs, and stop spreading the complete key in any channel.
- Review asynchronous tasks: deleting a key does not cancel submitted asynchronous tasks; terminate cancellable tasks and track the costs of non-cancellable ones.
- Determine the rotation scope: invalidate and replace confirmed leaked keys as soon as possible; for the remaining keys, judge by exposure scope, and rotate together the keys stored in the same exposed environment.
- Recovery order: fix the leak source with the high-risk locations checklist, then create a new key in a trusted environment with reconfigured permissions and budget, update credential references in services, jobs, and third-party integrations, confirm the new key works, and finally verify the old key is invalid.
FAQ
The leaked key is deleted. Why do I keep receiving alerts?
The leaked key is deleted. Why do I keep receiving alerts?
The same key keeps triggering alerts. Does that confirm a leak?
The same key keeps triggering alerts. Does that confirm a leak?
Why can't I see the complete key in the console? Can support retrieve the plaintext?
Why can't I see the complete key in the console? Can support retrieve the plaintext?
I just enabled inference logs. Why can't I find yesterday's inputs and outputs?
I just enabled inference logs. Why can't I find yesterday's inputs and outputs?
The usage page does not match actual calls?
The usage page does not match actual calls?
Calls return 429. Is that rate limiting or budget stop?
Calls return 429. Is that rate limiting or budget stop?
Can I bulk export logs for my own analysis?
Can I bulk export logs for my own analysis?
How do I tell whether the leaked credential is a Model Studio API key or an Alibaba Cloud AccessKey?
How do I tell whether the leaked credential is a Model Studio API key or an Alibaba Cloud AccessKey?