All Products
Search
Document Center

Alibaba Cloud Model Studio:Access Alibaba Cloud Model Studio model or application APIs through an endpoint over a private network

Last Updated:Nov 20, 2026

To directly call Alibaba Cloud Model Studio model or application APIs from within a VPC and ensure that traffic does not traverse the public internet, you can add a private connection in the Model Studio console to keep all communication entirely within the Alibaba Cloud internal network.

How it works

The Model Studio gateway supports the following two access methods:

  • Public internet access: Directly access the public MaaS domain {WorkspaceId}.{RegionId}.maas.aliyuncs.com, and the traffic reaches Model Studio over the public internet.
  • PrivateLink connection: After you add a private connection for the VPC in the Model Studio console, you can access Model Studio through the private domain name, and the traffic travels entirely over the Alibaba Cloud internal network without passing through the public internet.

After you add a private connection in the Model Studio console, the Alibaba Cloud PrivateLink service establishes a private connection (endpoint connection) between your VPC and Alibaba Cloud Model Studio. This connection is one-way by design: it only allows resources in your VPC to proactively access Alibaba Cloud Model Studio, and Alibaba Cloud Model Studio cannot access resources in your VPC through this connection in the reverse direction.

When compute resources in the VPC access the private domain name, the traffic is forwarded to the Alibaba Cloud Model Studio service through PrivateLink and does not traverse the public internet.

image

Regions where Alibaba Cloud Model Studio is available:

  • Public cloud: China (Beijing) and Hong Kong (China).

    Private network access is not currently supported in other regions.

Access Alibaba Cloud Model Studio APIs through a private connection

  1. Log on to the Model Studio console. In the left-side navigation pane, choose Manage > Network configuration.

  2. On first use, follow the instructions in the Add PrivateLink panel to complete the following preparations:

    • Authorize service-linked role for PrivateLink: Click Authorize Now to automatically create the service-linked role AliyunServiceRoleForBackrouterAccessNet.
    • Activate PrivateLink: Click Activate Now to activate the PrivateLink service.
  3. In the VPC private network access section, click Add and configure the following parameters. You can keep the default values for other parameters.

    • Region: Select the region based on the Alibaba Cloud Model Studio service region, for example "Hong Kong (China)".
    • VPC: Select the VPC that you plan to use to access Alibaba Cloud Model Studio. The private connection will be created in this VPC, and only resources such as ECS instances and containers in this VPC can access Alibaba Cloud Model Studio through the private domain name. If no VPC is available, click Create VPC to go to the VPC console and create one. To use a VPC shared by another account, directly select the shared VPC. For more information, see Cross-account access.
    • Zones and Switches: Select the zones supported by Alibaba Cloud Model Studio that contain switches, along with the corresponding switches. The private connection occupies one internal IP address of the switch in the selected zone as the internal resolution address of the Model Studio private domain name. You can add up to 2 zone and switch combinations. We recommend adding 2 for high availability: when one zone fails, traffic can automatically switch to another zone to avoid service interruption. If no switch is available, click Create Switch to go to the VPC console and create one.
    • Security Group: Select the security group to associate with the private connection, which controls who can access the private connection. Therefore, make sure that the security group allows inbound access on port 443 (HTTPS). If no security group is available, click Create Security Group to go to the Elastic Compute Service (ECS) console and create one.
  4. Click confirm and wait until the Status becomes Created. After the addition is complete, the configuration is expected to take effect within 1 to 3 minutes. Once it takes effect, any cloud server in the VPC can access the Model Studio service through the private domain name.

Step 2: Associate workspaces

A workspace that needs to access Alibaba Cloud Model Studio over a private network must be associated with a private connection.

  1. In the left-side navigation pane of the Model Studio console, choose Workspaces, and create a workspace or edit the target workspace.
  2. In Advanced Configuration, set Private connection to the target private connection. The drop-down options show the endpoint ID together with its region and VPC. If no target option is available, click Create private connection in the drop-down list to create one. After the association, the workspace can access the Model Studio service through the private connection of the corresponding VPC.
  3. To remove the association: edit the workspace, clear Private connection, and save the changes; or on the Network configuration page, expand the row of the target private connection, click Unbind in Associated Workspaces, and you will be redirected to the corresponding workspace to complete the operation. A private connection associated with workspaces must be unbound before it can be deleted.

