Queries the session logs of a specified application, supports filtering by agent, session, and role, and returns paginated log records.
Operation description
Logs for different roles may contain different fields. User messages may include Content. Assistant messages may include the model, token usage, and cost statistics. Tool execution results may include the tool name and execution status. Cost statistics are returned exactly as provided by the log source, and this API operation does not perform currency conversion.
Try it now
Test
RAM authorization
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| RegionId |
string |
Yes |
The region ID of the application. |
cn-hangzhou |
| ApplicationId |
string |
Yes |
The application ID. |
pa-************** |
| StartTime |
string |
Yes |
The start time of the query. Specify the time in the ISO 8601 standard in the YYYY-MM-DDTHH:mmZ format. The time must be in UTC. The start time cannot be later than the current time, and the interval between the start time and the current time cannot exceed 31 days. |
2026-11-04T01:00Z |
| EndTime |
string |
Yes |
The end time of the query. Specify the time in the ISO 8601 standard in the YYYY-MM-DDTHH:mmZ format. The time must be in UTC. The end time cannot be earlier than the start time, and the query time span cannot exceed 30 days. |
2026-11-04T02:00Z |
| PageSize |
integer |
No |
The number of entries to return on each page. Valid values: 30 to 100. Default value: 30. |
30 |
| PageNumber |
integer |
No |
The page number. Pages start from page 1. Maximum value: 2147483647. Default value: 1. |
1 |
| Type |
string |
No |
The log type. This API operation only queries session logs. Set the value to session. Valid values:
|
session |
| SessionId |
string |
No |
The session ID. This parameter must be specified together with the Agent parameter, or neither of them is specified. |
session-123 |
| Role |
string |
No |
The role filter for logs. Valid values: user, assistant, and toolResult. Valid values:
|
assistant |
| Agent |
string |
No |
The agent name. This parameter must be specified together with the SessionId parameter, or neither of them is specified. |
test-agent |
Response elements
|
Element |
Type |
Description |
Example |
|
object |
|||
| PageNumber |
integer |
The current page number. |
1 |
| ApplicationId |
string |
The application ID. |
pa-************** |
| PageRecordCount |
integer |
The number of log records returned on the current page. |
1 |
| RequestId |
string |
The request ID. |
2921D843-433A-5FB3-A03B-4EC093B219F8 |
| TotalRecordCount |
integer |
The total number of log records that meet the query conditions. |
1 |
| Items |
object |
||
| items |
array<object> |
The list of session log records. |
|
|
object |
|||
| Agent |
string |
The agent name. |
test-agent |
| Api |
string |
The name of the API operation called by the model. |
chat/completions |
| Content |
string |
The log message content. This field may be returned for user role logs. |
Hello |
| DetailDurationMs |
integer |
The detailed execution duration, in milliseconds. |
1500 |
| DetailIsError |
boolean |
Indicates whether the detailed execution result is an error. |
false |
| DetailStatus |
string |
The detailed execution status returned by the log source. |
completed |
| Id |
string |
The log message ID. |
msg-123 |
| Model |
string |
The name of the called model. |
gpt-3.5-turbo |
| ParentId |
string |
The parent message ID. |
parent-123 |
| Provider |
string |
The model service provider. |
openai |
| Role |
string |
The message role, such as user, assistant, or toolResult. |
assistant |
| SessionId |
string |
The ID of the session to which the log belongs. |
session-123 |
| Status |
string |
The tool execution status returned by the log source. |
success |
| StopReason |
string |
The reason why the assistant stopped generating, returned by the log source. |
length |
| Text |
string |
The generated text in the log. |
Generated response |
| Thinking |
string |
The thinking content of the log record. |
Let me think... |
| ThinkingSignature |
string |
The signature corresponding to the thinking content in the log. |
sig-123 |
| Time |
string |
The log time string returned exactly as provided by the log source. The example uses UTC time in the YYYY-MM-DDTHH:mm:ssZ format. |
2024-01-01T10:00:00Z |
| Timestamp |
string |
The original string of the log timestamp returned exactly as provided by the log source. The example is a Unix timestamp in seconds. |
1704067200 |
| ToolName |
string |
The name of the executed tool. |
calculator |
| TotalTokens |
integer |
The total number of tokens in the log record. |
150 |
| Type |
string |
The log event type returned by the log source. |
chat |
| UsageCacheRead |
integer |
The number of tokens read from the cache. |
20 |
| UsageCacheWrite |
integer |
The number of tokens written to the cache. |
10 |
| UsageCostCacheRead |
integer |
The original statistical value of the cache read cost passed through by the log source. This API operation does not perform currency conversion. The unit is defined by the log source. |
1 |
| UsageCostCacheWrite |
integer |
The original statistical value of the cache write cost passed through by the log source. This API operation does not perform currency conversion. The unit is defined by the log source. |
1 |
| UsageCostInput |
integer |
The original statistical value of the input token cost passed through by the log source. This API operation does not perform currency conversion. The unit is defined by the log source. |
1 |
| UsageCostOutput |
integer |
The original statistical value of the output token cost passed through by the log source. This API operation does not perform currency conversion. The unit is defined by the log source. |
1 |
| UsageCostTotal |
integer |
The original statistical value of the total cost passed through by the log source. This API operation does not perform currency conversion. The unit is defined by the log source. |
2 |
| UsageInput |
integer |
The number of input tokens. |
70 |
| UsageOutput |
integer |
The number of output tokens. |
80 |
| UsageTotalTokens |
integer |
The total number of tokens in the usage statistics. |
150 |
Examples
Success response
JSON format
{
"PageNumber": 1,
"ApplicationId": "pa-**************",
"PageRecordCount": 1,
"RequestId": "2921D843-433A-5FB3-A03B-4EC093B219F8",
"TotalRecordCount": 1,
"Items": {
"items": [
{
"Agent": "test-agent",
"Api": "chat/completions",
"Content": "Hello",
"DetailDurationMs": 1500,
"DetailIsError": false,
"DetailStatus": "completed",
"Id": "msg-123",
"Model": "gpt-3.5-turbo",
"ParentId": "parent-123",
"Provider": "openai",
"Role": "assistant",
"SessionId": "session-123",
"Status": "success",
"StopReason": "length",
"Text": "Generated response",
"Thinking": "Let me think...",
"ThinkingSignature": "sig-123",
"Time": "2024-01-01T10:00:00Z",
"Timestamp": "1704067200",
"ToolName": "calculator",
"TotalTokens": 150,
"Type": "chat",
"UsageCacheRead": 20,
"UsageCacheWrite": 10,
"UsageCostCacheRead": 1,
"UsageCostCacheWrite": 1,
"UsageCostInput": 1,
"UsageCostOutput": 1,
"UsageCostTotal": 2,
"UsageInput": 70,
"UsageOutput": 80,
"UsageTotalTokens": 150
}
]
}
}
Error codes
|
HTTP status code |
Error code |
Error message |
Description |
|---|---|---|---|
| 400 | InvalidStartTime.Malformed | The specified parameter StartTime is not valid. | The specified StartTime parameter is invalid. |
| 404 | InvalidDBClusterId.NotFound | The DBInstanceId provided does not exist in our records. | The specified DBClusterId parameter does not exist in the current record. |
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.