To call Model Studio APIs from a VPC without routing traffic over the public internet, add a PrivateLink connection in the Model Studio console and associate it with your workspace.
How it works
The Model Studio gateway supports the following two access methods:
- Public network access: Call Model Studio APIs over the public MaaS domain name
{WorkspaceId}.{RegionId}.maas.aliyuncs.com. Traffic is routed over the public internet. - PrivateLink private connection: Add a PrivateLink connection for your VPC in the Model Studio console, and then call Model Studio APIs over the private domain name. Traffic stays within the Alibaba Cloud network and does not traverse the public internet.
- China (Beijing)
- China (Shanghai)
- China (Hangzhou)
- China (Shenzhen)
- China (Ulanqab)
- China (Zhangjiakou)
Access Alibaba Cloud Model Studio API through PrivateLink
Step 1: Add a PrivateLink in the Model Studio console
- Log on to the Model Studio console, click set in the upper-right corner of the page, and select 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 internal-facing access section, click Add, configure the following parameters, and keep the other parameters at their default values.
- Region: Select the region based on the Alibaba Cloud Model Studio service region, for example, “China (Beijing)”.
- VPC: Select the VPC that you plan to use to access Alibaba Cloud Model Studio. The PrivateLink is created in this VPC, and only resources in this VPC, such as ECS instances and containers, 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 a zone that is supported by Alibaba Cloud Model Studio and contains vSwitches, and select the corresponding vSwitch. The PrivateLink occupies an internal IP address of the vSwitch in the selected zone, which serves as the internal resolution address of the Model Studio private domain name. You can add up to 2 zone and vSwitch combinations. We recommend adding 2 for high availability: if a zone fails, traffic automatically switches to another zone to avoid service interruption. If no vSwitch is available, click Create Switch to go to the VPC console and create one.
- Security Group: Select the security group to associate with the PrivateLink, which controls who can access the PrivateLink. Therefore, make sure the security group allows access on port 443 (HTTPS) in the inbound direction. If no security group is available, click Create Security Group to go to the ECS console and create one.
- Click confirm and wait until the Status becomes Created. After the addition, it takes about 1 to 3 minutes to take effect. During this period, any cloud server in the VPC can access Model Studio through the private domain name.
Step 2: Associate a workspace
Workspaces that need to access Alibaba Cloud Model Studio through the private network must be associated with the PrivateLink.
- In Workspaces, create a workspace or edit the target workspace.
- In Advanced Configuration, set PrivateLink to the target PrivateLink. The dropdown options display the endpoint IDs together with their regions and VPCs. If the target option is not available, click Create PrivateLink in the dropdown to create one. After the association, the workspace can access Model Studio through the PrivateLink of the corresponding VPC.
- To disassociate the workspace: edit the workspace, clear PrivateLink, and then save; or on the Network configuration page, expand the row of the target PrivateLink, click Unbind in Associated workspaces, and go to the corresponding workspace to process it. A PrivateLink associated with workspaces must be unbound before it can be deleted.
Step 3: Obtain the private domain name
After the association in Step 2 is completed, the system generates a private domain name for each associated workspace. On the Network configuration page, expand the target PrivateLink in the VPC internal-facing access list, obtain the private domain name from the Endpoint column, and view the workspace ID that the domain name belongs to in the Associated workspaces column. The private domain name is in the format {WorkspaceId}-{VpcId}.{region ID}.maas.aliyuncs.com, where WorkspaceId is the workspace ID and VpcId is the ID of the VPC that the PrivateLink belongs to.
In Workspaces, get the private domain name from the API Host column for the target workspace.
The private domain name can only be resolved and accessed within the selected VPC. Alibaba Cloud Model Studio API is called through HTTPS (port 443). If no workspace is associated, the Endpoint column of the expanded row is empty.
Step 4: Call and verify
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 initiate the call in the corresponding VPC.
The following example calls the Qwen text model 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 the call, make sure you have completed Get and configure an API Key. To directly pass in the API Key, 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 this VPC can access Model Studio through the private domain name. If the VPC where the caller's resources are located belongs to another Alibaba Cloud account, you can choose either of the following methods:
- Method 1: VPC sharing: Share the vSwitches of the caller VPC to the Model Studio account, and the PrivateLink is created directly in the caller VPC.
- Method 2: VPC interconnection: The PrivateLink is created in a VPC of the Model Studio account, and the caller VPC accesses the PrivateLink after being connected to the VPC through a VPC peering connection or Cloud Enterprise Network (CEN).
Method 1: VPC sharing
VPC sharing involves two accounts:
- VPC owner account: Owns the VPC and vSwitches, and shares the vSwitches.
- Model Studio account: Accepts the sharing, 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 Share Unit, and complete Configure Basic Info 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 in sequence. What is shared is the vSwitches rather than the entire VPC. For detailed operations, see Share a VPC.
Step 2: The Bailian account accepts the share
Log on to the Resource Sharing console with the Bailian account and accept the share on the Shared with Me page. If the resource share has been automatically associated, you can skip this step.
Step 3: The Bailian account adds a PrivateLink
Log on to the Bailian console and add a PrivateLink by following Step 1 in this topic. Note the following during the configuration:
- Region: Select the region where the shared VPC resides, and make sure that the region supports internal-facing access to Bailian.
- VPC: Select the shared VPC.
- Zones and Switches: Select the shared vSwitch under the shared VPC.
- Security Group: Select an available security group in the shared VPC, and make sure that the inbound direction allows the caller resources to access port 443.
Step 4: Complete the subsequent configuration and make calls
After the PrivateLink is created, associate a workspace and obtain the private domain name by following Step 2, Step 3, and Step 4 in this topic. The caller makes calls within the shared VPC by using the private domain name and the workspace API Key.
Method 2: VPC interconnection
VPC interconnection involves two accounts:
- Bailian account: Creates a PrivateLink in its own VPC (referred to as the Bailian VPC) and associates the workspace.
- Caller account: Owns the VPC where the caller resources reside (referred to as the caller VPC).
Step 1: Connect the networks
Connect the Bailian VPC and the caller VPC by using one of the following methods. 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
- 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 own VPCs, with the destination CIDR block set to the CIDR block of the peer VPC and the next hop set to the peering connection.
-
Cloud Enterprise Network
- Either account creates a Cloud Enterprise Network (CEN) instance and creates a transit router in the region where the VPC resides.
- The peer account authorizes its VPC to the CEN instance.
- Create a VPC connection for each of the two VPCs in the transit router to attach both VPCs to the same transit router.
Step 2: Allow traffic in the PrivateLink security group
After the networks are connected, the caller can access the PrivateLink only after being allowed by the PrivateLink security group. 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 VPC, such as 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 private domain name and the workspace API Key to the caller account, and the resources in the caller VPC make calls by following Step 4 in this topic. If a connection timeout error such as Failed to connect to <private 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 calling fees are borne by the account that creates the PrivateLink, regardless of which account the VPC belongs to. For the billing of VPC peering connections and Cloud Enterprise Network, see VPC peering connection and CEN billing rules.
FAQ
-
Why can't my ECS instance access Model Studio APIs over the PrivateLink connection?
Troubleshoot as follows:
- Check whether the ECS instance is in the same VPC as the PrivateLink connection. If the VPC of the ECS instance is different from the VPC where the PrivateLink is configured, you cannot access the Alibaba Cloud Bailian API over the private network. You must first configure VPC interconnection, such as a VPC peering connection or Cloud Enterprise Network, and allow traffic in the PrivateLink security group. For more information, see Method 2: VPC interconnection.
- Check the security group associated with the PrivateLink and make sure that an inbound rule is added to allow access to port 443 (HTTPS) from the CIDR block where the initiating ECS instance resides.
- Check the status of the PrivateLink. The private domain name can be used only after the connection status is Created and the connection has taken effect (about 1 to 3 minutes after creation).
- Check whether the workspace is associated. A private domain name is generated only after a workspace is associated with the PrivateLink connection. If the Endpoint column in the expanded row is empty, associate the workspace as described in Step 2.
- Can an endpoint be accessed from the public internet? No. PrivateLink establishes private connections only within the Alibaba Cloud network. Endpoints cannot be accessed from the public internet, and endpoint ENIs cannot be associated with elastic IP addresses (EIPs).
-
Do I need to associate a workspace with a legacy PrivateLink connection?
No. A legacy PrivateLink connection, which was created as an interface endpoint in the PrivateLink (VPC) console, is associated with all workspaces by default. You can use it to access Model Studio APIs over the private network without performing Step 2.
On the Network configuration page, expand an existing PrivateLink; the Endpoint column displays
vpc-{Region ID}.dashscope.aliyuncs.com(for example,vpc-cn-beijing.dashscope.aliyuncs.com), and the Associated workspaces column shows all workspaces; this differs from the new process, which lists{WorkspaceId}-{VpcId}.{Region ID}.maas.aliyuncs.comseparately for each workspace. You can no longer create a PrivateLink connection in this way. To add one, follow Step 1 to create it in the Model Studio console, and then follow Step 2 to associate the workspaces that need private network access.