Step 3: Obtain the private domain name

After completing the association in Step 2, the system generates a private domain name for each associated workspace. On the Network configuration page, expand the target private connection in the VPC private network access list, and obtain the private domain name from the Endpoint column. The Associated Workspaces column shows the ID of the workspace to which the domain name belongs. The private domain name is in the format of {WorkspaceId}-{VpcId}.{RegionId}.maas.aliyuncs.com, where WorkspaceId is the workspace ID and VpcId is the ID of the VPC to which the private connection belongs.

You can also choose Workspaces in the left-side navigation pane and view the private network domain name in the API Host column of the target workspace.

The private domain name can be resolved and accessed only within the selected VPC, and you call Alibaba Cloud Model Studio APIs over HTTPS (port 443). If no workspace is associated, the Endpoint column of the expanded row is empty.

Step 4: Verify API calls

Replace the domain name in the base_url of the Alibaba Cloud Model Studio API with the private domain name obtained in the previous step, and then make the calls from the corresponding VPC.

The following example shows how to call Qwen text models in OpenAI-compatible mode:

  • Before replacement: https://{WorkspaceId}.{RegionId}.maas.aliyuncs.com/compatible-mode/v1/chat/completions
  • After replacement: https://{WorkspaceId}-{VpcId}.{RegionId}.maas.aliyuncs.com/compatible-mode/v1/chat/completions

Calling example:

# 将原始域名替换为上一步骤中获取到的私网域名
curl -X POST https://{WorkspaceId}-{VpcId}.{RegionId}.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen-flash",
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful assistant."
        },
        {
            "role": "user",
            "content": "你是谁?"
        }
    ]
}'
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 将原始域名替换为上一步骤中获取到的私网域名
    base_url="https://{WorkspaceId}-{VpcId}.{RegionId}.maas.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
    model="qwen-flash",
    messages=[
        {'role': 'system', 'content': 'You are a helpful assistant.'},
        {'role': 'user', 'content': '你是谁?'}],
)
print(completion.model_dump_json())
import os
# We recommend using dashscope SDK version >= 2.0.1
import dashscope
from dashscope import DashScopeError
# Configure the private endpoint: replace the original domain with the private domain obtained in the previous step
client = dashscope.Client(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://{WorkspaceId}-{VpcId}.{RegionId}.maas.aliyuncs.com/api/v1",
)
messages = [{
    'role': 'user', 'content': '你是谁?'
}]
try:
    response = client.chat.completions.create(
        model="qwen-flash",
        messages=messages,
    )
    print(response)
except DashScopeError as e:
    print(f"HTTP status code: {e.status_code}")
    print(f"Error code: {e.code}")
    print(f"Error message: {e.message}")
    print("See: https://www.alibabacloud.com/help/model-studio/developer-reference/error-code")
// 建议DashScope SDK的版本 >= 2.12.0
import java.util.Arrays;
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.protocol.Protocol;
import com.alibaba.dashscope.utils.JsonUtils;
public class Main {
    public static GenerationResult callWithMessage() throws ApiException, NoApiKeyException, InputRequiredException {
        // 将原始域名替换为上一步骤中获取到的私网域名
        Generation gen = new Generation(Protocol.HTTP.getValue(), "https://{WorkspaceId}-{VpcId}.{RegionId}.maas.aliyuncs.com/api/v1");
        Message systemMsg = Message.builder()
                .role(Role.SYSTEM.getValue())
                .content("You are a helpful assistant.")
                .build();
        Message userMsg = Message.builder()
                .role(Role.USER.getValue())
                .content("你是谁?")
                .build();
        GenerationParam param = GenerationParam.builder()
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .model("qwen-flash")
                .messages(Arrays.asList(systemMsg, userMsg))
                .resultFormat(GenerationParam.ResultFormat.MESSAGE)
                .build();
        return gen.call(param);
    }
    public static void main(String[] args) {
        try {
            GenerationResult result = callWithMessage();
            System.out.println(JsonUtils.toJson(result));
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            // 打印错误信息
            System.err.println("An error occurred while calling the generation service: " + e.getMessage());
        }
    }
}

