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.
-
Public cloud: China (Beijing), Hong Kong (China), Singapore.
Private network access is not currently supported in other regions.
Access Alibaba Cloud Model Studio APIs through a private connection
Step 1: Add PrivateLink in the Model Studio console
- Log on to the Model Studio console. In the left-side navigation pane, choose Manage > Network configuration.
-
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.
- Authorize service-linked role for PrivateLink: Click Authorize Now to automatically create the service-linked role
-
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.
- 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.
- In Workspaces, create a workspace or edit an existing one.
- 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.
- 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.
In Workspaces, find the private domain name in the API Host column for your 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
HTTP
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.
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.
Step 1: The VPC owner account shares the vSwitches
Log on to the Resource Sharing console, click Create a resource share, and complete the following steps in sequence: Configure basic information and add resources (add the vSwitch to share), add permission (select AliyunRSDefaultPermissionVSwitch), add principal (enter the UID of the Bailian account), and Confirm and submit. You share the vSwitch, not the entire VPC. For detailed operations, see Share a 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.
Step 3: The Model Studio account adds a PrivateLink
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.
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).
Step 1: Connect the networks
Use either of the following methods to connect the Bailian VPC and the caller VPC. The CIDR blocks of the two VPCs cannot overlap. For a comparison of the two methods in terms of selection and billing, see VPC interconnection overview.
-
VPC peering connection
- 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.
- The peer account accepts the connection on the VPC peering connection page in the VPC console.
- 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.
-
Cloud Enterprise Network (CEN)
- Use either account to create a Cloud Enterprise Network (CEN) instance, and create a transit router in the region where the VPC resides.
- The peer account authorizes its VPC to the CEN instance.
- In the transit router, create a VPC connection for each of the two VPCs to attach both VPCs to the same transit router.
Step 2: Allow traffic through the PrivateLink security group
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:
| Parameter | Value |
|---|---|
| Authorization policy | Allow |
| Protocol Type | Custom TCP |
| Port range | 443 |
| Authorization object | The 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 |
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 <私网域名> 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 to understand and evaluate the costs.
The PrivateLink and model invocation 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
-
Why cannot my ECS instance access the Alibaba Cloud Bailian API through PrivateLink?
Troubleshoot the issue by following these steps:
- Confirm whether they are in the same VPC. If the VPC of the ECS instance is different from the VPC where PrivateLink is configured, you cannot access Alibaba Cloud Bailian APIs over the private network. You must first configure VPC interconnection, such as a VPC peering connection or Cloud Enterprise Network (CEN), and allow the PrivateLink security group. For more information, see Method 2: VPC interconnection.
- Check the security group associated with the PrivateLink and confirm that an inbound rule has been added to allow access from the CIDR block of the initiating ECS instance to port 443 (HTTPS).
- 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).
- 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.
- 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.
-
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 examplevpc-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.comfor 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.