BillingClient

Finance Finance

  • API Reference
    • Access control
    • Balance Query Related Interfaces
      • Account Balance Query
    • Bill Related Interfaces
      • Appendix
      • Charge Item Bill
      • Python Request Example
      • Resource Month Bill
    • Error response
    • Feature Update Records
    • General Description
    • Interface Specifications
    • Introduction
  • Bill Management
    • Bill Details
    • Bill Subscription
    • Consumption Information Subscription Guide
    • Consumption Overview
    • How to View
    • Tag-Based Billing
  • Charge
    • Billing & Configuration Changes
      • Configuration Upgrade Or Shrinkage
      • Shift Charge
    • Charge type
    • On-Demand Billing
    • Pay-as-you-go
    • Subscription billing
  • Contract
    • Apply for Electronic Contract
    • Overview
  • Cost Management
    • Cost Allocation
    • Cost Splitting
  • Disclaimer
  • Enterprise Organization Financial Management
  • FAQs
    • Bill and Debt
    • Billing Issues
    • Common Questions Overview
    • Contract Issues
    • Coupon Issues
    • Dedicated Account Remittance Issues
    • Invoice Issues
    • Order Issues
    • Recharge Issues
    • Refund Issues
    • Renew Issues
    • Withdrawal Issues
  • Invoice
    • Apply for Baidu Intelligent Cloud Invoice
    • Return or Exchange Baidu Intelligent Cloud Invoice
  • Multi-Account Multi-User Financial Management
    • Enterprise Organization - Financial Management
    • Multi-User Access Control - Financial Permission
    • Unified Finance
  • Order Management
  • Overview
  • Partner Deposit Payment
  • Purchase Guide
    • Coupon
      • Activating Coupons
      • Coupon Overview
      • Using Coupons
      • Viewing Coupons
    • Income and Expense Details
    • Purchase
    • Recharge
      • Exclusive Account Wire Transfer
      • Recharge Operations
      • Viewing Balance
    • Refund and Compensation
      • Product Compensation Standards
      • Refund Application Process
      • Refund policy
      • Unsubscribe Overview
      • Unsubscribe Rule Description
    • Renew
      • Auto-renewal
      • Renew Overview
      • Unified Resource Expiration Time
    • Withdrawal
  • Resource Package Management
    • Resource Package Deduction Details
    • Resource Package Overview
  • SDK
    • Java-SDK
      • Bill
      • BillingClient
      • Exception handling
      • Install SDK
      • Overview
      • Version Update Description
All documents
menu
No results found, please re-enter

Finance Finance

  • API Reference
    • Access control
    • Balance Query Related Interfaces
      • Account Balance Query
    • Bill Related Interfaces
      • Appendix
      • Charge Item Bill
      • Python Request Example
      • Resource Month Bill
    • Error response
    • Feature Update Records
    • General Description
    • Interface Specifications
    • Introduction
  • Bill Management
    • Bill Details
    • Bill Subscription
    • Consumption Information Subscription Guide
    • Consumption Overview
    • How to View
    • Tag-Based Billing
  • Charge
    • Billing & Configuration Changes
      • Configuration Upgrade Or Shrinkage
      • Shift Charge
    • Charge type
    • On-Demand Billing
    • Pay-as-you-go
    • Subscription billing
  • Contract
    • Apply for Electronic Contract
    • Overview
  • Cost Management
    • Cost Allocation
    • Cost Splitting
  • Disclaimer
  • Enterprise Organization Financial Management
  • FAQs
    • Bill and Debt
    • Billing Issues
    • Common Questions Overview
    • Contract Issues
    • Coupon Issues
    • Dedicated Account Remittance Issues
    • Invoice Issues
    • Order Issues
    • Recharge Issues
    • Refund Issues
    • Renew Issues
    • Withdrawal Issues
  • Invoice
    • Apply for Baidu Intelligent Cloud Invoice
    • Return or Exchange Baidu Intelligent Cloud Invoice
  • Multi-Account Multi-User Financial Management
    • Enterprise Organization - Financial Management
    • Multi-User Access Control - Financial Permission
    • Unified Finance
  • Order Management
  • Overview
  • Partner Deposit Payment
  • Purchase Guide
    • Coupon
      • Activating Coupons
      • Coupon Overview
      • Using Coupons
      • Viewing Coupons
    • Income and Expense Details
    • Purchase
    • Recharge
      • Exclusive Account Wire Transfer
      • Recharge Operations
      • Viewing Balance
    • Refund and Compensation
      • Product Compensation Standards
      • Refund Application Process
      • Refund policy
      • Unsubscribe Overview
      • Unsubscribe Rule Description
    • Renew
      • Auto-renewal
      • Renew Overview
      • Unified Resource Expiration Time
    • Withdrawal
  • Resource Package Management
    • Resource Package Deduction Details
    • Resource Package Overview
  • SDK
    • Java-SDK
      • Bill
      • BillingClient
      • Exception handling
      • Install SDK
      • Overview
      • Version Update Description
  • Document center
  • arrow
  • FinanceFinance
  • arrow
  • SDK
  • arrow
  • Java-SDK
  • arrow
  • BillingClient
Table of contents on this page
  • Create a BillingClient using AK/SK
  • Configure HTTPS protocol for Billing access
  • Configure BillingClient
  • Use a proxy

BillingClient

Updated at:2025-10-27

BillingClient is a client for the BILLING service of the transaction system. It provides developers with a series of methods for interacting with the BILLING service, including bill-related operations. To initiate an HTTP request for the BILLING service using the Java SDK, you need to initialize a BillingClient instance and modify the default configuration items of BosClientConfiguration as required.