Before making calls, make sure you have completed Get and configure API Key. To pass the API Key directly, replace $DASHSCOPE_API_KEY with your API Key.

Cross-account access

By default, a PrivateLink can only be created in a VPC of the current account, and only resources in that VPC can access Model Studio via the private domain name. If the VPC where the caller's resources reside belongs to another Alibaba Cloud account, you can choose either of the following methods:

  • Method 1: VPC sharing: Share the vSwitches of the caller's VPC with the Model Studio account, and the PrivateLink is created directly in the caller's VPC.
  • Method 2: VPC interconnection: The PrivateLink is created in a VPC owned by the Model Studio account, and the caller's VPC accesses it after being interconnected with that VPC via a VPC peering connection or Cloud Enterprise Network.

Neither method requires sharing the PrivateLink itself between accounts. When the caller is not the Model Studio account, the Model Studio account provides the private domain name and a workspace API Key to the caller.

Method 1: VPC sharing

VPC sharing involves two accounts:

  • VPC owner account: Owns the VPC and vSwitches, and is responsible for sharing the vSwitches.
  • Model Studio account: Accepts the share, and adds a PrivateLink and associates a workspace in the Model Studio console.

The PrivateLink is created in the shared VPC, and resources of either account in that VPC can use this connection. Alternatively, the VPC owner account can create the PrivateLink in that VPC itself for use by other accounts in the shared VPC. In either case, the PrivateLink fees are borne by the account that creates the PrivateLink. The following uses a PrivateLink created by the Model Studio account as an example.

Step 1: The VPC owner account shares the vSwitches

Log on to the Resource Sharing console, click Create Share Unit, and complete the following steps in sequence: Configure Basic Information and Add Resources (add the vSwitches to share), add permission (select AliyunRSDefaultPermissionVSwitch), add principal (enter the UID of the Model Studio account), and Confirm and Submit. You share vSwitches, not the entire VPC. For detailed operations, see Shared VPC.

Step 2: The Model Studio account accepts the share

Log on to the Resource Sharing console with the Model Studio account, and accept the share on the Shared with Me page. If the share unit has been automatically associated, you can skip this step.

Log on to the Model Studio console, and add a PrivateLink following Step 1 in this topic. Note the following when configuring:

  • Region: Select the region where the shared VPC resides, and make sure the region supports Model Studio private network access, for example China (Beijing) or Hong Kong (China).
  • VPC: Select the shared VPC.
  • Zones and Switches: Select a shared vSwitch under the shared VPC.
  • Security Group: Select a security group available in the shared VPC, and make sure the inbound direction allows the caller's resources to access port 443.

Other parameters are the same as those in the same-account procedure.

Step 4: Complete subsequent configuration and make calls

After the PrivateLink is created, associate a workspace and obtain the private domain name following Step 2, Step 3, and Step 4 in this topic. The caller makes calls within the shared VPC using the private domain name and the workspace API Key.

Method 2: VPC interconnection

VPC interconnection involves two accounts:

  • Model Studio account: Creates a PrivateLink in its own VPC (hereinafter the Model Studio VPC) and associates a workspace.
  • Caller account: Owns the VPC where the caller's resources reside (hereinafter the caller VPC).

After VPC interconnection, the networks of the two VPCs are connected bidirectionally, and either account can create a PrivateLink in its own VPC for the other account to call. That is, both accounts can act as the Model Studio account.

Step 1: Connect the networks

