The Optimization Solver console SDKs enable you to query license information programmatically — including service activation status, purchased license details, and license usage. If your application does not need to query this information, you do not need to install the SDKs.
Supported languages
SDKs are available for Java, Python3, Go, and C++.
| Language | GitHub repository | README |
|---|---|---|
| Java | alibabacloud-java-sdk | README.md |
| Go | alibabacloud-go-sdk | README.md |
| Python3 | alibabacloud-python-sdk | README.md |
| C++ | alibabacloud-cpp-sdk | README.md |
The following sections use Java to demonstrate all three API operations. For Go, Python3, and C++, see the README in the corresponding GitHub repository.
Prerequisites
Before you begin, ensure that you have:
An active Optimization Solver service
An AccessKey ID and AccessKey secret (see Obtain an AccessKey pair)
The fastjson dependency configured in your Java project (version 1.2.83)
Authentication
All examples authenticate using an AccessKey ID and AccessKey secret. Store these credentials as environment variables rather than hardcoding them in your source code — hardcoded credentials risk leakage if code is shared or committed to version control.
Use a Resource Access Management (RAM) user with the minimum required permissions instead of your Alibaba Cloud account credentials. To create a RAM user, log in to the RAM console.
The examples read credentials from the following environment variables:
| Environment variable | Description |
|---|---|
OSS_ACCESS_KEY_ID | Your AccessKey ID |
OSS_ACCESS_KEY_SECRET | Your AccessKey secret |
Java SDK examples
Add the fastjson dependency to your Maven project:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>All three examples follow the same structure: configure credentials and an endpoint, create a client, then call the target API.
Check service activation status
Use GetOpenStatus to verify whether Optimization Solver services are activated for your account.
package com.alibaba.mind.opt.sdk;
import com.alibaba.fastjson.JSON;
import com.aliyun.opt20210730.Client;
import com.aliyun.opt20210730.models.GetOpenStatusResponse;
import com.aliyun.teaopenapi.models.Config;
public class GetOpenStatusExample {
public static void main(String[] args) {
try {
Config authConfig = new Config();
authConfig.accessKeyId = System.getenv("OSS_ACCESS_KEY_ID");
authConfig.accessKeySecret = System.getenv("OSS_ACCESS_KEY_SECRET");
authConfig.endpoint = "opt.cn-beijing.aliyuncs.com";
Client client = new Client(authConfig);
GetOpenStatusResponse getOpenStatusResponse = client.getOpenStatus();
System.out.println(JSON.toJSONString(getOpenStatusResponse.getHeaders()));
System.out.println(JSON.toJSONString(getOpenStatusResponse.getBody()));
} catch (Exception e) {
e.printStackTrace();
}
}
}Query purchased license information
Use GetOrderInfo to retrieve details about your purchased licenses.
Before calling the API, select values for the required parameters:
relService — the service to query:
| Value | Description |
|---|---|
MP | Mathematical programming service |
resourceType — the license edition:
| Value | Description |
|---|---|
1 | Local Edition |
package com.alibaba.mind.opt.sdk;
import com.alibaba.fastjson.JSON;
import com.aliyun.opt20210730.Client;
import com.aliyun.opt20210730.models.GetOrderInfoRequest;
import com.aliyun.opt20210730.models.GetOrderInfoResponse;
import com.aliyun.teaopenapi.models.Config;
public class GetOrderInfoExample {
public static void main(String[] args) {
try {
Config authConfig = new Config();
authConfig.accessKeyId = System.getenv("OSS_ACCESS_KEY_ID");
authConfig.accessKeySecret = System.getenv("OSS_ACCESS_KEY_SECRET");
authConfig.endpoint = "opt.cn-hangzhou.aliyuncs.com";
Client client = new Client(authConfig);
GetOrderInfoRequest request = new GetOrderInfoRequest();
request.setRelService("MP"); // MP = mathematical programming service
request.setResourceType(1); // 1 = Local Edition
GetOrderInfoResponse getOrderInfoResponse = client.getOrderInfo(request);
System.out.println(JSON.toJSONString(getOrderInfoResponse.getHeaders()));
System.out.println(JSON.toJSONString(getOrderInfoResponse.getBody()));
} catch (Exception e) {
e.printStackTrace();
}
}
}Query license usage
Use GetOrderUsage to retrieve usage data for your licenses over a specified time range.
Before calling the API, select values for all three parameters:
relService — the service to query:
| Value | Description |
|---|---|
MP | Mathematical programming service |
resourceType — the license edition:
| Value | Description |
|---|---|
1 | Local Edition |
timeRange — the reporting window relative to the current date:
| Value | Description |
|---|---|
1 | One day before and after today |
2 | One week before and after today |
3 | One month before and after today |
package com.alibaba.mind.opt.sdk;
import com.alibaba.fastjson.JSON;
import com.aliyun.opt20210730.Client;
import com.aliyun.opt20210730.models.GetOrderUsageRequest;
import com.aliyun.opt20210730.models.GetOrderUsageResponse;
import com.aliyun.teaopenapi.models.Config;
public class GetOrderUsageExample {
public static void main(String[] args) {
try {
Config authConfig = new Config();
authConfig.accessKeyId = System.getenv("OSS_ACCESS_KEY_ID");
authConfig.accessKeySecret = System.getenv("OSS_ACCESS_KEY_SECRET");
authConfig.endpoint = "opt.cn-hangzhou.aliyuncs.com";
Client client = new Client(authConfig);
GetOrderUsageRequest request = new GetOrderUsageRequest();
request.setRelService("MP"); // MP = mathematical programming service
request.setResourceType(1); // 1 = Local Edition
request.setTimeRange(1); // 1 = one day before and after today
GetOrderUsageResponse listOrderUsage = client.getOrderUsage(request);
System.out.println(JSON.toJSONString(listOrderUsage.getHeaders()));
System.out.println(JSON.toJSONString(listOrderUsage.getBody()));
} catch (Exception e) {
e.printStackTrace();
}
}
}References
Alibaba Cloud Developer Center — SDK downloads, Maven coordinates, pip commands, and version history for all supported languages
Third-party SDKs — community-maintained SDKs for additional languages
Obtain an AccessKey pair — how to create and manage AccessKey credentials