After initializing the TosVectorsClient instance, you can send HTTP/HTTPS requests to the TOS Vectors service. This article describes how to initialize the Node.js SDK.
The TOS Vectors Node.js client provides a set of interfaces to interact with the TOS Vectors service and manage resources such as buckets and vectors. When initializing the client, you must provide the AccessKey ID, AccessKey Secret, and Region information. During initialization, you can set optional parameters such as connection timeout, retry count on timeout, and maximum idle connections.
Prerequisites
Configure long-term access credentials
Before initializing the SDK, you need to configure long-term access credentials. This chapter explains how to configure long-term access credentials on different operating systems.
- Open Terminal and run this command to open the file.
- Add your access key ID and secret access key at the end of the file.
- Run this command to apply the configuration.
- Run this command to verify the configuration.
The following output confirms a successful configuration.
- Open Terminal and run this command to open the file.
- Add your access key ID and secret access key at the end of the file.
- Run this command to apply the configuration.
- Run this command to verify the configuration.
The following output confirms a successful configuration.
- Open the command line interface and run this command to enter your access key ID and secret access key.
- Run this command to apply the configuration.
- Restart the command line interface and run this command to verify the configuration.
The following output confirms a successful configuration.
Create TosVectorsClient
Initialize with required parameters
The following code shows how to initialize TosVectorsClient using required TOS parameters, including AccessKey ID, AccessKey Secret, Endpoint, and Region.
Initialize with optional parameters
The TOS Vectors Node.js SDK provides various optional parameters to customize the TosVectorsClient configuration, such as setting STS, HTTP request timeout, request retry policies, and more.
The following code demonstrates how to customize the HTTP connection timeout for TosVectorsClient. See the timeout configuration section below for specific scenarios.
Common configuration scenarios
Configure timeout settings
You can configure the network request timeout by adding optional parameters when initializing TosVectorsClient. The TOS Vectors Node.js SDK currently provides the following timeout parameters for HTTP request timeout configuration:
- requestTimeout: HTTP request timeout in milliseconds, with a default value of 120,000 (120 seconds).
- connectionTimeout: timeout for establishing an HTTP connection in milliseconds, default is 10,000 (10 seconds).
- The following code shows how to configure the timeout when initializing TosVectorsClient.
Configure retry strategy
Network fluctuations or short-term TOS Vectors service errors (such as returning a 500 HTTP status code) may cause requests to the TOS service to fail. To address this, the SDK includes a retry mechanism with exponential backoff based on the configured number of retries. The default retry count is 3.
Idempotent operation interfaces retry using exponential backoff upon failure; non-idempotent interfaces throw the corresponding exception immediately. You can add optional parameters to configure the number of retries when initializing the TosVectorsClient.
The following code shows how to set the SDK retry count.
Initialization parameter list