API key leak investigation
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 |
Proceed in the following order:
疑似泄漏
├─ 第一步:定位 Key,立即重置或删除(止损)
├─ 第二步:按用量与费用曲线锁定异常时间段
├─ 第三步:按审计日志确认调用来源与行为(已开启推理日志时可查输入输出内容)
├─ 第四步:核对 Key 的创建、删除等管理操作
└─ 第五步:汇总定损,轮换凭证并修复泄漏源
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.
This page shows the key identity information: key ID, masked API key (for example sk-ws-H.YHXL****PgonKozeC4RM-Nm), description, owning account, and creation time. The description and owning account are the first clues to which application or owner the key belongs to; the complete plaintext is usually not viewable: new keys are displayed in full only once at creation, while some legacy keys can still be copied directly from the list, depending on what the list actually offers. For identification, rely on the masked value, ID, and description.
NoteDeleting a key does not cancel associated asynchronous tasks: tasks that have not finished will continue to run and incur charges, and must be terminated separately. See Asynchronous task billing when overdue. During the investigation, you can also enable "stop immediately when the budget is reached" for the key as a second containment measure; see Budget management.
Two common pitfalls when handling the incident:
- 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.
For metric definitions and operations, see View model usage.
Rule out normal business fluctuation first: compare the anomalous time, models, and call volume with releases, batch jobs, stress tests, and scheduled tasks of the business, and check whether the deployment region, egress IPs, or third-party tools using the key changed. Overseas IPs, new IPs, and usage spikes are signals that require verification, not conclusive evidence of a leak. Match the response to the level of suspicion: for a mere alert or mild anomaly, check the call sources in audit logs first; once the usage curve confirms calls from unfamiliar sources, reset or delete the key immediately and continue evidence collection.
Taking the leak confirmation time as the endpoint, look back 7 days (hourly) and 31 days (daily) to compare the key's historical baseline; the identified anomalous window defines the scope of the subsequent log investigation.
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.
For details, see Model Logs.
Inference logs
Inference logs contain complete prompts and responses plus intermediate steps (up to 128K). They must be enabled in advance under log 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 consolidated in Alibaba Cloud ActionTrail. Go to the ActionTrail event query page and filter by service (Model Studio) and time range. When filtering, note the service name and event name patterns of Model Studio events: in the China (Beijing) region, the service name is Model Studio Control (BailianControl), and the event list directly shows specific operation names (for example, api-key_listApiKeys4Agent); in other regions, the service name is Model Studio (Large Model Service Platform, SFM), and the event list shows gateway-level event names, so you need to expand an event record and check the requestParameters.Api field (for example, api-key.listApiKeys4Agent) to identify the specific operation. When filtering services by the "Model Studio" keyword, cover both service names.
- 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.
Confirm the key status and operation history through ActionTrail first, then investigate specific behavior with the call logs.
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.
WarningBefore abnormal costs are fully investigated, do not simply raise the budget or restore calling after turning off loss mitigation; complete the investigation above first to confirm the leak source is fixed.
FAQ
The leaked key has already been deleted. Why am I still receiving alerts?
There is a time gap between detection and notification, so you cannot determine whether an anomaly is still ongoing based solely on the notification time; historical events may also only be discovered and notified during subsequent reviews. Receiving a notification does not mean the old key can still be invoked successfully: if the old key has already been handled and recent usage shows no anomalies, you can check the invocation time and key identifier corresponding to the notification and then ignore it.
The same key keeps triggering alerts. Does this confirm a leak?
You cannot confirm a leak based solely on the number of repetitions. Check the invocation time, key identifier, and anomaly details corresponding to each alert, and distinguish newly occurring invocations, repeated notifications of the same event, and historical records.
A leak occurred but no platform alert was received. Why?
Platform risk detection and alerting are capabilities the platform provides proactively; they are not within the scope of services committed in the SLA, and due to the complexity of risk scenarios, an absolute alert coverage rate is not guaranteed; the secure storage and compliant use of credentials are your responsibility. Not receiving an alert does not mean there is no leak risk. First follow the steps in this document to complete the investigation and handling of the suspected leaked key, then verify the reason the alert was not delivered based on the anomaly time and notification records.
Why can't the full key be viewed in the console? Can support look up the plaintext?
No. The new key is displayed in full only once at creation; afterwards the full plaintext can no longer be viewed or copied (some legacy keys can still be copied directly from the list, subject to the capabilities actually provided by the list).
Inference Logs were just enabled. Why can't I find yesterday's inputs and outputs?
Inference Logs take effect only for future data; historical data cannot be traced back. Previous invocations can only be investigated through the field-level information in Audit logs.
The usage page does not match actual calls?
Token usage and costs are delayed by about 10 minutes; the usage page also only counts pay-as-you-go token-based calls, excluding training and pre-provisioned throughput (PTU). Failure counts and throttling errors are available on the model monitoring page.
Calls return 429. Is that rate limiting or budget stop?
Both return 429. A budget-exhausted error reads "The budget configured in Budget Management has been exhausted..."; see Error codes. A throttling 429 is triggered by rate or quota limits; distinguish them with the throttling error count metric in model monitoring.
Can I bulk export logs for my own analysis?
For your own analysis, deliver logs to your own SLS log store and search or export them there; see Log delivery.
How do I tell whether the leaked credential is a Model Studio API key or an Alibaba Cloud AccessKey?
They are different credentials: a Model Studio API key only accesses the model services within its authorization scope; an Alibaba Cloud AccessKey authenticates cloud API calls with permissions determined by the account and authorization configuration. Confirm the credential type first, then go to the corresponding product's management entry; do not mix up the processes.