Skip to main content

Model Logs

Model Studio records audit logs by default; you can enable inference logs to record the complete Prompt and Response, and deliver logs to a Simple Log Service (SLS) Logstore. You can also pass a custom request header to associate business requests with model calls in audit logs.

Model Studio records audit logs by default (stored on the platform, no configuration required), capturing the request information of each model call but not the Prompt or Response. Inference logs record the complete Prompt and Response and the intermediate steps; they must be enabled manually and rely on log delivery to write logs to your own Simple Log Service (SLS) Logstore.

Audit log

Audit logs are enabled by default for all users, require no configuration, and are stored on the Model Studio platform. Audit logs record the request information of each model call, including core metrics such as Request ID, time, model, token usage, latency, and status, but do not include the Prompt and Response content. To view the complete Prompt and Response content, enable inference logs (for how to enable them, see the Inference log section). Audit logs are retained for 30 days on the Model Studio platform by default. Log on to the Model Studio console, and in the left-side navigation pane choose Operations > Model Logs to open the Audit Log tab. To retain logs longer, enable log delivery to deliver audit logs to a Logstore under your own Simple Log Service (SLS) account, and then adjust the log retention period in SLS (to adjust the retention period, see Manage a Logstore; for how to enable delivery, see the Log delivery section).

Filter conditions

Audit logs support the following filter conditions:
  • Time range: 24 hours by default; supports 3/6/12/24 hours, today, and custom time ranges, and custom ranges can query logs from up to 30 days back.
  • Model: Drop-down selection; all models by default.
  • API key ID: Drop-down selection. The API key shows the ID and description; if the API key is deleted, the description is empty.
  • Status: Multiple selection, including 0 (request succeeded but the user actively interrupted it), 200 (Success), 4XX (exceptions caused by user behavior), and 5XX (service unavailable).
  • Inference type: Online inference by default.
  • Search Request ID: Exact match.

Log list

The audit log list displays the following fields: Request ID, call time, model, usage, first-token latency, call duration, status, API Key, and error code. The Actions column provides Details, which opens the audit log details side panel.
Audit log list

Details side panel

The audit log details side panel supports switching between the List and JSON tabs. The List tab shows the following groups:
  • Basic information: Request ID, creation time, model, API Key
  • Usage: total tokens, output tokens, input tokens
  • Performance: first-token latency, total duration, status code
The JSON view shows the complete log fields, including the extras extension fields (business identifiers are recorded there; see Custom business identifier best practices); the meaning of each field is described in Field reference. To create and manage API keys, see Obtain an API key.

Field reference

The JSON view of the audit log details side panel uses the same fields as the logs delivered to SLS. The 25 fields are described below by category (only the first 2 rows are shown by default; click Expand all fields to view the complete list).
CategoryFieldTypeDescription
Request basicsrequest_idstringUnique ID (UUID) generated by the system for the model call, used to locate and trace the call; corresponds to the Request ID column
Request basicsstart_timestringWhen the call started (Beijing time, to the millisecond); corresponds to the call time column
Request basicsstart_unix_timestampstringUnix timestamp (milliseconds) of when the call started
Request basicsdurationstringTotal time from request to response, in milliseconds; corresponds to the call duration column
Request basicsfirst_output_durationstringFirst-token latency (delay before the first output token), in milliseconds; shown only in records of streaming calls; corresponds to the first-token latency column
Request basicsstatus_codestringStatus code of the call: 0 (request succeeded but actively interrupted by the user), 200 (success), 4XX (exceptions caused by user behavior), 5XX (service unavailable); corresponds to the status column
Request basicserror_codestringError code of the failed call, shown only in failed records; corresponds to the error code column
Request basicserror_messagestringError message of the failed call, shown only in failed records
Model and sourcemodelstringModel code; corresponds to the model column
Model and sourcesourcestringLog source (model indicates a model call)
Model and sourcechannelstringCall channel (default indicates the default channel)
Model and sourceregionstringRegion of the call, such as cn-beijing
Token usageusage.total_tokensintTotal tokens consumed by the call, corresponding to the usage column
Token usageusage.input_tokensintInput tokens
Token usageusage.output_tokensintOutput tokens
Token usageusage.prompt_tokens_details.cached_tokensintNumber of input tokens served from the context cache
Authentication and clientapikey_idstringID of the API key used for the call, corresponding to the API Key column; after an API key is deleted, the list does not show the description and the details show only the ID
Authentication and clientuidstringAlibaba Cloud account ID that made the call
Authentication and clientclient_ipstringClient IP that made the call
Authentication and clientworkspace_idstringWorkspace from which the call was made
Extensionextras.custom_datastringCustom business identifier (see Custom business identifier best practices)
Extensionextras.encryptstringEncryption status
Extensionextras.model_typestringModel type
Extensionextras.protocolstringCall protocol: HTTP (non-streaming), SSE (streaming)
Extensionextras.sub_protocolstringCall sub-protocol