Use either of the following methods to connect the Model Studio VPC and the caller VPC. The CIDR blocks of the two VPCs must not overlap. For a comparison of the two methods in terms of selection and billing, see VPC interconnection overview.

  • VPC peering connection
    1. Either account creates a peering connection in the VPC console, selects Cross-account for Receiver account type, and enters the peer account UID and peer VPC ID.
    2. The peer account accepts the connection on the VPC peering connection page in the VPC console.
    3. Both accounts add routes to the route tables of their respective VPCs, with the destination CIDR block set to the peer VPC CIDR block and the next hop set to the peering connection.

    For detailed operations, see VPC peering connection.

  • Cloud Enterprise Network
    1. Use either account to create a Cloud Enterprise Network (CEN) instance, and create a transit router in the region where the VPC resides.
    2. The peer account authorizes its VPC to the CEN instance.
    3. In the transit router, create a VPC connection for each of the two VPCs to attach both VPCs to the same transit router.

    For detailed instructions, see Use enterprise edition transit routers to connect VPCs across regions and accounts.

After the network connectivity is established, the caller still needs to be allowed by the PrivateLink security group before it can access PrivateLink. The Bailian account adds the following inbound rule to the security group associated with the PrivateLink:

ParameterValue
Authorization policyAllow
Protocol TypeCustom TCP
Port range443
Authorization objectThe CIDR block of the caller's VPC, for example 192.168.0.0/16. You can view it on the VPC details page in the VPC console

If traffic is not allowed, calls will time out even after the network connectivity is established.

Step 3: Make calls

The Bailian account provides the internal domain name and the workspace API Key to the caller account, and resources in the caller's VPC make calls by following Step 4 of this topic. If a connection timeout error such as Failed to connect to <internal domain name> port 443 is returned, check the network configuration in Step 1 and the security group rules in Step 2.

Billing Details

Using PrivateLink incurs additional fees. You can refer to PrivateLink billing details to understand and evaluate the costs.

The PrivateLink and model call fees are borne by the account that created the PrivateLink, regardless of which account the VPC belongs to. For the billing of VPC peering connections and Cloud Enterprise Network (CEN), see VPC peering connection and CEN billing rules.

FAQ

  1. Why cannot my ECS instance access the Alibaba Cloud Bailian API through PrivateLink?

    Troubleshoot the issue by following these steps:

    1. Confirm whether they are in the same VPC.

      If the VPC of the ECS instance is different from the VPC where PrivateLink is configured, the ECS instance cannot access the Alibaba Cloud Bailian API over the private network. You need to first configure VPC interconnection, such as a VPC peering connection or CEN, and allow traffic through the PrivateLink security group. For details, see Method 2: VPC interconnection.

    2. Check the security group associated with the PrivateLink, and confirm that an inbound rule has been added to allow access to port 443 (HTTPS) from the CIDR block where the initiator ECS instance resides.

    3. Confirm the PrivateLink status.

      You can access the Alibaba Cloud Bailian API through the internal domain name only after the PrivateLink status is Created and the connection takes effect (an expected delay of 1 to 3 minutes after creation).

    4. Confirm that the workspace has been associated.

      The internal domain name is generated only after the workspace is associated with the PrivateLink. If the Endpoint column in the expanded row is empty, follow Step 2 to associate the workspace first.

  2. Can the endpoint be accessed from the public network?

    No. PrivateLink is used only to establish private connections over the Alibaba Cloud internal network. Endpoints do not support public network access, and the endpoint network interface cannot be bound with an elastic public IP (EIP) either.

  3. Do existing PrivateLink connections created by the old method still need to be associated with a workspace?

    No. Existing PrivateLink connections established by creating interface endpoints in the PrivateLink (VPC) console are associated with all workspaces by default, and can be directly used to access the Alibaba Cloud Bailian API over the private network without performing Step 2.

    On the Network configuration page, expand an existing PrivateLink connection: the Endpoint column displays vpc-{region ID}.dashscope.aliyuncs.com (for example vpc-ap-southeast-1.dashscope.aliyuncs.com), and the Associated workspaces column shows all workspaces; this differs from the new process, which displays {WorkspaceId}-{VpcId}.{region ID}.maas.aliyuncs.com for each workspace.

    The old method no longer supports creating new PrivateLink connections. To add a new one, follow Step 1 to create it in the Bailian console, and follow Step 2 to associate the workspaces that require private network access.