Initialization

ET

  • API Reference
    • API function release records
    • Appendix
    • Common Request Headers and Response Headers
    • Dedicated Line Related Interfaces
      • Add dedicated channel routing parameters
      • Add dedicated channel user object
      • Apply for physical dedicated line
      • Associate dedicated channel
      • Create dedicated channel
      • Create routing rules of Dedicated channel
      • Delete dedicated channel
      • Delete routing rules of dedicated channel
      • Disable dedicated channel IPv6 function
      • Disassociate dedicated channel
      • Enable IPv6 function for the dedicated channel
      • Modify the dedicated channel routing rules
      • Query dedicated channel
      • Query dedicated line details
      • Query dedicated line list
      • Query the routing rules of the dedicated channel
      • Remove dedicated channel route parameters
      • Remove dedicated channel user object
      • Resubmit the dedicated channel
      • Update dedicated channel
      • Update physical dedicated line
    • Error code
    • General Description
    • Interface Overview
    • Overview
    • Service domain
  • FAQs
    • General Problems
  • Function Release Records
  • Getting Started Guide
    • Getting Started Guide
    • On-Premises IDC and Cloud VPC Interconnection
      • Add dedicated channel
      • Add network instance
      • Apply for physical dedicated line
      • Configure user-side routing and test connectivity
      • Create dedicated gateway
  • Operation guide
    • Dedicated channel
      • Add cross-account dedicated channel
      • Add dedicated channel
      • Dedicated Channel Cross-Account Authorization for Cloud Smart Network
      • Dedicated Channel IPv6 Feature Configuration
      • Delete dedicated channel
      • Dynamic routing BGP configuration for dedicated channels
      • Static route configuration for dedicated channels
    • Dedicated gateway
      • Create dedicated gateway
      • Dedicated Gateway
    • Identity and access management
    • Monitor and Operations
      • Alarm Strategy Description
      • Dedicated Channel Instance Diagnosis
      • Fault Drill
    • Physical dedicated line
      • Apply for physical dedicated line
      • Express Tunnel process
      • Manage Physical Dedicated Line
      • Operation preparation
  • Product billing
    • Billing Item Description
    • Charge
    • Expiration description
    • Overdue description
  • Product Description
    • Application scenarios
    • Dedicated Line Access Point Address
    • Product advantages
    • Usage restrictions
    • What Is Dedicated Line Access
  • SDK
    • GO SDK
      • Dedicated line
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Version history
    • Java-SDK
      • Dedicated line
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Version history
    • Python SDK
      • Dedicated line
      • Function Release Records
      • Initialization
      • Install the SDK Package
      • Overview
  • Service Level Agreement (SLA)
    • Service Level Agreement (SLA)
  • Typical Practices
    • Connecting On-Premises IDC to Cloud VPC via Multi-Line ECMP (Dynamic Routing)
    • Connecting On-Premises IDC to Cloud VPC via Multi-Line ECMP (Static Routing)
    • Connecting On-Premises IDC to Cloud VPC via Primary and Backup Dedicated Lines (Dynamic Routing)
    • Connecting On-Premises IDC to Cloud VPC via Primary and Backup Dedicated Lines (Static Routing)
    • Interconnecting IDCs and VPCs Across Different Regions via Dedicated Lines
All documents
menu
No results found, please re-enter