Inference log

Inference logs must be enabled manually. On top of audit logs, inference logs additionally record the complete Prompt and Response and the intermediate steps, which help with debugging, optimization, and troubleshooting. Inference logs are stored in your own Simple Log Service (SLS) Logstore.

Enable inference logs

Inference logs are disabled by default; you must first enable audit log delivery. On the log page, switch to the Inference Log tab (when it is not configured, this tab shows a guide page to enable it) and click Start configuration to open the log delivery configuration dialog box. You can also enter it by clicking the Log delivery configuration button in the upper-right corner of the log page. After you complete the authorization and Logstore configuration, you can view the inference log list.
Inference logs are currently supported only in the Beijing and Singapore regions; other regions are not yet supported.

Log list and details

The filter conditions for inference logs are the same as for audit logs. For models that do not support inference logs, "Not supported by the current model" is displayed. On top of audit logs, the inference log list adds a "Requests and responses" column that shows the Prompt and Response data. Each log entry is limited to 128K in length; content beyond the limit is truncated. For the complete content, view the logs in the SLS Logstore you delivered to.
Inference log list
Inference logs can be recycled into training datasets: click the Log backflow button on the Inference Log tab. For more information, see Log backflow.
Inference logs record the complete Prompt and Response, which is suitable for reproducing abnormal requests, debugging model outputs, and troubleshooting intermittent issues.

Log delivery

By default, Model Studio stores audit logs on the platform, so you can view them in the console without any delivery. To retain logs long term or integrate them with your own O&M systems, enable log delivery, which automatically delivers audit logs and inference logs to a Logstore of the Simple Log Service (SLS) under your account. Log delivery is also a prerequisite for enabling inference logs.
Enabling inference logs and delivering logs to your own SLS Logstore incurs Simple Log Service charges.

Delivery configuration steps

The log delivery configuration entry is in the upper-right corner of the log page (to open the log page, choose Operations > Model Logs in the left-side navigation pane). Configuring log delivery for the first time requires the following three steps:
  1. Authorize the Simple Log Service role.
  2. Activate Simple Log Service.
  3. Create a Logstore.
Existing users who have already enabled log delivery do not need to reconfigure; the original configuration is retained automatically, and the Logstore cannot be changed.
On the SLS side, modifying indexes is not supported; modifying indexes causes query failures. Do not delete the SLS Logstore created by Model Studio; deleting it causes log delivery failures.

Audit log delivery

After you enable or disable audit log delivery, a result message briefly pops up at the top of the page. The authorization and configuration process is the same as the delivery configuration steps.

Inference log delivery

Before you enable inference log delivery, you must first enable audit log delivery (inference log delivery cannot be enabled when audit log delivery is not configured). The authorization and configuration process for inference log delivery is the same as the delivery configuration steps.
After you disable audit log delivery, inference log delivery is also disabled.
After the configuration is complete, a status indicator is displayed next to the log delivery configuration; the three states have the same meanings as for monitoring data delivery.
After you disable log delivery, logs generated during the disabled period are not synchronized to the SLS Logstore and cannot be backfilled or restored afterward. Disable it with caution.

Custom business identifier best practices

