
Alibabacloud Bailian Videoanalysis
- 154 installs
- 208 repo stars
- Updated August 4, 2026
- aliyun/alibabacloud-aiops-skills
Integrate Alibaba Cloud Bailian video analysis APIs into apps and agent workflows for scene detection, summarization, tagging, and downstream automation triggers.
About
Build-time integration skill for Alibaba Cloud Bailian video analysis. Enables developers and agents to send video assets, interpret model outputs, and connect insights to product features or automated downstream actions.
- Bailian video API request shaping
- Auth, quotas, and regional endpoint setup
- Structured parsing of analysis outputs
- Pipeline hooks for alerts and workflows
- Error handling for async video jobs
Alibabacloud Bailian Videoanalysis by the numbers
- 154 all-time installs (skills.sh)
- Ranked #3,298 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/aliyun/alibabacloud-aiops-skills --skill alibabacloud-bailian-videoanalysisAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 154 |
|---|---|
| repo stars | ★ 208 |
| Last updated | August 4, 2026 |
| Repository | aliyun/alibabacloud-aiops-skills ↗ |
What it does
Integrate Alibaba Cloud Bailian video analysis APIs into apps and agent workflows for scene detection, summarization, tagging, and downstream automation triggers.
Files
Bailian Video Analysis
This skill provides video analysis functionality based on Alibaba Cloud Bailian Video Analysis Light Application. It uses the Bailian (QuanMiaoLightApp) API for intelligent video comprehension, including shot analysis, ASR transcription, title generation, caption extraction, and mind mapping.
Architecture: CLI (Credential Chain) + OSS (File Storage) + Bailian Workspace + Quanmiao Video Analysis Service + Python SDK Scripts
---
Output Language Policy
Detection Priority: User input language → Environment language → Default: Chinese (中文)
Apply to: All user-facing messages, summaries, error explanations, and interactive prompts.
Keep original language: Code snippets, API responses, file paths, technical identifiers, HTTP status codes.
---
Installation
1. Python Dependencies
python -m pip install -r scripts/requirements.txt
# On some systems, use pyhon3 instead of python2. Alibaba Cloud CLI
Pre-check: Aliyun CLI >= 3.3.1 required
Run aliyun version to verify >= 3.3.1. If not installed or version too low,see references/cli-installation-guide.md for installation instructions.Then [MUST] run aliyun configure set --auto-plugin-install true to enable automatic plugin installation.AI-Mode Configuration for aliyun CLI
>
When using the aliyun CLI in this skill, you MUST configure AI-Mode settings:
>
```bash
# Enable AI-Mode (required before using CLI commands)
aliyun configure ai-mode enable
>
# Set User-Agent for tracking (required)
aliyun configure ai-mode set-user-agent AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysis
>
# Update plugins to latest versions (recommended)
aliyun plugin update
```
>
Note: After completing your tasks, you can disable AI-Mode:
```bash
aliyun configure ai-mode disable
```
3. Important Prerequisite: Activate Bailian and Video Analysis Service
Before using this skill, you must first activate the Video Analysis service in the Alibaba Cloud Bailian console!
1. Visit Bailian Video_Analysis page 2. Click the "Paid activation" button 3. Confirm activation and wait for the service to take effect (usually 1-2 minutes)
4. Important Prerequisite: Guide Users to Grant Permissions in Alibaba Cloud Access Control and Bailian
Before using this skill, you must grant the following permissions to the previously configured AK, otherwise calls will fail and may cause 403 errors
1) RAM Permission Grant
See references/ram-policies.md for the full list of required RAM permissions and authorization instructions.
[MUST] Permission Failure Handling: When any command or API call fails due to permission errors at any point during execution, follow this process:
1. Read references/ram-policies.md to get the full list of permissions required by this SKILL2. Use ram-permission-diagnose skill to guide the user through requesting the necessary permissions3. Pause and wait until the user confirms that the required permissions have been granted
2) Bailian Workspace Permission Grant
1. Visit Alibaba Cloud Bailian Permission Management 2. If the RAM user corresponding to the AK does not exist, click "Add User" in the upper right corner of the page, select the corresponding RAM user and click confirm to add. 3. There is a 30s effective time after configuration, please wait patiently for a while.
---
Authentication
Pre-check: Alibaba Cloud Credentials Required
>
Security Rules:
- NEVER read, echo, or print AK/SK values (e.g., echo $ALIBABA_CLOUD_ACCESS_KEY_ID is FORBIDDEN)- NEVER ask the user to input AK/SK directly in the conversation or command line
- NEVER use aliyun configure set with literal credential values- ONLY use aliyun configure list to check credential status>
```bash
aliyun configure list
```
Check the output for a valid profile (AK, STS, or OAuth identity).
>
If no valid profile exists, STOP here.
1. Obtain credentials from Alibaba Cloud Console
2. Configure credentials outside of this session (via aliyun configure in terminal or environment variables in shell profile)3. Return and re-run after aliyun configure list shows a valid profile---
Parameter Confirmation
IMPORTANT: Parameter Confirmation — Before executing any command or API call,
confirm user-provided or customizable parameters (video source, OSS bucket, oss object key).
System-auto-resolved parameters (workspace_id, default OSS bucket) do NOT
require explicit confirmation unless the user wants to override them.
| Parameter | Type | Description | Default / Resolution |
|---|---|---|---|
video_source | Required | Local file path OR downloadable video URL | N/A (user must provide) |
workspace_id | Auto-resolved | Bailian workspace ID | Auto-detected(user may override) |
ossBucket | Optional | OSS bucket name for file upload | Auto-detect from first available bucket; user may specify (e.g. --ossBucket my-bucket) |
ossObjectKey | Optional | OSS object key for the uploaded file | /temp/quanmiao/YYYYMMDD/filename |
expireSeconds | Optional | Temporary URL expiration time (seconds) | 14400 (4 hours) |
Confirmation Workflow: 1. Auto-detection first: The skill will auto-detect workspace_id and ossBucket when possible 2. User override: If user wants to specify custom values, confirm before using 3. Local vs URL: Confirm whether user is providing a local file path or a public URL
---
Core Workflow
⚠️ CRITICAL: Cloud API Mandatory — This skill MUST use Bailian (QuanMiaoLightApp) API for video analysis. Local tools (ffmpeg, whisper, OpenCV, ffprobe, mediainfo, etc.) are FORBIDDEN. If API calls fail due to credentials or permissions, follow Permission Failure Handling process — DO NOT fall back to local analysis.
Step 1: Environment Check
Run python scripts/check_env.py to verify:
- Python packages are installed
- Credentials are configured via default credential chain
If check_env.py fails or returns {"ready": false}:
- Packages missing → Run
python -m pip install -r scripts/requirements.txt - Credentials missing or invalid → Follow Permission Failure Handling process:
1. Read references/ram-policies.md to get required permissions 2. Use ram-permission-diagnose skill to guide user through permission request 3. Wait for user confirmation before proceeding 4. DO NOT proceed with local analysis tools
Expected output: {"ready": true} indicates environment is properly configured.
Step 2: Get Workspace ID
Do not ask the user for workspace_id upfront. Always auto-fetch available workspaces first:
aliyun modelstudio list-workspaces --user-agent AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysisWorkspace selection logic:
- Single workspace returned → use it directly, no need to prompt the user
- Multiple workspaces returned → display a numbered list and proceed with the following:
1. Default behavior: Use the first workspace in the list automatically to avoid unnecessary interaction 2. User explicitly requests selection: If the user says "let me choose workspace", "show me the workspace list", or similar, present the full list and ask them to pick one
- No workspaces returned → inform the user that no Bailian workspace is available, guide them to create one at the Bailian Console
- Record user selection in the session to avoid repeated inquiries
Step 3: Upload File(video_source) to OSS
Based on the input resource type from Input Resource Validation:
Case A: User provided a downloadable URL → Verify URL accessibility: Test if the URL is downloadable using appropriate method for your OS → Skip this step. Use the video_source as file_url in Step 4.
Case B: User provided a local file path → Auto-detects OSS bucket、Upload local file to OSS and get a temporary URL(file_url) for Step 4:
- (1) Auto-detect or use user-specified OSS bucket:
- If user specifies
--ossBucket <bucket_name>, attempt to use that bucket - If the specified bucket returns 403 AccessDenied or BucketAlreadyExists: DO NOT switch to another bucket automatically. Instead:
1. Inform the user that the specified bucket is not accessible 2. Follow the Permission Failure Handling process in RAM Policy section 3. Guide user to grant OSS bucket access permissions or specify an alternative bucket they own 4. Wait for user confirmation before proceeding
- If no bucket specified, auto-detect from first available bucket
aliyun ossutil ls --user-agent AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysis- (2) Upload file to OSS: Generate a unique key(oss_object_key) for the uploaded file.
IMPORTANT - Upload Path Restriction:
- Default path: MUST use
/temp/quanmiao/YYYYMMDD/filenameformat (auto-generated with current date) - Custom path: ONLY if user explicitly specifies a custom oss_object_key, otherwise always use default path
- Security rule: NEVER upload files outside
/temp/quanmiao/prefix unless user explicitly requests it
aliyun ossutil cp <video_source> oss://{oss_bucket}/{oss_object_key} --user-agent AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysis --region {oss_region}- (3) Generate temporary URL: Generate a temporary URL for the uploaded file using the
ossutil signcommand. --expireSeconds: Default 14400s (4 hours), confirm if different value needed
aliyun ossutil sign oss://{oss_bucket}/{oss_object_key} --expires-duration {expire_seconds} --user-agent AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysis --region {oss_region}- (4) Verify URL accessibility: Test if the generated URL is downloadable using appropriate method for your OS
- Note: Prefer GET request over HEAD request for verification, as some OSS signature versions may reject HEAD requests.
Recommended validation URL downloadable methods:
- macOS/Linux:
curl -L --connect-timeout 10 --max-time 30 -o /dev/null -w "%{http_code}" <file_url>(returns HTTP status code) - Windows:
Invoke-WebRequest -Uri <file_url> -Method Head -TimeoutSec 30(PowerShell)
Validation criteria:
- HTTP 200 → URL is valid and accessible, proceed to Step 4
- HTTP 403/404 → URL expired or invalid, regenerate with
ossutil sign - Other errors → Check network or OSS permissions
Step 4: Submit Video Analysis Task
⚠️ MANDATORY API CALL — You MUST call SubmitVideoAnalysisTask on QuanMiaoLightApp product (version 2024-08-01). Do NOT use videorecog, Mts, or any other product. Do NOT attempt local analysis.
API Selection Checklist — Before calling, verify:
- ✅ Product: QuanMiaoLightApp (NOT videorecog, NOT Mts)
- ✅ Version: 2024-08-01
- ✅ Action: SubmitVideoAnalysisTask
- ✅ Parameters: workspace_id, file_url
python scripts/quanmiao_submit_videoAnalysis_task.py --workspace_id <workspace_id> --file_url <file_url>Parameters requiring confirmation:
--workspace_id: From Step 2 (confirm with user)--file_url: From Step 3 upload result or user-provided URL (confirm validity)
Error Handling:
- If API returns 401 InvalidApiKey or 403 AccessDenied: STOP and follow Permission Failure Handling process
- Do NOT attempt alternative APIs or local tools
- Inform user: "Video analysis requires Bailian service activation and proper RAM permissions. Please follow the permission grant guide."
Returns task_id for polling.
Step 5: Poll for Task Result
⚠️ MANDATORY API CALL — You MUST poll GetVideoAnalysisTask on QuanMiaoLightApp product (version 2024-08-01) until status is SUCCESSED. Do NOT generate summary from local tools or filename inference.
Video analysis is asynchronous. Poll until completion:
Task Status: PENDING → RUNNING → SUCCESSED | FAILED | CANCELED
Variables:
result_json_path:~/.quanmiao/videoanalysis/<video_filename_without_ext>_<task_id>.jsonindex_file:~/.quanmiao/videoanalysis/index.jsonl
Polling Loop: 1. Wait 10 seconds after submission 2. Run: python scripts/quanmiao_get_videoAnalysis_task_result.py --workspace_id <workspace_id> --task_id <task_id> --save_path <result_json_path> 3. Check the returned status field:
- `SUCCESSED` → Script auto-saves JSON to
result_json_path, append entry toindex_file, display saved locations, then proceed to Step 6 - `FAILED` or `CANCELED` → check error message, inform user, stop
- `PENDING` or `RUNNING` → display any partial results available, wait 10s, repeat from step 2
4. Max 180 retries (approximately 30 minutes)
When taskStatus = SUCCESSED:
1. Append to index file (index_file):
{"task_id": "<task_id>", "video_source": "<original_path_or_url>", "workspace_id": "<workspace_id>", "result_file": "<result_json_path>", "timestamp": "<ISO8601>"}2. Display saved locations:
✅ Files saved successfully:
- Raw JSON result: <result_json_path>
- Index updated: <index_file>Parameters requiring confirmation:
--workspace_id: Same as Step 4 (confirm consistency)--task_id: From Step 4 submission result (verify before polling)
Step 6: Summarize Video Content
CRITICAL: Use the results from Step 5 directly. Do NOT call the API again. Do NOT re-execute any analysis.
Extract data from the SUCCESSED response obtained in Step 5 and summarize according to user requirements.
Case A: If the user has a specific analysis request (e.g., "analyze the speaker's body language", "extract key business insights", "compare two people in the video"), base your answer primarily on:
- `payload.output.videoGenerateResults` — scene-by-scene analysis, descriptions, interpretations
- `payload.output.videoAnalysisResult.text` — visual shot analysis, object/person recognition, action detection
Combine these fields to construct a targeted answer. Supplement with other fields (captions, mind map, title) as context if relevant.
Case B: If no specific request, use the standard output format: Title → Outline → Summary → Captions → Shot Analysis → Timeline → Token Usage
---
Important Constraints
- Cloud-only: No local fallbacks (ffmpeg, whisper, etc.). If cloud API fails, follow Permission Failure Handling process.
- Violation Consequence: Using local tools instead of QuanMiaoLightApp API will result in task failure.
- Security: Never expose credentials in logs or prompts
- Permissions: On auth errors, see
ram-policies.md - Caching: Check
~/.quanmiao/videoanalysis/index.jsonlbefore re-analyzing same video
---
Success Verification
See references/verification-method.md for step-by-step verification commands and expected outcomes.
---
Cleanup
To clean up resources created by this skill:
Delete uploaded OSS objects:
aliyun ossutil rm oss://{oss_bucket}/{oss_object_key} --user-agent AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysisCleanup best practices:
- Confirm bucket name and oss object key before deletion
- Only delete objects with
/temp/quanmiao/prefix to avoid accidental data loss - Cached results at
~/.quanmiao/videoanalysis/can be kept for future reference or deleted manually
---
Best Practices
1. Always verify environment first — run check_env.py before any other operation to catch missing dependencies or credentials early. 2. Auto-detect workspace_id — always fetch workspaces via list-workspaces; default to the first result, but present a selection list when the user explicitly asks to choose. 3. Use default OSS settings — unless the user specifies a particular bucket, let the script auto-detect the bucket and generate the oss object key. 4. Display partial results during polling — when task status is RUNNING, show available results (title, captions) to give the user real-time feedback. 5. Save complete result for summary — when status becomes SUCCESSED, use the full result payload directly for Step 6 without re-calling the API. 6. Respect URL expiration — temporary OSS URLs expire after expireSeconds (default 14400s); ensure the task is submitted before the URL expires. 7. Handle permission errors gracefully — follow the Permission Failure Handling process in the RAM Policy section; never improvise credential fixes.
---
Command Tables
See references/related-commands.md for the full list of available scripts and their parameters.
---
Reference Links
| Reference | Purpose |
|---|---|
references/cli-installation-guide.md | Installing and upgrading Aliyun CLI |
references/ram-policies.md | RAM permission checklist and authorization guide |
references/acceptance-criteria.md | Acceptance criteria and correct/incorrect usage patterns |
references/related-commands.md | Available scripts and CLI command reference |
references/verification-method.md | Step-by-step success verification commands |
---
Troubleshooting
Common scenarios:
- Permission denied → See ram-policies.md
- CLI not found → See cli-installation-guide.md
- Workspace not found → Create at Bailian Console
- Upload failed → Check OSS bucket permissions
- Task timeout → Video too large or network issues
---
Acceptance Criteria: alibabacloud-bailian-videoanalysis
Scenario: Alibaba Cloud Bailian (Quanmiao) Video Analysis Purpose: Skill testing acceptance criteria
---
Correct Python Script Usage Patterns
1. Environment Check
✅ CORRECT
python scripts/check_env.py- Returns JSON with
ready: true/false - Checks Python packages and credentials via default credential chain
- Does NOT read or print AK/SK values
❌ INCORRECT
echo $ALIBABA_CLOUD_ACCESS_KEY_ID # NEVER print credentials
python scripts/check_env.py --ak xxx --sk xxx # NEVER pass AK/SK as arguments- Credentials are checked via the default credential chain only
- The script uses
CredentialClientinternally; no manual credential passing
2. Workspace Listing
✅ CORRECT
aliyun modelstudio list-workspaces --user-agent AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysis- Returns JSON array of available workspaces
- Auto-detects workspace_id; does NOT require user to know it in advance
- Uses
--user-agentparameter for tracking
❌ INCORRECT
aliyun modelstudio list-workspaces # Missing --user-agent parameter3. File Upload to OSS
✅ CORRECT
# List buckets first
aliyun ossutil ls --user-agent AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysis
# Upload file
aliyun ossutil cp /path/to/video.mp4 oss://my-bucket/temp/quanmiao/20260409/video.mp4 --user-agent AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysis --region cn-beijing
# Generate temporary URL
aliyun ossutil sign oss://my-bucket/temp/quanmiao/20260409/video.mp4 --expires-duration 7200 --user-agent AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysis --region cn-beijing- Uses auto-detected bucket and generated object key by default
- All commands include
--user-agentparameter - Optionally specifies custom
--expires-duration(default 7200s)
❌ INCORRECT
aliyun ossutil cp /path/to/video.mp4 oss://my-bucket/key # Missing --user-agent and --region
aliyun ossutil sign oss://my-bucket/key # Missing required parameters4. Submit Video Analysis Task
✅ CORRECT
python scripts/quanmiao_submit_videoAnalysis_task.py --workspace_id llm-xxx --file_url "https://..."- workspace_id must come from Step 2
- file_url must come from Step 3 (upload script output tempUrl)
❌ INCORRECT
python scripts/quanmiao_submit_videoAnalysis_task.py --workspace_id fake-id --file_url "invalid-url" # Invalid workspace_id or URL
python scripts/quanmiao_submit_videoAnalysis_task.py # Missing required parameters- Both
--workspace_idand--file_urlare required - file_url must be a valid temporary OSS URL
5. Get Task Result
✅ CORRECT
python scripts/quanmiao_get_videoAnalysis_task_result.py --workspace_id llm-xxx --task_id abc123- Poll every 10-15 seconds until status is
SUCCESSEDorFAILED - Handle
RUNNINGstatus by displaying partial results
❌ INCORRECT
python scripts/quanmiao_get_videoAnalysis_task_result.py --workspace_id llm-xxx --task_id abc123 --retry 1000 # No --retry parameter exists- The script returns the current task status; polling logic is handled externally
- Max retries should be 180 (approximately 30 minutes)
6. Authentication
✅ CORRECT
aliyun configure list # Check credential status- Uses
aliyun configure listto verify credentials - Relies on Alibaba Cloud default credential chain
❌ INCORRECT
aliyun configure set --mode AK --access-key-id LTAI... --access-key-secret abc... # NEVER set credentials within the session
echo $ALIBABA_CLOUD_ACCESS_KEY_ID # NEVER print credential values- Credentials must be configured outside of the session
- Never read, echo, or print AK/SK values
Common Anti-Patterns
Hardcoding User-Specific Parameters
❌ INCORRECT
# Assuming a specific workspace_id without checking
python scripts/quanmiao_submit_videoAnalysis_task.py --workspace_id llm-known-good --file_url ...- Always fetch workspaces via step 4 first; default to the first result or present a selection list if the user explicitly asks to choose
Skipping Environment Check
❌ INCORRECT
# Jumping directly to OSS upload without checking environment
aliyun ossutil cp /path/to/video.mp4 oss://my-bucket/key --user-agent AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysis --region cn-beijing- Always run
check_env.pyfirst to ensure dependencies and credentials are ready
Re-calling API After Success
❌ INCORRECT
# Step 5 returned SUCCESSED, but calling get_result again in Step 6
python scripts/quanmiao_get_videoAnalysis_task_result.py --workspace_id llm-xxx --task_id abc123- Use the result from Step 5 directly in Step 6; do NOT call the API again
Aliyun CLI Installation & Configuration Guide
Complete guide for installing and configuring Aliyun CLI.
Table of Contents
- Installation
- macOS
- Linux
- Windows
- Configuration
- Quick Start
- Configuration Modes
- Environment Variables
- Managing Multiple Profiles
- Credential Priority
- Verification
- Security Best Practices
- Troubleshooting
- Advanced Configuration
- Next Steps
- References
Aliyun CLI 3.3.1+: Supports installing and using all published Alibaba Cloud product plugins. Make sure to upgrade to 3.3.1 or later for full plugin ecosystem coverage.
>
[IMPORTANT] After installation, run the following command to enable automatic plugin installation:
```bash
aliyun configure set --auto-plugin-install true
```
Installation
macOS
Using Homebrew (Recommended)
brew install aliyun-cli
# Upgrade to latest
brew upgrade aliyun-cli
# Verify version (>= 3.3.1)
aliyun versionUsing Binary
# Download
wget https://aliyuncli.alicdn.com/aliyun-cli-macosx-latest-amd64.tgz
# Extract
tar -xzf aliyun-cli-macosx-latest-amd64.tgz
# Move to PATH
sudo mv aliyun /usr/local/bin/
# Verify
aliyun versionLinux
Debian/Ubuntu
# Download
wget https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-amd64.tgz
# Extract and install
tar -xzf aliyun-cli-linux-latest-amd64.tgz
sudo mv aliyun /usr/local/bin/
# Verify
aliyun versionCentOS/RHEL
# Download
wget https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-amd64.tgz
# Extract and install
tar -xzf aliyun-cli-linux-latest-amd64.tgz
sudo mv aliyun /usr/local/bin/
# Verify
aliyun versionARM64 Architecture
# Download ARM64 version
wget https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-arm64.tgz
# Extract and install
tar -xzf aliyun-cli-linux-latest-arm64.tgz
sudo mv aliyun /usr/local/bin/Windows
Using Binary 1. Download from: https://aliyuncli.alicdn.com/aliyun-cli-windows-latest-amd64.zip 2. Extract the ZIP file 3. Add the directory to your PATH environment variable 4. Open new Command Prompt or PowerShell 5. Verify: aliyun version Using PowerShell
# Download
Invoke-WebRequest -Uri "https://aliyuncli.alicdn.com/aliyun-cli-windows-latest-amd64.zip" -OutFile "aliyun-cli.zip"
# Extract
Expand-Archive -Path aliyun-cli.zip -DestinationPath C:\aliyun-cli
# Add to PATH (requires admin privileges)
$env:Path += ";C:\aliyun-cli"
[Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::Machine)
# Verify
aliyun versionConfiguration
Quick Start
aliyun configure set \
--mode AK \
--access-key-id <your-access-key-id> \
--access-key-secret <your-access-key-secret> \
--region cn-hangzhouAll aliyun configure commands support non-interactive flags, which is the recommended approach — it works in scripts, CI/CD pipelines, and agent-driven automation without hanging on stdin prompts. Where to Get Access Keys 1. Log in to Aliyun Console: https://ram.console.aliyun.com/ 2. Navigate to: AccessKey Management 3. Create a new AccessKey pair 4. Save the secret immediately — it's only shown once
Configuration Modes
Aliyun CLI supports 6 authentication modes. All examples below use non-interactive flags.
1. AK Mode (Access Key)
Most common mode for personal accounts and scripts.
aliyun configure set \
--mode AK \
--access-key-id LTAI5tXXXXXXXX \
--access-key-secret 8dXXXXXXXXXXXXXXXXXXXXXXXX \
--region cn-hangzhouConfiguration is stored in ~/.aliyun/config.json:
{
"current": "default",
"profiles": [
{
"name": "default",
"mode": "AK",
"access_key_id": "LTAI5tXXXXXXXX",
"access_key_secret": "8dXXXXXXXXXXXXXXXXXXXXXXXX",
"region_id": "cn-hangzhou",
"output_format": "json",
"language": "en"
}
]
}2. StsToken Mode (Temporary Credentials)
For short-lived access (tokens expire in 1-12 hours).
aliyun configure set \
--mode StsToken \
--access-key-id LTAI5tXXXXXXXX \
--access-key-secret 8dXXXXXXXXXXXXXXXXXXXXXXXX \
--sts-token v1.0:XXXXXXXXXXXXXXXX \
--region cn-hangzhouUse cases: CI/CD pipelines, temporary access for external contractors, cross-account access.
3. RamRoleArn Mode (Assume RAM Role)
Assume a RAM role for elevated or cross-account access.
aliyun configure set \
--mode RamRoleArn \
--access-key-id LTAI5tXXXXXXXX \
--access-key-secret 8dXXXXXXXXXXXXXXXXXXXXXXXX \
--ram-role-arn acs:ram::123456789012:role/AdminRole \
--role-session-name my-session \
--region cn-hangzhouUse cases: cross-account resource access, temporary elevated privileges, role-based access control.
4. EcsRamRole Mode (ECS Instance RAM Role)
Use the RAM role attached to an ECS instance — no credentials needed.
aliyun configure set \
--mode EcsRamRole \
--ram-role-name MyEcsRole \
--region cn-hangzhouRequirements: must be running on an ECS instance with a RAM role attached. Use cases: scripts and automation running on ECS instances.
5. RsaKeyPair Mode (RSA Key Pair)
Use RSA key pair for authentication (generate key pair in Aliyun Console first).
aliyun configure set \
--mode RsaKeyPair \
--private-key /path/to/private-key.pem \
--key-pair-name my-key-pair \
--region cn-hangzhou6. RamRoleArnWithEcs Mode (ECS + RAM Role)
Combine ECS instance role with RAM role assumption for cross-account access from ECS.
aliyun configure set \
--mode RamRoleArnWithEcs \
--ram-role-name MyEcsRole \
--ram-role-arn acs:ram::123456789012:role/TargetRole \
--role-session-name my-session \
--region cn-hangzhouEnvironment Variables
Highest priority - overrides config file Access Key Mode
export ALIBABA_CLOUD_ACCESS_KEY_ID=your_access_key_id
export ALIBABA_CLOUD_ACCESS_KEY_SECRET=your_access_key_secret
export ALIBABA_CLOUD_REGION_ID=cn-hangzhouSTS Token Mode
export ALIBABA_CLOUD_ACCESS_KEY_ID=your_access_key_id
export ALIBABA_CLOUD_ACCESS_KEY_SECRET=your_access_key_secret
export ALIBABA_CLOUD_SECURITY_TOKEN=your_sts_token
export ALIBABA_CLOUD_REGION_ID=cn-hangzhouECS RAM Role Mode
export ALIBABA_CLOUD_ECS_METADATA=role_nameUse Case:
- CI/CD pipelines
- Docker containers
- Temporary credential override
Managing Multiple Profiles
Create Named Profiles
aliyun configure set --profile projectA \
--mode AK \
--access-key-id LTAI5tAAAAAAAA \
--access-key-secret 8dAAAAAAAAAAAAAAAAAAAAAAAA \
--region cn-hangzhou
aliyun configure set --profile projectB \
--mode AK \
--access-key-id LTAI5tBBBBBBBB \
--access-key-secret 8dBBBBBBBBBBBBBBBBBBBBBBBB \
--region cn-shanghaiUse Specific Profile
aliyun ecs describe-instances --profile projectA
export ALIBABA_CLOUD_PROFILE=projectA
aliyun ecs describe-instances # Uses projectAList and Switch Profiles
aliyun configure list # List all profiles
aliyun configure set --current projectA # Switch default profileCredential Priority
Credentials are loaded in this order (first found wins): 1. Command-line flag: --profile <name> 2. Environment variable: ALIBABA_CLOUD_PROFILE 3. Environment credentials: ALIBABA_CLOUD_ACCESS_KEY_ID, etc. 4. Configuration file: ~/.aliyun/config.json (current profile) 5. ECS Instance RAM Role: If running on ECS with attached role
Verification
Test Authentication
# Basic test - list regions
aliyun ecs describe-regions
# Expected output: JSON array of regionsIf successful, you'll see:
{
"Regions": {
"Region": [
{
"RegionId": "cn-hangzhou",
"RegionEndpoint": "ecs.cn-hangzhou.aliyuncs.com",
"LocalName": "China East 1 (Hangzhou)"
},
...
]
},
"RequestId": "..."
}If failed, you'll see error messages:
InvalidAccessKeyId.NotFound- Wrong Access Key IDSignatureDoesNotMatch- Wrong Access Key SecretInvalidSecurityToken.Expired- STS token expired (for StsToken mode)Forbidden.RAM- Insufficient permissions
Debug Configuration
# Show current configuration
aliyun configure get
# Test with debug logging
aliyun ecs describe-regions --log-level=debug
# Check credential provider
aliyun configure get modeSecurity Best Practices
1. Use RAM Users (Not Root Account)
- Don't: Use Aliyun root account credentials
- Do: Create RAM users with specific permissions
# Create RAM user in console
# Attach only necessary policies
# Use RAM user's access keys2. Principle of Least Privilege
Grant only the minimum permissions needed:
# Example: Read-only ECS access
# Attach policy: AliyunECSReadOnlyAccess3. Rotate Access Keys Regularly
# Create new access key in RAM Console, then update configuration
aliyun configure set --access-key-id NEW_KEY --access-key-secret NEW_SECRET
# Delete old access key from console4. Use STS Tokens for Temporary Access
aliyun configure set --mode StsToken \
--access-key-id XXXX --access-key-secret XXXX \
--sts-token XXXX --region cn-hangzhou5. Use ECS RAM Roles When Possible
aliyun configure set --mode EcsRamRole --ram-role-name MyRole --region cn-hangzhou6. Never Commit Credentials
# Add to .gitignore
echo "~/.aliyun/config.json" >> .gitignore
# Use environment variables in CI/CD instead7. Secure Config File
# Restrict permissions
chmod 600 ~/.aliyun/config.jsonTroubleshooting
Issue: Command Not Found
# Check installation
which aliyun
# Check PATH
echo $PATH
# Reinstall or add to PATHIssue: Authentication Failed
# Verify configuration
aliyun configure get
# Test with debug
aliyun ecs describe-regions --log-level=debug
# Check credentials in console
# Verify access key is activeIssue: Permission Denied
# Error: Forbidden.RAM
# Check RAM user permissions
# Attach necessary policies in RAM console
# Example: AliyunECSFullAccess for ECS operationsIssue: STS Token Expired
# Error: InvalidSecurityToken.Expired
# Reconfigure with new token
aliyun configure set --mode StsToken \
--access-key-id XXXX --access-key-secret XXXX \
--sts-token NEW_TOKEN --region cn-hangzhouIssue: Wrong Region
# Some resources may not exist in the specified region
# Check available regions
aliyun ecs describe-regions
# Update default region
aliyun configure set region cn-shanghaiAdvanced Configuration
Custom Endpoint
# Use custom or private endpoint
export ALIBABA_CLOUD_ECS_ENDPOINT=ecs-vpc.cn-hangzhou.aliyuncs.comProxy Settings
# HTTP proxy
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080
# No proxy for specific domains
export NO_PROXY=localhost,127.0.0.1,.aliyuncs.comTimeout Settings
# Connection timeout (default: 10s)
export ALIBABA_CLOUD_CONNECT_TIMEOUT=30
# Read timeout (default: 10s)
export ALIBABA_CLOUD_READ_TIMEOUT=30Next Steps
After installation and configuration: 1. Install plugins for services you need (v3.3.1+ supports all published product plugins):
aliyun plugin install --names ecs vpc rds
# List all available plugins
aliyun plugin list-remote2. Explore commands:
aliyun ecs --help
aliyun fc --help3. Read documentation:
- Command Syntax Guide
- Global Flags Reference
- Common Scenarios
References
- Official Documentation: https://help.aliyun.com/zh/cli/
- RAM Console: https://ram.console.aliyun.com/
- Access Key Management: https://ram.console.aliyun.com/manage/ak
- Plugin Repository: https://github.com/aliyun/aliyun-cli
RAM Permissions
This Skill requires the following Alibaba Cloud RAM permissions to function properly.
Required Permissions
| Product | Action | Description |
|---|---|---|
| ModelStudio | modelstudio:ListWorkspaces | List Bailian workspaces |
| OSS | ossutil:ls | List buckets or objects |
| OSS | ossutil:cp | Upload, Download or Copy Objects |
| OSS | ossutil:presign | Generate a pre-signed URL for object |
| QuanMiaoLightApp | quanmiaolightapp:SubmitVideoAnalysisTask | Submit video analysis task |
| QuanMiaoLightApp | quanmiaolightapp:GetVideoAnalysisTask | Get video analysis task results |
Permission Details
modelstudio:ListWorkspaces
Used to query the list of available Bailian workspaces.
ossutil:ls, ossutil:cp, ossutil:presign
Used to manage OSS buckets and objects, including listing buckets/objects, uploading/downloading files, and generating temporary access URLs.
quanmiaolightapp:SubmitVideoAnalysisTask
Used to submit video analysis tasks to Bailian service.
quanmiaolightapp:GetVideoAnalysisTask
Used to query video analysis task results.
Authorization Methods
Use System Policies (Recommended)
1. Visit Alibaba Cloud RAM Console 2. Select the target RAM user 3. Click "Add Permissions" button 4. Search and select the following system policies:
AliyunBailianFullAccess(includes Bailian-related permissions)AliyunModelStudioReadOnlyAccess(includes ModelStudio-related permissions)AliyunQuanMiaoLightAppFullAccess(includes QuanMiao-related permissions)AliyunOSSFullAccess(includes OSS-related permissions, can be restricted to specific buckets)
5. Confirm and add permissions
Notes
- There may be a delay of approximately 30 seconds after authorization before permissions take effect
- If you encounter
403orIndex.NoWorkspacePermissionserrors, please check:
1. Whether the RAM user has been granted the above permissions 2. Whether workspace permissions have been granted to the user in the Bailian console
---
Permission Failure Handling
When any command or API call fails due to permission errors at any point during execution, follow this process:
1. Read this file (references/ram-policies.md) to get the full list of permissions required by this SKILL 2. Use `ram-permission-diagnose` skill to guide the user through requesting the necessary permissions 3. Pause and wait until the user confirms that the required permissions have been granted 4. Retry the failed operation after permissions are confirmed
Important: Never proceed with operations that require permissions the user does not have. Always pause and wait for explicit confirmation.
Related Commands: alibabacloud-bailian-videoanalysis
Available Python Scripts
All scripts are located in the scripts/ directory:
| Script | Purpose | Required Parameters | Optional Parameters |
|---|---|---|---|
check_env.py | Check environment configuration (packages + credentials) | None | None |
quanmiao_submit_videoAnalysis_task.py | Submit video analysis task to Bailian | --workspace_id, --file_url | None |
quanmiao_get_videoAnalysis_task_result.py | Get video analysis task result | --workspace_id, --task_id | None |
Aliyun CLI Commands
Important: All aliyun CLI commands MUST include --user-agent AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysis.
| Command | Purpose |
|---|---|
aliyun version | Verify CLI version (>= 3.3.1) |
aliyun configure list | Check credential status (NEVER print AK/SK) |
aliyun configure set --auto-plugin-install true | Enable automatic plugin installation |
aliyun modelstudio list-workspaces | List Bailian workspaces |
aliyun ossutil ls | List OSS buckets |
aliyun ossutil cp <local-file> oss://<bucket>/<key> | Upload file to OSS |
aliyun ossutil sign oss://<bucket>/<key> --expires-duration 2h | Generate temporary URL |
aliyun ossutil rm oss://<bucket>/<key> | Delete uploaded OSS object (cleanup) |
Execution Order
1. check_env.py (environment validation)
↓
2. aliyun modelstudio list-workspaces (get workspace_id)
↓
3a. [If local file] aliyun ossutil cp + sign (upload & get URL)
3b. [If URL provided] Skip upload, use URL directly
↓
4. quanmiao_submit_videoAnalysis_task.py (submit task)
↓
5. quanmiao_get_videoAnalysis_task_result.py (poll loop)
↓
6. Summarize (no script call, use Step 5 result directly)Verification Method: alibabacloud-bailian-videoanalysis
Step-by-step verification commands to confirm successful execution at each workflow stage.
---
Step 1: Environment Check Verification
Command:
python scripts/check_env.pyExpected Output (Success):
{
"pythonPackagesInstalled": {
"alibabacloud-quanmiaolightapp20240801": true,
"alibabacloud-openapi-util": true,
"alibabacloud-credentials": true,
"alibabacloud-tea-openapi": true,
"alibabacloud-tea-util": true
},
"allPythonPackagesInstalled": true,
"credentialsConfigured": true,
"ready": true,
"errors": []
}Verification Criteria:
readyfield istrueallPythonPackagesInstalledfield istruecredentialsConfiguredfield istrueerrorsarray is empty
Failure Actions:
- If
allPythonPackagesInstalledisfalse→ Runpip install -r scripts/requirements.txt - If
credentialsConfiguredisfalse→ Guide user to runaliyun configureoutside session
Additional CLI Verification:
# Verify Aliyun CLI version >= 3.3.1
aliyun version
# Verify credentials are configured
aliyun configure list---
Step 2: Workspace Listing Verification
Command:
aliyun modelstudio list-workspaces --user-agent AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysisExpected Output (Success):
{
"RequestId": "...",
"Workspaces": [
{
"WorkspaceId": "llm-xxx",
"Name": "Default Workspace"
}
]
}Verification Criteria:
Workspacesarray is non-empty- Each workspace has
WorkspaceIdandNamefields WorkspaceIdstarts withllm-prefix
Failure Actions:
- If
Workspacesis empty → User may not have activated Bailian service; guide to Bailian console - If error contains
No workspace permissions→ Check RAM permissions and Bailian workspace authorization
---
Step 3: OSS Upload Verification
Commands:
# List available buckets
aliyun ossutil ls --user-agent AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysis
# Upload file to OSS
aliyun ossutil cp <local-file> oss://<bucket>/<key> --user-agent AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysis --region <region>
# Generate temporary URL
aliyun ossutil sign oss://<bucket>/<key> --expires-duration 7200 --user-agent AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysis --region <region>Expected Output (Sign Command Success):
https://my-bucket.oss-cn-beijing.aliyuncs.com/temp/quanmiao/20260409/video.mp4?Signature=xxx&Expires=xxx&OSSAccessKeyId=xxxVerification Criteria:
- Generated URL is a valid HTTPS URL containing OSS domain and signature parameters
- URL includes
Signature,Expires, andOSSAccessKeyIdquery parameters - Bucket name and object key match the uploaded file
Failure Actions:
- If upload fails with permission error → Follow Permission Failure Handling in RAM Policy section
- If file not found → Verify local file path points to an existing file
- If no buckets available → Create an OSS bucket first or use user-provided video URL directly
---
Step 4: Task Submission Verification
Command:
python scripts/quanmiao_submit_videoAnalysis_task.py --workspace_id <workspace_id> --file_url <tempUrl>Expected Output (Success):
{
"task_id": "xxxx"
}Verification Criteria:
- Response contains a non-empty
task_idfield - No error code or message in response
Failure Actions:
- If
task_idis missing → Check thatworkspace_idexists andfile_urlis valid and not expired - If permission error → Follow Permission Failure Handling in RAM Policy section
---
Step 5: Task Result Polling Verification
Command:
python scripts/quanmiao_get_videoAnalysis_task_result.py --workspace_id <workspace_id> --task_id <task_id>Expected Output (SUCCESSED):
{
"header": {
"taskId": "...",
"event": "task-finished",
"sessionId": "...",
"eventInfo": "完成视频理解"
},
"payload": {
"output": {
"videoTitleGenerateResult": { "text": "..." },
"videoCaptionResult": { "videoCaptions": [] },
"videoAnalysisResult": { "text": "..." },
"videoGenerateResults": [{ "text": "..." }],
"videoMindMappingGenerateResult": { "text": "...", "videoMindMappings": [] },
"videoCalculatorResult": { "items": [] }
},
"usage": {
"inputTokens": 1,
"outputTokens": 1,
"totalTokens": 2
}
},
"requestId": "..."
}Verification Criteria:
header.eventequals"task-finished"payload.outputcontains all expected result fieldspayload.usagecontains token counts
Status Handling:
| Status | Action |
|---|---|
PENDING | Wait 10-15s, retry |
RUNNING | Display partial results, wait 10-15s, retry |
SUCCESSED | Proceed to Step 6 |
FAILED | Check error message, inform user |
CANCELED | Inform user task was canceled |
Maximum retries: 180 (approximately 30 minutes)
---
Step 6: Summary Verification
Verification Criteria:
- Summary uses data from Step 5 result directly (no additional API calls)
- Output includes all sections: title, outline, overview, captions, shot analysis, timeline, summary, token usage
- Token usage numbers match
payload.usagefrom Step 5 result
---
#!/usr/bin/env python3
"""
Check the Bailian SDK environment and credential configuration.
Returns a JSON object with the check results.
Uses the Alibaba Cloud default credential chain; does not directly read AccessKey/SecretKey.
"""
import subprocess
import json
import sys
try:
from alibabacloud_credentials.client import Client as CredentialClient
except ImportError:
CredentialClient = None
# Required Python packages list
REQUIRED_PACKAGES = [
'alibabacloud-quanmiaolightapp20240801',
'alibabacloud-openapi-util',
'alibabacloud-credentials',
'alibabacloud-tea-openapi',
'alibabacloud-tea-util'
]
def check_package_installed(package_name):
"""Check if Python package is installed using importlib.metadata (Python 3.8+)"""
try:
# Use importlib.metadata which is more reliable than pip commands
from importlib.metadata import version
version(package_name)
return True
except ImportError:
# Fallback for older Python versions
try:
import pkg_resources
pkg_resources.get_distribution(package_name)
return True
except (ImportError, pkg_resources.DistributionNotFound):
return False
except Exception:
return False
def check_env():
result = {
'pythonPackagesInstalled': {},
'allPythonPackagesInstalled': False,
'credentialsConfigured': False,
'ready': False,
'errors': []
}
# Check if credentials can be obtained through default credential chain
try:
if CredentialClient is None:
raise ImportError('alibabacloud-credentials not installed')
credential = CredentialClient()
# Try to get credentials to verify credential chain is available
credential.get_credential().access_key_id
result['credentialsConfigured'] = True
except Exception as error:
result['errors'].append('Alibaba Cloud credentials not configured, please run `aliyun configure` to configure credentials')
result['credentialsConfigured'] = False
# Check if all required Python packages are installed
all_installed = True
for pkg in REQUIRED_PACKAGES:
if check_package_installed(pkg):
result['pythonPackagesInstalled'][pkg] = True
else:
result['pythonPackagesInstalled'][pkg] = False
result['errors'].append(f'Python package not installed: {pkg}')
all_installed = False
result['allPythonPackagesInstalled'] = all_installed
# Determine if ready
result['ready'] = result['credentialsConfigured'] and result['allPythonPackagesInstalled']
print(json.dumps(result, indent=2, ensure_ascii=False))
if __name__ == '__main__':
check_env()
#!/usr/bin/env python3
"""
Get video analysis task result from Bailian.
Uses the Alibaba Cloud default credential chain.
Optionally save the result to a local JSON file.
"""
import sys
import json
import argparse
import os
from pathlib import Path
from alibabacloud_quanmiaolightapp20240801.client import Client as QuanMiaoLightApp20240801Client
from alibabacloud_credentials.client import Client as CredentialClient
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_quanmiaolightapp20240801 import models as quan_miao_light_app_20240801_models
from alibabacloud_tea_util import models as util_models
def create_client() -> QuanMiaoLightApp20240801Client:
"""
Initialize client using credential chain
@return: Client
@throws Exception
"""
credential = CredentialClient()
config = open_api_models.Config(
credential=credential,
user_agent='AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysis'
)
# Endpoint refer to https://api.aliyun.com/product/QuanMiaoLightApp
config.endpoint = f'quanmiaolightapp.cn-beijing.aliyuncs.com'
return QuanMiaoLightApp20240801Client(config)
def main(workspace_id, task_id, save_path=None):
client = create_client()
get_video_analysis_task_request = quan_miao_light_app_20240801_models.GetVideoAnalysisTaskRequest(
task_id=task_id
)
runtime = util_models.RuntimeOptions(
read_timeout=30000,
connect_timeout=5000
)
headers = {}
try:
resp = client.get_video_analysis_task_with_options(workspace_id, get_video_analysis_task_request, headers, runtime)
result_data = resp.body.to_map()
# Save to file if save_path is provided and status is SUCCESSED
if save_path and result_data.get('payload', {}).get('output', {}).get('taskStatus') == 'SUCCESSED':
save_result_to_file(result_data, save_path)
# Print result to stdout
print("\nRaw result: \n\n" + json.dumps(result_data, indent=2, ensure_ascii=False))
except Exception as error:
error_data = getattr(error, 'data', {})
recommend = error_data.get('Recommend', '') if isinstance(error_data, dict) else ''
print(json.dumps({
'error': str(error),
'recommend': recommend
}, indent=2, ensure_ascii=False))
sys.exit(1)
# Parameter validation functions
def validate_workspace_id(arg):
if not arg or arg.strip() == '':
raise ValueError('workspace_id cannot be empty')
if not isinstance(arg, str):
raise ValueError('workspace_id must be a string type')
# Trim whitespace
trimmed = arg.strip()
if len(trimmed) > 64:
raise ValueError('workspace_id length cannot exceed 64 characters')
# Only allow letters, numbers, hyphens, and underscores
import re
if not re.match(r'^[a-zA-Z0-9_-]+$', trimmed):
raise ValueError('workspace_id contains invalid characters, only letters, numbers, hyphens and underscores are allowed')
return trimmed
def validate_task_id(arg):
if not arg or arg.strip() == '':
raise ValueError('task_id cannot be empty')
if not isinstance(arg, str):
raise ValueError('task_id must be a string type')
# Trim whitespace
trimmed = arg.strip()
if len(trimmed) > 128:
raise ValueError('task_id length cannot exceed 128 characters')
return trimmed
def save_result_to_file(result_data, save_path):
"""
Save the result data to a JSON file.
Args:
result_data: The result data to save
save_path: Path to save the JSON file
"""
try:
# Create directory if it doesn't exist
save_dir = os.path.dirname(save_path)
if save_dir:
Path(save_dir).mkdir(parents=True, exist_ok=True)
# Write JSON file
with open(save_path, 'w', encoding='utf-8') as f:
json.dump(result_data, f, indent=2, ensure_ascii=False)
print(f"✅ Raw JSON result saved to: {save_path}", file=sys.stderr)
except Exception as e:
print(f"⚠️ Warning: Failed to save raw JSON result to {save_path}: {str(e)}", file=sys.stderr)
# Get parameters from command line arguments
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Get video analysis task result from Bailian')
parser.add_argument('--workspace_id', required=True, help='Workspace ID')
parser.add_argument('--task_id', required=True, help='Task ID')
parser.add_argument('--save_path', required=False, default=None,
help='Path to save JSON result (only saves when taskStatus=SUCCESSED)')
args = parser.parse_args()
try:
workspace_id_arg = validate_workspace_id(args.workspace_id)
task_id_arg = validate_task_id(args.task_id)
main(workspace_id_arg, task_id_arg, args.save_path)
except Exception as error:
print(json.dumps({'error': str(error)}, indent=2, ensure_ascii=False))
sys.exit(1)#!/usr/bin/env python3
"""
Submit video analysis task to Bailian.
Uses the Alibaba Cloud default credential chain.
"""
import sys
import json
import argparse
from alibabacloud_quanmiaolightapp20240801.client import Client as QuanMiaoLightApp20240801Client
from alibabacloud_credentials.client import Client as CredentialClient
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_quanmiaolightapp20240801 import models as quan_miao_light_app_20240801_models
from alibabacloud_tea_util import models as util_models
def create_client() -> QuanMiaoLightApp20240801Client:
"""
Initialize client using credential chain
@return: Client
@throws Exception
"""
credential = CredentialClient()
config = open_api_models.Config(
credential=credential,
user_agent='AlibabaCloud-Agent-Skills/alibabacloud-bailian-videoanalysis'
)
# Endpoint refer to https://api.aliyun.com/product/QuanMiaoLightApp
config.endpoint = f'quanmiaolightapp.cn-beijing.aliyuncs.com'
return QuanMiaoLightApp20240801Client(config)
def main(workspace_id, file_url):
client = create_client()
submit_video_analysis_task_request = quan_miao_light_app_20240801_models.SubmitVideoAnalysisTaskRequest(
video_url=file_url
)
runtime = util_models.RuntimeOptions(
read_timeout=30000,
connect_timeout=5000
)
headers = {}
try:
resp = client.submit_video_analysis_task_with_options(workspace_id, submit_video_analysis_task_request, headers, runtime)
status = resp.body.http_status_code
if status == 200:
# 输出任务ID
result = {
'task_id': resp.body.data.task_id if resp.body.data else None
}
print(json.dumps(result, indent=2, ensure_ascii=False))
else:
print(json.dumps(resp.body.to_map(), indent=2, ensure_ascii=False))
except Exception as error:
error_data = getattr(error, 'data', {})
recommend = error_data.get('Recommend', '') if isinstance(error_data, dict) else ''
print(json.dumps({
'error': str(error),
'recommend': recommend
}, indent=2, ensure_ascii=False))
sys.exit(1)
# Parameter validation functions
def validate_workspace_id(arg):
if not arg or arg.strip() == '':
raise ValueError('workspace_id cannot be empty')
if not isinstance(arg, str):
raise ValueError('workspace_id must be a string type')
# Trim whitespace
trimmed = arg.strip()
if len(trimmed) > 64:
raise ValueError('workspace_id length cannot exceed 64 characters')
# Only allow letters, numbers, hyphens, and underscores
import re
if not re.match(r'^[a-zA-Z0-9_-]+$', trimmed):
raise ValueError('workspace_id contains invalid characters, only letters, numbers, hyphens and underscores are allowed')
return trimmed
def validate_file_url(arg):
if not arg or arg.strip() == '':
raise ValueError('fileUrl cannot be empty')
if not isinstance(arg, str):
raise ValueError('fileUrl must be a string type')
# Trim whitespace
trimmed = arg.strip()
# Basic URL format validation
if not trimmed.startswith(('http://', 'https://')):
raise ValueError('fileUrl must be a valid HTTP/HTTPS URL')
return trimmed
# Get parameters from command line arguments
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Submit video analysis task to Bailian')
parser.add_argument('--workspace_id', required=True, help='Workspace ID')
parser.add_argument('--file_url', required=True, help='File URL (OSS temporary URL)')
args = parser.parse_args()
try:
workspace_id_arg = validate_workspace_id(args.workspace_id)
file_url_arg = validate_file_url(args.file_url)
main(workspace_id_arg, file_url_arg)
except Exception as error:
print(json.dumps({'error': str(error)}, indent=2, ensure_ascii=False))
sys.exit(1)
alibabacloud-openapi-util==0.2.4
alibabacloud-credentials==1.0.8
alibabacloud-tea-util==0.3.14
alibabacloud-tea-openapi==0.4.4
alibabacloud-quanmiaolightapp20240801>=2.13.8