Configure your credentials and create your first DSW instance with PAI CLI.
Prerequisites
An Alibaba Cloud account and an AccessKey pair.
Step 1: Configure access credentials
If this is your first time setting up PAI CLI, use Method 1: Interactive setup (recommended). It validates your credentials before writing them to the configuration file. For advanced options such as multi-profile management, STS or ECS RAM Role authentication, and endpoint configuration, see Configuration management.
An AccessKey is sensitive information. Don't commit it to a code repository or share it with others. Alternatively, store credentials in the environment variables PAI_ACCESS_KEY_ID and PAI_ACCESS_KEY_SECRET instead of the configuration file.
Method 1: Interactive setup (recommended)
pai config init
Method 2: Set values directly
# Set AccessKey credentials (for scripted scenarios)
pai config set access_key_id LTAI5xxxxxxxxxxxxx
pai config set access_key_secret xxxxxxxxxxxxxxxxxxxxxxxx
# Set the default region
pai config set region cn-hangzhou
# Set the default workspace (optional; omit --workspace-id in later commands)
pai config set workspace_id ws-xxxxxxxxxxxxx
Step 2: Verify the configuration
To verify the configuration:
# View the effective configuration and the source of each value
pai config show
# List accessible workspaces
pai workspace list
Step 3: View available resources
Check which GPU instance types and preset images are available:
# List available GPU ECS instance types
pai dsw instance list-ecs-specs --accelerator-type GPU
# List available preset images
pai image list --type preset
Step 4: Create a DSW instance
Create a GPU instance with the following command:
# Create a GPU instance (pay-as-you-go)
pai dsw instance create \
--name my-first-instance \
--ecs-spec ecs.gn7i-c8g1.2xlarge \
--image image-fp32i3q6aq8wwfuwkf
Instance creation typically takes 2–5 minutes. Run pai dsw instance wait <instance-id> --for Running to monitor progress. The command returns when the instance reaches the Running state.
Step 5: Run commands and clean up
# Run a command on the instance
pai dsw instance exec <instance-id> -- nvidia-smi
# Stop the instance when you're done (no charges after stop)
pai dsw instance stop <instance-id>
# Or delete the instance
pai dsw instance delete <instance-id> -y
What's next
Explore the full PAI CLI command reference, including global parameters, request body overrides, and exit codes, in Command reference.