ET

  • API Reference
    • API function release records
    • Appendix
    • Common Request Headers and Response Headers
    • Dedicated Line Related Interfaces
      • Add dedicated channel routing parameters
      • Add dedicated channel user object
      • Apply for physical dedicated line
      • Associate dedicated channel
      • Create dedicated channel
      • Create routing rules of Dedicated channel
      • Delete dedicated channel
      • Delete routing rules of dedicated channel
      • Disable dedicated channel IPv6 function
      • Disassociate dedicated channel
      • Enable IPv6 function for the dedicated channel
      • Modify the dedicated channel routing rules
      • Query dedicated channel
      • Query dedicated line details
      • Query dedicated line list
      • Query the routing rules of the dedicated channel
      • Remove dedicated channel route parameters
      • Remove dedicated channel user object
      • Resubmit the dedicated channel
      • Update dedicated channel
      • Update physical dedicated line
    • Error code
    • General Description
    • Interface Overview
    • Overview
    • Service domain
  • FAQs
    • General Problems
  • Function Release Records
  • Getting Started Guide
    • Getting Started Guide
    • On-Premises IDC and Cloud VPC Interconnection
      • Add dedicated channel
      • Add network instance
      • Apply for physical dedicated line
      • Configure user-side routing and test connectivity
      • Create dedicated gateway
  • Operation guide
    • Dedicated channel
      • Add cross-account dedicated channel
      • Add dedicated channel
      • Dedicated Channel Cross-Account Authorization for Cloud Smart Network
      • Dedicated Channel IPv6 Feature Configuration
      • Delete dedicated channel
      • Dynamic routing BGP configuration for dedicated channels
      • Static route configuration for dedicated channels
    • Dedicated gateway
      • Create dedicated gateway
      • Dedicated Gateway
    • Identity and access management
    • Monitor and Operations
      • Alarm Strategy Description
      • Dedicated Channel Instance Diagnosis
      • Fault Drill
    • Physical dedicated line
      • Apply for physical dedicated line
      • Express Tunnel process
      • Manage Physical Dedicated Line
      • Operation preparation
  • Product billing
    • Billing Item Description
    • Charge
    • Expiration description
    • Overdue description
  • Product Description
    • Application scenarios
    • Dedicated Line Access Point Address
    • Product advantages
    • Usage restrictions
    • What Is Dedicated Line Access
  • SDK
    • GO SDK
      • Dedicated line
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Version history
    • Java-SDK
      • Dedicated line
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Version history
    • Python SDK
      • Dedicated line
      • Function Release Records
      • Initialization
      • Install the SDK Package
      • Overview
  • Service Level Agreement (SLA)
    • Service Level Agreement (SLA)
  • Typical Practices
    • Connecting On-Premises IDC to Cloud VPC via Multi-Line ECMP (Dynamic Routing)
    • Connecting On-Premises IDC to Cloud VPC via Multi-Line ECMP (Static Routing)
    • Connecting On-Premises IDC to Cloud VPC via Primary and Backup Dedicated Lines (Dynamic Routing)
    • Connecting On-Premises IDC to Cloud VPC via Primary and Backup Dedicated Lines (Static Routing)
    • Interconnecting IDCs and VPCs Across Different Regions via Dedicated Lines
  • Document center
  • arrow
  • ET
  • arrow
  • SDK
  • arrow
  • GO SDK
  • arrow
  • Initialization
Table of contents on this page
  • Usage steps
  • Confirm Endpoint
  • Create a Client object
  • Call function API
  • Example
  • Configuration
  • Use HTTPS
  • Detailed configurations

Initialization

Updated at:2025-11-11

Usage steps

Confirm Endpoint

Before using the SDK, you must confirm the endpoint (service domain) which Baidu AI Cloud will be integrated with. Taking Baidu's Virtual Private Cloud (VPC) product as an example, you can read the Service Domain Names section to understand concepts related to endpoints. Similar to other services, it is necessary to understand and confirm the endpoints of the corresponding services.

Create a Client object

Each specific service has a Client object, which encapsulates a series of easy-to-use methods for developers to interact with the corresponding service. Developers can refer to the directory corresponding to the specific service within the SDK to use the relevant service.

Call function API

Developers can call corresponding function APIs based on the created Client object of the relevant service to utilize the functions of Baidu AI Cloud.

Example

Using Baidu AI Cloud’s Virtual Private Cloud (VPC) as an example, a basic usage demonstration is provided below. For detailed usage instructions, refer to the service-specific documentation.