When troubleshooting business issues, you may need to confirm which model calls were triggered by a specific order or business request. When calling a model, you can pass a custom business identifier (such as an order identifier, business request ID, or trace ID) in the X-DashScope-Custom-Data request header. The identifier is written as-is into the extras.custom_data field of the audit log for that call, associating business requests with model calls. When the same business request triggers multiple model calls, you can reuse the same business identifier and record the Request ID of each call separately in your business logs. Business identifiers are shown only in the JSON view of the audit log details, and filtering by business identifier is not supported. When troubleshooting, first obtain the Request ID from the business logs, then locate the call in the audit logs and verify the business identifier (see Verify the audit log).
Currently, this request header is supported in calls to the OpenAI-compatible Chat API (including streaming calls) and the Model Studio native API (the /api/v1/services/ path). The OpenAI-compatible Responses API and the Anthropic-compatible Messages API are not yet supported.

Pass a business identifier

  1. Select an identifier to associate with your business logs. This topic uses the order identifier order-20261028-001 as an example.
  2. Write the identifier into the X-DashScope-Custom-Data request header and make the model call. Replace {WorkspaceId} with your workspace ID. If you call from another region, use the endpoint of that region (see OpenAI compatible - Chat).
  • cURL
  • OpenAI Python SDK
curl --request POST 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions' \
  --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
  --header 'Content-Type: application/json' \
  --header 'X-DashScope-Custom-Data: order-20261028-001' \
  --data '{
    "model": "qwen-plus",
    "messages": [{"role": "user", "content": "Hello"}]
  }'
The value of this request header is written to audit logs. Do not pass sensitive information such as AccessKeys, API keys, tokens, passwords, or phone numbers. If the original identifier contains sensitive information, use a substitute identifier that does not, and maintain the mapping on the business side.

Verify the audit log

  1. After the model call completes, record the Request ID from the response (for OpenAI-compatible APIs, the response body id field and the x-request-id response header return the same value; for the native API, the response body request_id field).
  2. Log on to the Model Studio console, select the region and workspace used for the call, and in the left-side navigation pane choose Operations > Model Logs. On the Audit Log tab, select a time range that covers the call time, and use the Request ID (exact match) to locate the record.
  3. Click Details on the record, switch to the JSON tab in the audit log details side panel, and check the extras.custom_data field. In this example, the value is order-20261028-001. The following shows only the extras fields related to this feature:
{
  "custom_data": "order-20261028-001"
}
Audit log details side panel - JSON view (extras.custom_data)
If no call record is found, check the following:
  1. Whether the region, workspace, query time range, and Request ID match those used for the call.
  2. Whether the call was rejected at the authentication layer (for example, an invalid API key) — calls rejected at the authentication layer do not generate audit logs.
If the record is found but has no custom_data field, check whether the request actually sent to Model Studio carried this request header, and whether the gateways or proxies the request passed through forwarded it intact (see Usage limits and notes).

Pass multiple business fields (optional)

To pass multiple fields such as a business request ID and a business scenario, serialize the fields into a compact JSON string and pass it as the value of the request header. The following example reuses the client created earlier:
import json

custom_data = json.dumps(
    {"biz_request_id": "order-20261028-001", "scene": "customer_service"},
    ensure_ascii=True,
    separators=(",", ":"),
)

response = client.chat.completions.create(
    model="qwen-plus",
    messages=[{"role": "user", "content": "Hello"}],
    extra_headers={"X-DashScope-Custom-Data": custom_data},
)
Verify the audit log as described earlier; the extras snippet is as follows:
{
  "custom_data": "{\"biz_request_id\":\"order-20261028-001\",\"scene\":\"customer_service\"}"
}
custom_data is always a string in the audit log, not a nested JSON object. After parsing extras, you can use json.loads(extras["custom_data"]) to parse the business fields. Before sending, confirm that the serialized string is within the length limit specified in the Usage limits and notes; otherwise, truncation may make the JSON unparseable.

Usage limits and notes

  • Audit logs retain at most the first 512 characters of the request header value; the excess is truncated.
  • Use ASCII characters for the request header value: HTTP clients and proxies generally do not support non-ASCII header values, and the request fails at the sending stage. When passing multiple fields, use JSON serialization with ensure_ascii=True.
  • The request header name is case-insensitive; use X-DashScope-Custom-Data consistently.
  • If the model request passes through a business service, API gateway, or other proxy, make sure the intermediate layers forward this request header intact to Model Studio.
  • The business identifier is for business association only and does not change how the system Request ID is generated or queried.