Create a BillingClient using AK/SK

Users can refer to the following code to create a BillingClient to access Billing with AK/SK:

Plain Text
1 public class Sample {
2    public static void main(String[] args) {
3 String ACCESS_KEY_ID = <your-access-key-id>;                   // User’s Access Key ID
4 String SECRET_ACCESS_KEY = <your-secret-access-key>;// User’s Secret Access Key
5 // Initialize a BillingClient
6        BillingClientConfiguration config = new BillingClientConfiguration();
7        config.setCredentials(new DefaultBceCredentials(ACCESS_KEY_ID, SECRET_ACCESS_KEY));
8        config.setEndpoint("https://billing.baidubce.com");
9        BillingClient client = new BillingClient(config);
10    }
11 }

In the code above, [ACCESS_KEY_ID](Reference/Retrieve AK and SK/How to Obtain AKSK.md) corresponds to “Access Key ID” in the console. [SECRET_ACCESS_KEY](Reference/Retrieve AK and SK/How to Obtain AKSK.md) corresponds to “Access Key Secret” in the console. For the method to retrieve them, refer to the Guide - [Manage ACCESSKEY](Reference/Retrieve AK and SK/How to Obtain AKSK.md).

Configure HTTPS protocol for Billing access

Billing supports the HTTPS transmission protocol. You can access the Billing service via HTTPS in the Billing Java SDK through the following two methods:

  • Specify HTTPS in the endpoint:

    Plain Text
    1 String endpoint = "http://billing.baidubce.com";
    2 String ak = "ak";
    3 String sk = "sk";
    4 BillingClientConfiguration config = new BillingClientConfiguration();
    5 config.setCredentials(new DefaultBceCredentials(ak, sk));
    6 BillingClient client = new BillingClient(config);
  • Configure HTTPS by calling setProtocol:

    Plain Text
    1 String endpoint = "billing.baidubce.com"; // endpoint without protocol
    2 String ak = "ak";
    3 String sk = "sk";
    4 BillingClientConfiguration config = new BillingClientConfiguration();
    5 config.setCredentials(new DefaultBceCredentials(ak, sk));
    6 config.setEndpoint(ENDPOINT);
    7 config.setProtocol(Protocol.HTTPS); // Defaults to HTTP if unspecified
    8 BillingClient client = new BillingClient(config);

    Note: If the endpoint already includes a protocol, the one in endpoint takes effect, and the setProtocol() method will be ignored.

Configure BillingClient

If the user needs to configure some detailed parameters of BillingClient, they can specify the BillingClientConfiguration object when constructing BillingClient. BillingClientConfiguration is the configuration class for the BILLING service, which can configure parameters such as proxy and maximum count of connections for the client.

Use a proxy

The following code snippet enables the client to access BILLING service using a proxy:

Plain Text
1String ACCESS_KEY_ID = <your-access-key-id>;                   // User’s Access Key ID
2 String SECRET_ACCESS_KEY = <your-secret-access-key>;// User’s Secret Access Key
3 String ENDPOINT = <domain-name>;                               // User-defined domain name
4 // Create a BillingClientConfiguration instance
5 BillingClientConfiguration config = new BillingClientConfiguration();
6 // Configure proxy to local port 8080
7 config.setProxyHost("127.0.0.1");
8 config.setProxyPort(8080);
9 // Create a Billing client
10 config.setCredentials(new DefaultBceCredentials(ACCESS_KEY_ID,SECRET_ACCESS_KEY));
11 config.setEndpoint(ENDPOINT);
12 BillingClientclient = new BillingClient (config);

All client operations will then route through the proxy at 127.0.0.1:8080. For verified proxies, configure credentials:

Plain Text
1// Create a BillingClientConfiguration instance
2 BillingClientConfiguration config = new BillingClientConfiguration ();
3 // Configure proxy to local port 8080
4 config.setProxyHost("127.0.0.1");
5 config.setProxyPort(8080);
6 // Set username and password
7 config.setProxyUsername(<username>);                             // Username
8 config.setProxyPassword(<password>);                             // Password

Users may set the basic network parameters with BillingClientConfiguration:

Plain Text
1 BillingClientConfiguration config = new BillingClientConfiguration();
2    
3 // Set maximum number of HTTP connections to 10
4 config.setMaxConnections(10);
5    
6 // Set TCP connection timeout to 5,000 milliseconds
7 config.setConnectionTimeout(5000);
8    
9 // Set timeout for Socket data transmission to 2,000 milliseconds
10 config.setSocketTimeout(2000);

Parameter description

The following parameters can be configured via BillingClientConfiguration:

Parameters Description
UserAgent User agent, refers to HTTP’s User-Agent header
Protocol Connection protocol type
ProxyDomain Windows domain for NTLM-verified proxy
ProxyHost Proxy server host address
ProxyPort Proxy server port
ProxyUsername Proxy verification username
ProxyPassword Proxy verification password
ProxyPreemptiveAuthenticationEnabled Enable user agent verification or not
ProxyWorkstation NTLM proxy workstation name
LocalAddress Local address
ConnectionTimeoutInMillis Timeout for establishing TCP connections (unit: ms)
SocketTimeoutInMillis Timeout for socket data transmission (unit: ms)
MaxConnections Maximum allowable HTTP connections
RetryPolicy Retry policy for connections
SocketBufferSizeInBytes Buffer size for socket operations
StreamBufferSize Stream file buffer size

Previous
Bill
Next
Exception handling