Install PAI SDK for Python and configure workspace credentials and region settings to train and deploy models.
Prerequisites
You have obtained an AccessKey pair.
You have created a workspace.
You have created an OSS bucket.
-
Python 3.8 or later.
-
RAM users require permissions on workspace and Object Storage Service (OSS) buckets:
-
Assign developer or administrator role to submit training jobs. For more information, see Manage members of the workspace.
-
Grant read and write permissions to store code and models in OSS buckets. For more information, see "Grant your RAM user or RAM role the permissions to access OSS" in Grant the permissions that are required to use Machine Learning Designer.
-
Installation
Install PAI SDK for Python:
pip install "alipai>=0.4.0"
Configuration
Configure workspace credentials and region settings:
# Run after SDK installation.
python -m pai.toolkit.config
Configuration example:

Upon successful configuration, the system displays: Configuration saved successfully: <Path to which the configurations are saved>.
Configuration parameters
The configuration wizard prompts for the following parameters:
Available regions
Supported region IDs for region_id parameter:
Cross-region configuration
Programmatic configuration for cross-region scenarios, such as deploying EAS services in a different region from workspace:
from pai.session import Session
# Initialize session with US region
session = Session(
workspace_id="12345",
region_id="us-southeast-1", # EAS service deployed in US region
oss_bucket_name="my-pai-bucket"
)
# Deploy model to EAS service in us-southeast-1
from pai.model import Model
model = Model(
model_data="oss://my-pai-bucket/models/my_model/",
session=session
)
# Deploy with region-specific configuration
predictor = model.deploy(
service_name="my-service",
instance_type="ecs.g6.xlarge",
options={
"metadata.region": "us-southeast-1" # Explicit region specification
}
)
Note: Ensure OSS bucket and EAS service are in the same region for optimal performance. Cross-region data transfer may incur additional latency and costs.
Next steps
After configuration, submit training jobs. For more information, see Submit a training job.