You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Vector bucket
ListVectorBuckets(TOS Vectors Node.js SDK)
Copy page
Download PDF
ListVectorBuckets(TOS Vectors Node.js SDK)
The listVectorBuckets interface lists vector buckets. This article explains how to perform this operation using the listVectorBuckets interface of the TOS Vectors Node.js SDK.​
Notes​
  • to prevent key leakage, the sample code in this article reads the Access Key ID and Secret Access Key from environment variables. therefore, before using the SDK, you need to configure long-term access credentials. For details, see configure long-term access credentials.​
  • the TOS Vectors Node.js SDK supports temporary access credentials and allows configuring timeout mechanisms, retry policies, and more. You can adjust these flexibly to enhance application security. For details, see common configuration scenarios.​
Permissions required​
the main account has all permissions by default, but IAM users have no permissions by default. If you need to use a sub-account to perform the listVectorBuckets operation, the primary account must grant the following permissions to the sub-account through IAM policies and bucket policies:​
tosvectors:ListVectorBuckets​
Code example​
Basic usage of listing vector buckets​
​
// List basic usage of vector buckets​
​
import {​
TosVectorsClient,​
TosClientError,​
TosServerError,​
} from "@volcengine/tos-sdk";​
​
// Retrieve authentication information and configuration from environment variables​
const accessKeyId = process.env["TOS_ACCESS_KEY"]; // TOS_ACCESS_KEY: your Access Key ID​
const accessKeySecret = process.env["TOS_SECRET_KEY"]; // TOS_SECRET_KEY: your Secret Key​
const region = 'Provide your region';​
const endpoint = 'Provide your vector endpoint';​
​
const client = new TosVectorsClient({​
accessKeyId,​
accessKeySecret,​
region,​
endpoint,​
});​
​
/**​
* Handle errors that may occur during SDK calls.​
*@paramerror The error object caught​
*/​
function handleError(error: Error) {​
if (error instanceof TosClientError) {​
// Client-side exceptions, usually due to parameter errors or network issues​
console.log("Client Error:");​
console.log(" Message:", error.message);​
if (error.stack) {​
console.log(" Stack:", error.stack);​
}​
} else if (error instanceof TosServerError) {​
// Server-side exceptions, indicating the request was received but processing failed​
console.log("Server Error:");​
console.log(" Request ID:", error.requestId);​
console.log(" Status Code:", error.statusCode);​
console.log(" Code:", error.code);​
console.log(" Message:", error.message);​
console.log(" Headers:", error.headers);​
} else {​
// Other unknown exceptions​
console.log("Unexpected Error:");​
console.log(" Message:", error.message);​
}​
}​
​
async function main() {​
try {​
// 2. Call listVectorBuckets to list vector buckets at once​
const result = await client.listVectorBuckets({​
maxResults: 100,​
});​
​
// 3. Print general return information​
console.log("Request Succeeded:");​
console.log(" Request ID:", result.requestId);​
console.log(" Status Code:", result.statusCode);​
console.log(" Headers:", result.headers);​
​
// 4. Print business data: the list of vector buckets returned this time​
const buckets = result.data.vectorBuckets || [];​
if (buckets.length === 0) {​
console.log("The current request did not return any vector buckets.");​
} else {​
console.log("Vector bucket List:");​
for (const bucket of buckets) {​
console.log(` - Name: ${bucket.vectorBucketName}`);​
console.log(` Creation Time: ${bucket.creationTime}`);​
console.log(` TRN: ${bucket.vectorBucketTrn}`);​
}​
}​
​
// Print the next page token (if any)​
if (result.data.nextToken) {​
console.log("Next Token:", result.data.nextToken);​
}​
} catch (error: any) {​
handleError(error);​
}​
}​
​
main();​
​
​
Paginated listing of vector buckets​
​
// list vector buckets with pagination​
​
import {​
TosVectorsClient,​
TosClientError,​
TosServerError,​
} from "@volcengine/tos-sdk";​
​
// get authentication information and configuration from environment variables​
const accessKeyId = process.env["TOS_ACCESS_KEY"]; // TOS_ACCESS_KEY: your Access Key ID​
const accessKeySecret = process.env["TOS_SECRET_KEY"]; // TOS_SECRET_KEY: your Secret Key​
const region = 'Provide your region';​
const endpoint = 'Provide your vector endpoint';​
​
const client = new TosVectorsClient({​
accessKeyId,​
accessKeySecret,​
region,​
endpoint,​
});​
​
/**​
* handle errors that may occur during SDK calls.​
*@paramerror caught error object​
*/​
function handleError(error: Error) {​
if (error instanceof TosClientError) {​
// Client-side error, usually caused by parameter issues or network problems​
console.log("Client Error:");​
console.log(" Message:", error.message);​
if (error.stack) {​
console.log(" Stack:", error.stack);​
}​
} else if (error instanceof TosServerError) {​
// Server-side error, indicating the request was received but processing failed​
console.log("Server Error:");​
console.log(" Request ID:", error.requestId);​
console.log(" Status Code:", error.statusCode);​
console.log(" Code:", error.code);​
console.log(" Message:", error.message);​
console.log(" Headers:", error.headers);​
} else {​
// Other unknown errors​
console.log("Unexpected Error:");​
console.log(" Message:", error.message);​
}​
}​
​
async function main() {​
let maxResults = 100;​
​
try {​
console.log("Start paging and listing vector buckets...");​
​
let nextToken: string | undefined = undefined;​
let page = 1;​
​
// Use nextToken for paginated iteration​
do {​
console.log(`\n Request the vector bucket list for page ${page}...`);​
​
const result = await client.listVectorBuckets({​
maxResults,​
nextToken,​
});​
​
// Print common request information per page​
console.log("Page Request Info:");​
console.log(" Request ID:", result.requestId);​
console.log(" Status Code:", result.statusCode);​
console.log(" Headers:", result.headers);​
​
// Print the vector bucket list of this page​
const buckets = result.data.vectorBuckets || [];​
if (buckets.length === 0) {​
console.log(" This page did not return any vector buckets.");​
} else {​
console.log(" Vector bucket list on this page:");​
for (const bucket of buckets) {​
console.log(` - Name: ${bucket.vectorBucketName}`);​
console.log(` Creation Time: ${bucket.creationTime}`);​
console.log(` TRN: ${bucket.vectorBucketTrn}`);​
}​
}​
​
nextToken = result.data.nextToken;​
if (nextToken) {​
console.log(" Next Token:", nextToken);​
page += 1;​
} else {​
console.log(" There are no more paging results.");​
}​
} while (nextToken);​
} catch (error: any) {​
handleError(error);​
}​
}​
​
main();​
​
​
Related documentation​
For the API documentation of ListVectorBuckets, please refer to ListVectorBuckets.​
​
Last updated: 2026.02.06 18:01:44