Go
1import (
2	"github.com/baidubce/bce-sdk-go/services/vpc"
3)
4func main() {
5 // User’s Access Key ID and Secret Access Key
6	ACCESS_KEY_ID, SECRET_ACCESS_KEY := "<your-access-key-id>", "<your-secret-access-key>"
7 // VPC service endpoint
8	ENDPOINT := "<domain-name>"
9 // Create VPC service client
10	vpcClient, err := vpc.NewClient(AK, SK, ENDPOINT)
11 // Create VPC
12    args := &CreateVPCArgs{
13		Name:        "TestSDK-VPC",
14		Description: "vpc test",
15		Cidr:        "192.168.0.0/16",
16		ClientToken: "clientToken",
17	}
18	result, err := vpcClient.CreateVPC("<your-create-vpc-args>"); err != nil {
19	if err != nil {
20		fmt.Println("create vpc failed:", err)
21	}
22	fmt.Println("create vpc success ,vpc id ", result.VPCID)
23}

Configuration

Use HTTPS

The SDK supports access to the service products of Baidu AI Cloud by HTTPS. To use HTTPS, you can simply specify the domain name using HTTPS in the endpoint when creating the Client object corresponding to the service. The SDK will automatically recognize and use HTTPS for access.

Detailed configurations

When developers use the GO SDK, the Client object created for the corresponding service provides the following parameters in its exported Config field for detailed configurations:

ConfigMap name Types Meaning
Endpoint string Domain name for service requests
ProxyUrl string The proxy address for client requests
Region string Region for resource requests
UserAgent string User name, HTTP request’s User-Agent header
Credentials *auth.BceCredentials Authentication object for requests, divided into regular AK/SK and STS
SignOption *auth.SignOptions Options for authentication string signing
Retry RetryPolicy Retry policy for connections
ConnectionTimeoutInMillis int Connection timeout, in milliseconds, defaulting to 20 minutes

Description:

  1. The Credentials field is created using the auth.NewBceCredentials and auth.NewSessionBceCredentials functions. The former is used by default, while the latter is used for STS authentication.
  2. The SignOption field represents options when generating a signature string, as detailed in the table below:
Name Types Meaning
HeadersToSign map[string]struct{} HTTP headers used when generating the signature string
Timestamp int64 Timestamp used in the generated signature string, defaulting to the value at the time of sending request
ExpireSeconds int Validity period of the signature string
Plain Text
1 Among configuration options, HeadersToSign defaults to `Host`, `Content-Type`, `Content-Length` and `Content-MD5`; TimeStamp is typically set to zero, indicating that the timestamp at the time of generating the certification string shall be used, and users generally shall not explicitly specify the value for this field; ExpireSeconds defaults to 1,800 seconds or 30 minutes.
  1. The Retry field specifies the retry policy, currently supporting two types: NoRetryPolicy and BackOffRetryPolicy. By default, the latter is used. This retry policy specifies the maximum number of retries, the maximum retry duration, and the retry base. Retries increase exponentially based on the retry base multiplied by 2 until the maximum number of retries or the maximum retry duration is reached.

Developers can configure detailed parameters accordingly. Below are some configuration examples:

Go
1// Client is the `Client` object of a specific service
2 // Configure request proxy address
3client.Config.ProxyUrl = "127.0.0.1:8080"
4 // Configure to not retry, default: Back Off retry
5client.Config.Retry = bce.NewNoRetryPolicy()
6 // Configure connection timeout to 30 seconds
7client.Config.ConnectionTimeoutInMillis = 30 * 1000
8 // Configure the HTTP request header Host for signing
9client.Config.SignOption.HeadersToSign = map[string]struct{}{"Host": struct{}{}}
10 // Configure the validity period of the signature to 30 seconds
11client.Config.SignOption.ExpireSeconds = 30

Previous
Exception handling
Next
Install the SDK Package