# pai-schedule

Part of **PAI**

# Platform for AI (PAI) Schedule Management

## Capabilities Overview

| Sub-capability | Calling Mode | Description |
|----------------|--------------|-------------|
| Manage Schedules | Synchronous | Delete schedules. |

## API Calling Patterns

### Authentication
The primary authentication method is **Bearer Token** via the `Authorization` header.

- Include the header: `Authorization: Bearer <your_api_key>`
- Store your API key in the environment variable: `DASHSCOPE_API_KEY`
- While other Alibaba Cloud authentication methods exist (e.g., AccessKey), the Bearer Token pattern is used consistently across PAI Plugin APIs and is recommended for simplicity.

### Service Endpoint
The API uses region-agnostic global endpoints with two variants:

- China region: `https://api.aliyun.com/api/PaiPlugin/2022-01-12/schedules/{Id}`
- International region: `https://api.alibabacloud.com/api/PaiPlugin/2022-01-12/schedules/{Id}`

Both endpoints support the same functionality. Choose based on your deployment region.

### Synchronous Request Pattern
All schedule management operations use a **Synchronous** calling mode:
1. Send an HTTP request (e.g., DELETE) directly to the resource endpoint.
2. The server processes the request immediately.
3. A complete JSON response is returned in the same connection.
4. No polling or async result fetching is required.

For deletion, send a `DELETE` request to `/schedules/{Id}`. The response indicates success or failure instantly.

## Parameter Reference

### Manage Schedules

| Parameter | Type | Required | Default | Constraints | Description |
|-----------|------|----------|---------|-------------|-------------|
| Id | string | false | — | — | The schedule ID. For more information, see ListSchedules. |

## Code Examples

### Delete a Schedule - curl - all

```bash
curl -X DELETE https://api.aliyun.com/api/PaiPlugin/2022-01-12/schedules/0bddaf8f-5628-427a-8652-5e24f6b4c35d
```

### Delete a Schedule with Authentication - curl - all

```bash
curl -X DELETE \
  https://api.aliyun.com/api/PaiPlugin/2022-01-12/schedules/0bddaf8f-5628-427a-8652-5e24f6b4c35d \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY"
```

### Delete a Schedule (International Endpoint) - curl - all

```bash
curl -X DELETE \
  https://api.alibabacloud.com/api/PaiPlugin/2022-01-12/schedules/0bddaf8f-5628-427a-8652-5e24f6b4c35d \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY"
```

### Python Example Using requests - Python - all

```python
import os
import requests

schedule_id = "0bddaf8f-5628-427a-8652-5e24f6b4c35d"
url = f"https://api.aliyun.com/api/PaiPlugin/2022-01-12/schedules/{schedule_id}"
headers = {
    "Authorization": f"Bearer {os.getenv('DASHSCOPE_API_KEY')}"
}

response = requests.delete(url, headers=headers)
print(response.json())
```

## Response Format

```json
{
  "Data": "OK",
  "ErrorCode": 0,
  "ErrorMessage": "OK",
  "RequestId": "f8651828-609d-4de8-ab49-ab781d7fd85a"
}
```

**Key Fields**:
- `Data` — Operation result payload (typically "OK" on success)
- `ErrorCode` — Numeric error code (0 indicates success)
- `ErrorMessage` — Human-readable error message
- `RequestId` — Unique identifier for troubleshooting

## Error Handling

| Error Code | Description | Recommended Action |
|------------|-------------|---------------------|
| 400 | Bad Request - The request parameters are invalid or missing. | Verify the schedule ID format and ensure it is provided in the path. |
| 404 | Not Found - The specified schedule ID does not exist. | Confirm the schedule exists by calling ListSchedules first. |
| 500 | Internal Server Error - An unexpected error occurred on the server side. | Retry the request after a short delay; if persistent, contact support with the RequestId. |

## Pricing & Billing

### Billing Model
Per-request billing: each API call (successful or failed) is counted as one request.

### Price Reference

| Tier | Input Price | Output Price |
|------|-------------|--------------|
| standard | 0.001 / | 0.001 / |

### Free Tier
1000 free calls per month.

### Usage Limits
100 QPS (queries per second).

### Billing Notes
Each request is billed regardless of success or failure. Failed requests still consume quota.

## FAQ

Q: How do I find the schedule ID to delete?
A: Use the ListSchedules API (not covered in this skill) to retrieve existing schedule IDs before deletion.

Q: Is there a way to delete multiple schedules at once?
A: No, the current API only supports deleting one schedule per request. You must issue separate DELETE calls for each schedule.

Q: What happens if I try to delete a non-existent schedule?
A: The API returns a 404 error with "Not Found". Your application should handle this gracefully.

Q: Do I need special permissions to delete a schedule?
A: Yes, your API key must have appropriate RAM permissions for the PAI Plugin service. Ensure your Alibaba Cloud account has `pai:DeleteSchedule` permission.

Q: Can I restore a deleted schedule?
A: No, schedule deletion is permanent. There is no built-in recovery mechanism—ensure you really want to delete before calling the API.