OSS assigns a unique request ID to every request it processes. When a request fails, provide the request ID to technical support so they can locate and resolve the issue.
This topic explains how to find a request ID from different access methods: OSS SDKs, browser developer tools, real-time logs, ossutil, and the Linux CLI.
Tip: When contacting technical support, provide the following information together: - Request ID - Approximate request time - Bucket name - Operation type (for example, PutObject, GetObject) This helps support staff resolve the issue faster.
Get request IDs from OSS SDKs
When a request fails, the OSS SDK exposes the request ID in the exception object. When a request succeeds, the request ID is returned in the response object.
The error output looks like:
Error Code: NoSuchKey
Error Message: The specified key does not exist.
Request ID: 5F2D4B3C1A2E4F1D
Host ID: examplebucket.oss-cn-hangzhou.aliyuncs.comThe following examples show how to extract the request ID from both error and success responses.
Java
import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
import java.io.File;
public class Demo {
public static void main(String[] args) throws Exception {
// Specify the endpoint of the region where your bucket is located.
// This example uses the China (Hangzhou) region.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Load access credentials from environment variables.
// Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running this code.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
String bucketName = "examplebucket";
String objectName = "exampledir/exampleobject.txt";
String filePath = "D:\\localpath\\examplefile.txt";
OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);
try {
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, new File(filePath));
PutObjectResult result = ossClient.putObject(putObjectRequest);
} catch (OSSException oe) {
// OSS returned an error response — the request reached OSS but was rejected.
System.out.println("Error Message: " + oe.getErrorMessage());
System.out.println("Error Code: " + oe.getErrorCode());
System.out.println("Request ID: " + oe.getRequestId());
System.out.println("Host ID: " + oe.getHostId());
} catch (ClientException ce) {
// Client-side error — the request could not reach OSS (for example, a network issue).
System.out.println("Error Message: " + ce.getMessage());
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
}
}PHP
<?php
if (is_file(__DIR__ . '/../autoload.php')) {
require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
}
use OSS\OssClient;
use OSS\Core\OssException;
// Load access credentials from environment variables.
// Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running this code.
$accessKeyId = getenv("OSS_ACCESS_KEY_ID");
$accessKeySecret = getenv("OSS_ACCESS_KEY_SECRET");
// Specify the endpoint of the region where your bucket is located.
$endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
$bucket = "examplebucket";
try {
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
$result = $ossClient->getObject($bucket, "demo.txt");
} catch (OssException $e) {
// Print the error message and request ID.
printf($e->getMessage() . "\n");
printf($e->getRequestId() . "\n");
}Node.js
const OSS = require('ali-oss');
const path = require('path');
const client = new OSS({
// Specify the region where your bucket is located.
region: 'oss-cn-hangzhou',
// Load access credentials from environment variables.
// Avoid hardcoding credentials in your source code.
accessKeyId: process.env.OSS_ACCESS_KEY_ID,
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
bucket: 'examplebucket',
});
async function put() {
try {
const result = await client.put(
'exampleobject.txt',
path.normalize('D:\\localpath\\examplefile.txt')
);
console.log(result);
} catch (e) {
// The error object includes the request ID.
console.log(e);
}
}
put();Python
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
# Load access credentials from environment variables.
# Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running this code.
auth = oss2.ProviderAuth(EnvironmentVariableCredentialsProvider())
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')
try:
stream = bucket.get_object('exampleobject.txt')
except oss2.exceptions.NoSuchKey as e:
# e.request_id contains the request ID.
print('status={0}, request_id={1}'.format(e.status, e.request_id))Go
package main
import (
"fmt"
"net/http"
"os"
"strings"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func HandleError(err error) {
fmt.Println("Error:", err)
os.Exit(-1)
}
func main() {
// Load access credentials from environment variables.
// Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running this code.
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Specify the endpoint of the region where your bucket is located.
client, err := oss.New("https://oss-cn-hangzhou.aliyuncs.com", "", "", oss.SetCredentialsProvider(&provider))
if err != nil {
HandleError(err)
}
bucketName := "examplebucket"
objectName := "exampleobject.txt"
bucket, err := client.Bucket(bucketName)
if err != nil {
HandleError(err)
}
var responseHeader http.Header
err = bucket.PutObject(objectName, strings.NewReader("Hello OSS"), oss.GetResponseHeader(&responseHeader))
if err != nil {
if serviceErr, ok := err.(oss.ServiceError); ok {
// OSS returned an error response.
fmt.Println("Error Message:", serviceErr.Message)
fmt.Println("Error Code:", serviceErr.Code)
fmt.Println("Request ID:", serviceErr.RequestID)
fmt.Println("Host ID:", serviceErr.HostID)
} else {
fmt.Println("Error:", err)
os.Exit(-1)
}
}
// For successful requests, extract the request ID from the response header.
requestId := oss.GetRequestId(responseHeader)
fmt.Println("Request ID:", requestId)
}Get request IDs from browser developer tools
OSS returns the request ID in the x-oss-request-id response header. The location of the request ID depends on whether the request succeeded or failed:
Successful requests: The request ID is in the HTTP response headers. Use your browser's developer tools to inspect the
x-oss-request-idheader.Failed requests: If OSS returns an error page, the request ID is in the XML response body:
<Error> <Code>AccessDenied</Code> <Message>Access Denied</Message> <RequestId>5F2D4B3C1A2E4F1D</RequestId> <HostId>examplebucket.oss-cn-hangzhou.aliyuncs.com</HostId> </Error>
The following steps use Google Chrome on Windows as an example.
Get the request ID when accessing an object directly
Open your browser and press
F12to open the developer tools.Click Network.
Access the object URL in your browser.
In the Name panel, click the object name.
Click the Headers tab. In the Response Headers section, find
x-oss-request-id.

Get the request ID when uploading an object in the OSS console
Open your browser and press
F12to open the developer tools.Click Network.
Log on to the OSS console. In the left-side navigation pane, click Buckets, then click the target bucket name.
In the left-side navigation tree, choose Object Management > Objects.
Upload an object. For more information, see Upload objects.
In the Name panel of the developer tools, click the uploaded object name.
Click the Headers tab. In the Response Headers section, find
x-oss-request-id.

Get request IDs from real-time logs
Use the Real-time Log Query feature in the OSS console to search for request IDs by operation.
Log on to the OSS console.
In the left-side navigation pane, click Buckets, then click the target bucket name.
Choose Logging > Real-time Log Query.
Press
Ctrl+Fand search forrequest_id.

Get request IDs from ossutil
When you run an ossutil command, the request ID appears in the returned log output.

Get request IDs from the Linux CLI
Use curl with verbose output to retrieve the x-oss-request-id header from the HTTP response.
Get the object URL from the OSS console.
Log on to the OSS console.
In the left-side navigation pane, click Buckets, then find and click the target bucket.
In the left-side navigation tree, choose Object Management > Objects.
Find the target object and click View Details in the Actions column. Then click Copy Object URL.
Run the following command to send the request and display the response headers:
curl -voa "<object-URL>"Replace
<object-URL>with the URL you copied.In the output, find the
x-oss-request-idheader:< x-oss-request-id: 5F2D4B3C1A2E4F1D
