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

Torch Object Storage

Copy page
Download PDF
Vector bucket
CreateVectorBucket(TOS Vectors Node.js SDK)
Copy page
Download PDF
CreateVectorBucket(TOS Vectors Node.js SDK)
The createVectorBucket API creates a vector bucket. This article explains how to perform this operation using the createVectorBucket API in the TOS Vectors Node.js SDK.​
Notes​
  • You need to fill in the region and endpoint in the sample code according to your actual situation. For details, see Region and Endpoint.​
  • 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 using temporary access credentials and allows flexible settings such as timeout mechanisms and retry policies to enhance application security based on your business needs. For details, see Common Configuration Scenarios.​
  • Anonymous requests to create buckets are not allowed. Each user can create up to 100 vector buckets globally (including standard buckets).​
Permissions required​
The root account has all permissions by default, while IAM users have no permissions by default. If you need to use a sub-account to perform the createVectorBucket operation, the primary account must grant the sub-account the following permissions through IAM policies and bucket policies:​
tosvectors:CreateVectorBucket​
Code example:​
Create a vector bucket​
​
// Create a vector bucket​
​
import {​
TosVectorsClient,​
TosClientError,​
TosServerError,​
} from "@volcengine/tos-sdk";​
​
// Get authentication information and configuration from environment variables​
const client = new TosVectorsClient({​
accessKeyId: process.env["TOS_ACCESS_KEY"] as string, // TOS_ACCESS_KEY: your Access Key ID​
accessKeySecret: process.env["TOS_SECRET_KEY"] as string, // TOS_SECRET_KEY: your Secret Key​
region: 'Provide your region', // vector bucket region, for example cn-beijing​
endpoint: 'Provide your vector endpoint', // vector service domain, for example tosvectors-cn-beijing.volces.com​
});​
​
// read the vector bucket name to create from environment variables​
const vectorBucketName = 'Provide your vector bucket name'; // vector bucket name to create​
​
/**​
* handle errors that may occur during SDK calls.​
*@paramerror the caught error object​
*/​
function handleError(error: Error) {​
if (error instanceof TosClientError) {​
// client exception, 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 exception 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 {​
// 1. Prepare the parameters required by the API according to the use case scenario.​
​
console.log(`Start creating vector buckets: ${vectorBucketName} ...`);​
​
// 2. Call the corresponding API method.​
const result = await client.createVectorBucket({​
vectorBucketName,​
});​
​
// 3. Process and print key information from the returned result.​
console.log("Request ID:", result.requestId);​
console.log("Status Code:", result.statusCode);​
console.log("Headers:", result.headers);​
// after creation, you can use getVectorBucket to query details​
console.log("Result Data:", result.data);​
} catch (error: any) {​
handleError(error);​
}​
}​
​
main();​
​
​
Related documentation​
For the API documentation of CreateVectorBucket, see CreateVectorBucket.​
​
Last updated: 2026.02.06 18:01:45