Initialization
Confirm Endpoint
Before configuring the Endpoint for SDK usage, please refer to the developer guide section on BLB Access Domain Name to understand Endpoint-related concepts. Baidu AI Cloud currently supports multiple regions. Please refer to Region Selection Guide.
Currently, supported regions include "Beijing," "Guangzhou," "Suzhou," "Hong Kong," "Wuhan," "Baoding," "Shanghai," and "Singapore.\
The corresponding information for the service domain name:
| Access region | Endpoint |
|---|---|
| bj | blb.bj.baidubce.com |
| gz | blb.gz.baidubce.com |
| su | blb.su.baidubce.com |
| hkg | blb.hkg.baidubce.com |
| fwh | blb.fwh.baidubce.com |
| bd | blb.bd.baidubce.com |
| fsh | blb.fsh.baidubce.com |
| sin | blb.sin.baidubce.com |
Create a BlbClient
Create a BlbClient with AK/SK
Users can refer to the following code to create a BlbClient to access BLB with AK/SK:
1from baidubce import bce_client_configuration
2from baidubce.services.blb import blb_client
3from baidubce.auth import bce_credentials
4class Sample():
5 def setUp(self):
6 AK = 'your-access-key-id' # User's Access Key ID
7 SK = 'your-secret-access-key' # User's Secret Access Key
8# Initialize a BlbClient
9 config = BceClientConfiguration(credentials=BceCredentials(AK, SK))
10 client = blb_client.BlbClient(config)
In the code above, AK corresponds to the "Access Key ID" in the console, and SK corresponds to the "Access Key Secret" in the console. For the access method, please refer to the Operation Guide for Managing Access Key.
By default, the above method assigns the default domain as BLB’s service address. However, to specify a custom domain name, you need to include the ENDPOINT parameter.
1 AK = 'your-access-key-id' # User's Access Key ID
2 SK = 'your-secret-access-key' # User's Secret Access Key
3 HOST = 'domain-name' # User-specified domain name. For domain selection, refer to the "Region List" below
4# Initialize a BlbClient
5 config = BceClientConfiguration(credentials=BceCredentials(AK, SK), endpoint=HOST)
6 client = blb_client.BlbClient(config)
Note:
The ENDPOINTparameter must use region-specific domain names (e.g., http://aihc.bj.baidubce.com for Beijing). If unspecified, it defaults to the Beijing regionhttp://blb.bj.baidubce.com.
