IMA AI Creation
⚙️ How This Skill Works
For transparency: This skill uses a bundled Python script (scripts/ima_create.py) to call the IMA Open API. The script:
- Sends your prompt to two IMA-owned domains (see "Network Endpoints" below)
- Uses
--user-id only locally as a key for storing your model preferences
- Returns image/video/music URLs when generation is complete
What gets sent to IMA servers:
- ✅ Your prompt/description (image/video/music)
- ✅ Model selection (SeeDream/Wan/Suno/etc.)
- ✅ Generation parameters (size, duration, style, etc.)
- ❌ NO API key in prompts (key is used for authentication only)
- ❌ NO user_id (it's only used locally)
What's stored locally:
~/.openclaw/memory/ima_prefs.json - Your model preferences (< 1 KB)
~/.openclaw/logs/ima_skills/ - Generation logs (auto-deleted after 7 days)
- See SECURITY.md for complete privacy policy
🌐 Network Endpoints Used
| Domain |
Owner |
Purpose |
Data Sent |
Privacy |
api.imastudio.com |
IMA Studio |
Main API (product list, task creation, task polling) |
Prompts, model IDs, generation params, your API key |
Standard HTTPS, data processed for AI generation |
imapi.liveme.com |
IMA Studio |
Image/Video upload service (presigned URL generation) |
Your API key, file metadata (MIME type, extension) |
Standard HTTPS, used for image/video tasks only |
*.aliyuncs.com, *.esxscloud.com |
Alibaba Cloud (OSS) |
Image/video storage (file upload, CDN delivery) |
Raw image/video bytes (via presigned URL, NO API key) |
IMA-managed OSS buckets, presigned URLs expire after 7 days |
Key Points:
- Music tasks (
text_to_music) only use api.imastudio.com.
- Image/video tasks require
imapi.liveme.com to obtain presigned URLs for uploading input images.
- Your API key is sent to both
api.imastudio.com and imapi.liveme.com (both owned by IMA Studio).
- Verify network calls:
tcpdump -i any -n 'host api.imastudio.com or host imapi.liveme.com' (see SECURITY.md).
⚠️ Credential Security Notice
Your API key is sent to both IMA-owned domains:
Authorization: Bearer ima_xxx... → api.imastudio.com (main API)
- Query param
appUid=ima_xxx... → imapi.liveme.com (upload service)
Security best practices:
- 🧪 Use test keys for experiments: Generate a separate API key for testing.
- 🔍 Monitor usage: Check
https://imastudio.com/dashboard for unauthorized activity.
- ⏱️ Rotate keys: Regenerate your API key periodically (monthly recommended).
- 📊 Review logs: Check
~/.openclaw/logs/ima_skills/ for unexpected API calls.
Why two domains? IMA Studio uses a microservices architecture:
api.imastudio.com: Core AI generation API
imapi.liveme.com: Specialized image/video upload service (shared infrastructure)
Both domains are operated by IMA Studio. The same API key grants access to both services.
Agent Execution (Internal Reference)
Note for users: You can review the script source at scripts/ima_create.py anytime.
The agent uses this script to simplify API calls. Music tasks use only api.imastudio.com, while image/video tasks also call imapi.liveme.com for file uploads (see "Network Endpoints" above).
Use the bundled script internally for all task types — it ensures correct parameter construction:
# ─── Image Generation ──────────────────────────────────────────────────────────
# Basic text-to-image (default model)
python3 {baseDir}/scripts/ima_create.py \
--api-key $IMA_API_KEY --task-type text_to_image \
--model-id doubao-seedream-4.5 --prompt "a cute puppy on grass, photorealistic" \
--user-id {user_id} --output-json
# Text-to-image with size override (Nano Banana2)
python3 {baseDir}/scripts/ima_create.py \
--api-key $IMA_API_KEY --task-type text_to_image \
--model-id gemini-3.1-flash-image --prompt "city skyline at sunset, 4K" \
--size 2k --user-id {user_id} --output-json
# Image-to-image with input URL
python3 {baseDir}/scripts/ima_create.py \
--api-key $IMA_API_KEY --task-type image_to_image \
--model-id doubao-seedream-4.5 --prompt "turn into oil painting style" \
--input-images https://example.com/photo.jpg --user-id {user_id} --output-json
# ─── Video Generation ──────────────────────────────────────────────────────────
# Basic text-to-video (default model, 5s 720P)
python3 {baseDir}/scripts/ima_create.py \
--api-key $IMA_API_KEY --task-type text_to_video \
--model-id wan2.6-t2v --prompt "a puppy dancing happily, cinematic" \
--user-id {user_id} --output-json
# Text-to-video with extra params (10s 1080P)
python3 {baseDir}/scripts/ima_create.py \
--api-key $IMA_API_KEY --task-type text_to_video \
--model-id wan2.6-t2v --prompt "dramatic ocean waves, sunset" \
--extra-params '{"duration":10,"resolution":"1080P","aspect_ratio":"16:9"}' \
--user-id {user_id} --output-json
# Image-to-video (animate static image)
python3 {baseDir}/scripts/ima_create.py \
--api-key $IMA_API_KEY --task-type image_to_video \
--model-id wan2.6-i2v --prompt "camera slowly zooms in, gentle movement" \
--input-images https://example.com/photo.jpg --user-id {user_id} --output-json
# First-last frame video (two images)
python3 {baseDir}/scripts/ima_create.py \
--api-key $IMA_API_KEY --task-type first_last_frame_to_video \
--model-id kling-video-o1 --prompt "smooth transition between frames" \
--input-images https://example.com/frame1.jpg https://example.com/frame2.jpg \
--user-id {user_id} --output-json
# ─── Music Generation ──────────────────────────────────────────────────────────
# Basic text-to-music (Suno default)
python3 {baseDir}/scripts/ima_create.py \
--api-key $IMA_API_KEY --task-type text_to_music \
--model-id sonic --prompt "upbeat electronic music, 120 BPM, no vocals" \
--user-id {user_id} --output-json
# Music with custom lyrics (Suno custom mode)
python3 {baseDir}/scripts/ima_create.py \
--api-key $IMA_API_KEY --task-type text_to_music \
--model-id sonic --prompt "pop ballad, emotional" \
--extra-params '{"custom_mode":true,"lyrics":"Your custom lyrics here...","vocal_gender":"female"}' \
--user-id {user_id} --output-json
# Background music (DouBao BGM)
python3 {baseDir}/scripts/ima_create.py \
--api-key $IMA_API_KEY --task-type text_to_music \
--model-id GenBGM --prompt "relaxing ambient music for meditation" \
--user-id {user_id} --output-json
The script outputs JSON with url, model_name, credit — use these values in the UX protocol messages below. The script internals (product list query, parameter construction, polling) are invisible to users.
Overview
Call IMA Open API to create AI-generated content. All endpoints require an ima_* API key. The core flow is: query products → create task → poll until done.
🔒 Security & Transparency Policy
This skill is community-maintained and open for inspection.
✅ What Users CAN Do
Full transparency:
- ✅ Review all source code: Check
scripts/ima_create.py and ima_logger.py anytime
- ✅ Verify network calls: Music tasks use
api.imastudio.com only; image/video tasks also use imapi.liveme.com (see "Network Endpoints" section)
- ✅ Inspect local data: View
~/.openclaw/memory/ima_prefs.json and log files
- ✅ Control privacy: Delete preferences/logs anytime, or disable file writes (see below)
Configuration allowed:
- ✅ Set API key in environment or agent config:
- Environment variable:
export IMA_API_KEY=ima_your_key_here
- OpenClaw/MCP config: Add
IMA_API_KEY to agent's environment configuration
- Get your key at: https://imastudio.com
- ✅ Use scoped/test keys: Test with limited API keys, rotate after testing
- ✅ Disable file writes: Make prefs/logs read-only or symlink to
/dev/null
Data control:
- ✅ View stored data:
cat ~/.openclaw/memory/ima_prefs.json
- ✅ Delete preferences:
rm ~/.openclaw/memory/ima_prefs.json (resets to defaults)
- ✅ Delete logs:
rm -rf ~/.openclaw/logs/ima_skills/ (auto-cleanup after 7 days anyway)
- ✅ Review security: See SECURITY.md for complete privacy policy
⚠️ Advanced Users: Fork & Modify
If you need to modify this skill for your use case:
- Fork the repository (don't modify the original)
- Update your fork with your changes
- Test thoroughly with limited API keys
- Document your changes for troubleshooting
Note: Modified skills may break API compatibility or introduce security issues. Official support only covers the unmodified version.
❌ What to AVOID (Security Risks)
Actions that could compromise security:
- ❌ Sharing API keys publicly or in skill files
- ❌ Modifying API endpoints to unknown servers
- ❌ Disabling SSL/TLS certificate verification
- ❌ Logging sensitive user data (prompts, IDs, etc.)
- ❌ Bypassing authentication or billing mechanisms
Why this matters:
- API Compatibility: Skill logic aligns with IMA Open API schema
- Security: Malicious modifications could leak credentials or bypass billing
- Support: Modified skills may not be supported
- Community: Breaking changes affect all users
📋 Privacy & Data Handling Summary
What this skill does with your data:
| Data Type |
Sent to IMA? |
Stored Locally? |
User Control |
| Prompts (image/video/music) |
✅ Yes (required for generation) |
❌ No |
None (required) |
| API key |
✅ Yes (authentication header) |
❌ No |
Set via env var |
| user_id (optional CLI arg) |
❌ Never (local preference key only) |
✅ Yes (as prefs file key) |
Change --user-id value |
| Model preferences |
❌ No |
✅ Yes (~/.openclaw) |
Delete anytime |
| Generation logs |
❌ No |
✅ Yes (~/.openclaw) |
Auto-cleanup 7 days |
Privacy recommendations:
- Use test/scoped API keys for initial testing
- Note:
--user-id is never sent to IMA servers - it's only used locally as a key for storing preferences in ~/.openclaw/memory/ima_prefs.json
- Review source code at
scripts/ima_create.py to verify network calls (search for create_task function)
- Rotate API keys after testing or if compromised
Get your IMA API key: Visit https://imastudio.com to register and get started.
🔧 For Skill Maintainers Only
Version control:
- All changes must go through Git with proper version bumps (semver)
- CHANGELOG.md must document all changes
- Production deployments require code review
如果你需要定制功能,请:
- Fork 这个 Skill 创建私有版本(不保证兼容性)
- 或者联系 IMA 技术支持申请企业定制
### 🔧 For Skill Maintainers Only
**Version control:**
- All changes must go through Git with proper version bumps (semver)
- CHANGELOG.md must document all changes
- Production deployments require code review
**File checksums (optional):**
```bash
# Verify skill integrity
sha256sum SKILL.md scripts/ima_create.py
If users report issues, verify file integrity first.
🧠 User Preference Memory
User preferences override recommended defaults across ALL task types.
If a user has generated before, use their preferred model — not the system default.
Storage: ~/.openclaw/memory/ima_prefs.json
Single file, shared across all IMA skills:
{
"user_{user_id}": {
"text_to_image": { "model_id": "doubao-seedream-4.5", "model_name": "SeeDream 4.5", "credit": 5, "last_used": "2026-02-27T03:07:27Z" },
"image_to_image": { "model_id": "doubao-seedream-4.5", "model_name": "SeeDream 4.5", "credit": 5, "last_used": "2026-02-27T03:07:27Z" },
"text_to_video": { "model_id": "wan2.6-t2v", "model_name": "Wan 2.6", "credit": 25, "last_used": "2026-02-27T10:00:00Z" },
"image_to_video": { "model_id": "wan2.6-i2v", "model_name": "Wan 2.6", "credit": 25, "last_used": "2026-02-27T10:00:00Z" },
"first_last_frame_to_video": { "model_id": "kling-video-o1", "model_name": "Kling O1", "credit": 48, "last_used": "2026-02-26T08:00:00Z" },
"reference_image_to_video": { "model_id": "kling-video-o1", "model_name": "Kling O1", "credit": 48, "last_used": "2026-02-26T08:00:00Z" },
"text_to_music": { "model_id": "sonic", "model_name": "Suno", "credit": 25, "last_used": "2026-02-26T06:00:00Z" }
}
}
If the file or key doesn't exist, fall back to the ⭐ Recommended Defaults below.
Model Selection Priority (Strict Order)
1. User explicitly specifies a model in this message
→ use it, save as new preference, confirm if different from old preference
2. User has a saved preference for this task type
→ use it, mention "根据你的使用习惯"
3. No preference exists
→ use ⭐ Recommended Default, save after success
When to Read (Before Every Generation)
import json, os
prefs_path = os.path.expanduser("~/.openclaw/memory/ima_prefs.json")
try:
with open(prefs_path) as f:
prefs = json.load(f)
user_pref = prefs.get(f"user_{user_id}", {}).get(task_type)
except (FileNotFoundError, json.JSONDecodeError):
user_pref = None
if user_pref:
model_id = user_pref["model_id"]
model_name = user_pref["model_name"]
credit = user_pref["credit"]
source = "preference" # pre-generation message: "根据你的使用习惯"
else:
model_id, model_name, credit = RECOMMENDED_DEFAULTS[task_type]
source = "default"
When to Write (After Every Successful Generation)
os.makedirs(os.path.dirname(prefs_path), exist_ok=True)
try:
with open(prefs_path) as f:
prefs = json.load(f)
except (FileNotFoundError, json.JSONDecodeError):
prefs = {}
from datetime import datetime, timezone
prefs.setdefault(f"user_{user_id}", {})[task_type] = {
"model_id": model_id,
"model_name": model_name,
"credit": credit,
"last_used": datetime.now(timezone.utc).isoformat(),
}
with open(prefs_path, "w") as f:
json.dump(prefs, f, ensure_ascii=False, indent=2)
When to Update (User Explicitly Changes Model)
| User Says |
Action |
用XXX / 换成XXX / 改用XXX / use XXX |
Use that model this time AND save as new preference |
以后都用XXX / 默认用XXX / always use XXX |
Save preference + confirm: ✅ 已记住!以后 [类型] 生成默认用 [XXX] |
换个模型 / try another model |
Show top 3 alternatives, let user pick; save chosen |
用最好的 / best quality |
Use highest-quality model for this type; save preference |
用便宜的 / cheapest |
Use lowest-cost model; only save if user adds "以后都用" |
清除我的偏好 / reset preference |
Delete user_{user_id}.{task_type} from prefs file; confirm |
Pre-Generation Notification (with preference)
When using a saved preference, mention it naturally:
🎨 根据你的使用习惯,将用 [Model Name] 帮你生成…
• 模型:[Model Name](你的常用模型)
• 预计耗时:[X ~ Y 秒]
• 消耗积分:[N pts]
Preference Change Confirmation
When user switches to a different model than their saved preference:
💡 你之前喜欢用 [Old Model],这次换成了 [New Model]。
要把 [New Model] 设为以后的默认吗?
回复「是」保存 / 回复「否」仅本次使用
⭐ Recommended Defaults
These are fallback defaults — only used when no user preference exists.
Always default to the newest and most popular model. Do NOT default to the cheapest.
| Task Type |
Default Model |
model_id |
Cost |
Why |
| text_to_image |
SeeDream 4.5 |
doubao-seedream-4.5 |
5 pts |
Latest doubao flagship, photorealistic 4K |
| image_to_image |
SeeDream 4.5 |
doubao-seedream-4.5 |
5 pts |
Latest, best i2i quality |
| text_to_video |
Wan 2.6 |
wan2.6-t2v |
25 pts |
🔥 Most popular t2v, balanced cost. Premium → Hailuo 2.3 (38 pts) |
| image_to_video |
Wan 2.6 |
wan2.6-i2v |
25 pts |
🔥 Most popular i2v, 1080P |
| first_last_frame_to_video |
Kling O1 |
kling-video-o1 |
48 pts |
Newest Kling reasoning model |
| reference_image_to_video |
Kling O1 |
kling-video-o1 |
48 pts |
Best reference fidelity |
| text_to_music |
Suno (sonic-v4) |
sonic |
25 pts |
Latest Suno engine, best quality |
Quick selection guide (production as of 2026-02-27, sorted by popularity):
- Image (3 models available) → SeeDream 4.5 (5, default); budget → Nano Banana2 (4, 512px); premium → Nano Banana Pro (10-18)
- 🔥 Video from text (most popular) → Wan 2.6 (25, balanced); premium → Hailuo 2.3 (38); budget → Vidu Q2 (5)
- 🔥 Video from image (most popular) → Wan 2.6 (25)
- Music → Suno (25); DouBao BGM/Song (30 each)
- Cheapest → Nano Banana2 512px (4) for image; Vidu Q2 (5) for video
⚠️ Production Image Models (3 available):
- SeeDream 4.5 (
doubao-seedream-4.5) — 5 pts, default
- Nano Banana Pro (
gemini-3-pro-image) — 10/10/18 pts for 1K/2K/4K
All other image models mentioned in older documentation are no longer available in production.
🌟 Parameter Support Notes (All Task Types):
Image Models (text_to_image / image_to_image)
- ❌ aspect_ratio: NOT supported by any production image model (all produce 1:1 or fixed aspect ratio only)
- ✅ size:
- Nano Banana2: 512px, 1K, 2K, 4K (via different
attribute_ids, 4-13 pts)
- Nano Banana Pro: 1K, 2K, 4K (via different
attribute_ids, 10-18 pts)
- SeeDream 4.5: Adaptive default only (no size control, 5 pts)
- ❌ 8K: No model supports 8K (max is 4K via Nano Banana Pro)
- ❌ Custom aspect ratios (7:3, 4:5, etc.): Not supported. Use video models as workaround.
- ✅ n: Multiple outputs supported (1-4), credit × n
Video Models (text_to_video / image_to_video / first_last_frame / reference_image)
- ✅ resolution: 540P, 720P, 1080P, 2K, 4K (model-dependent, higher res = higher cost)
- ✅ aspect_ratio: 16:9, 9:16, 1:1, 4:3 (model-dependent, check
form_config)
- ✅ duration: 4s, 5s, 10s, 15s (model-dependent, longer = higher cost)
- ⚠️ generate_audio: Supported by Veo 3.1, Kling O1, Hailuo (check
form_config)
- ✅ prompt_extend: AI-powered prompt enhancement (most models support)
- ✅ negative_prompt: Content exclusion (most models support)
- ✅ shot_type: Single/multi-shot control (model-dependent)
- ✅ seed: Reproducibility control (most models support, -1 = random)
- ✅ n: Multiple outputs (1-4), credit × n
Music Models (text_to_music)
- ✅ custom_mode: Suno only (enables vocal_gender, lyrics support)
- ✅ vocal_gender: Suno only (male/female/mixed, requires custom_mode=True)
- ✅ lyrics: Suno only (custom lyrics support, requires custom_mode=True)
- ❌ duration: Fixed-length output (DouBao ~30s, Suno ~2min, not user-controllable)
- ✅ n: Multiple outputs supported (1-2), credit × n
Common Parameter Patterns
- n (batch generation): Supported by ALL models. Cost = base_credit × n. Creates n independent resources.
- seed: Supported by most models (-1 = random, >0 = reproducible results)
- prompt_extend: AI-powered prompt enhancement (video models only)
Decision Tree: When User Requests Unsupported Features
User asks for custom aspect ratio image (e.g. "7:3 landscape")
→ ❌ Image models don't support custom ratios
→ ✅ Solution: "图片模型不支持自定义比例。建议用视频模型(Wan 2.6 t2v)生成16:9视频,然后截取首帧作为图片。"
User asks for 8K image
→ ❌ No model supports 8K
→ ✅ Solution: "当前最高支持4K分辨率(Nano Banana Pro,18积分)。要使用吗?"
User asks for video with audio
→ Check model: Veo 3.1 / Kling O1 / Hailuo have generate_audio
→ ✅ Solution: "Veo 3.1 和 Kling O1 支持音频生成(需在参数中设置 generate_audio=True)。要用哪个?"
User asks for long music (e.g. "5 minute track")
→ ❌ Duration not user-controllable
→ ✅ Solution: "Suno 生成约2分钟音乐。需要更长时长可以生成多段后拼接。"
User asks for 30s video
→ Check model: Most models max 15s
→ ✅ Solution: "当前最长15秒。可选模型:Wan 2.6(15s, 75积分), Kling O1(10s, 96积分)。"
When user requests unsupported combinations:
- Any image model + custom aspect_ratio → "不支持自定义比例,建议用视频模型(Wan 2.6)生成后截取首帧"
- Any model + 8K → "最高支持4K (Nano Banana Pro, 18 pts)"
- Image model + 7:3 → "图片模型不支持,建议用 Wan 2.6 视频模型(支持16:9/9:16)生成后截帧"
- Video + audio (unsupported model) → "该模型不支持音频。建议用 Veo 3.1 或 Kling O1 (支持 generate_audio 参数)"
- Music + custom duration → "音乐时长由模型固定(Suno约2分钟,DouBao约30秒),无法自定义"
💬 User Experience Protocol (IM / Feishu / Discord)
This skill runs inside IM platforms (Feishu, Discord via OpenClaw).
Generation takes 10 seconds (music) up to 6 minutes (video). Never let users wait in silence.
Always follow all 4 steps below, every single time.
🚫 Never Say to Users
The following are internal implementation details. Never mention them in any user-facing message, under any circumstances:
| ❌ Never say |
✅ What users care about |
ima_create.py / 脚本 / script |
— |
| 自动化脚本 / automation script |
— |
| 自动处理产品列表查询 |
— |
| 自动解析参数和配置 |
— |
| 智能轮询 / polling / 轮询 |
— |
| product list / 商品列表接口 |
— |
| attribute_id / model_version / form_config |
— |
| API 调用 / HTTP 请求 |
— |
| 任何技术参数名 |
模型名称、积分、生成时间 |
User messages must only contain: model name, estimated/actual time, credits consumed, result URL, and natural language status updates.
Estimated Generation Time (All Task Types)
| Task Type |
Model |
Estimated Time |
Poll Every |
Send Progress Every |
| text_to_image |
SeeDream 4.5 |
25~60s |
5s |
20s |
|
Nano Banana2 💚 |
20~40s |
5s |
15s |
|
Nano Banana Pro |
60~120s |
5s |
30s |
| image_to_image |
SeeDream 4.5 |
25~60s |
5s |
20s |
|
Nano Banana2 💚 |
20~40s |
5s |
15s |
|
Nano Banana Pro |
60~120s |
5s |
30s |
| text_to_video |
Wan 2.6, Hailuo 2.0/2.3, Vidu Q2, Pixverse |
60~120s |
8s |
30s |
|
SeeDance 1.5 Pro, Kling 2.6, Veo 3.1 |
90~180s |
8s |
40s |
|
Kling O1, Sora 2 Pro |
180~360s |
8s |
60s |
| image_to_video |
Same ranges as text_to_video |
— |
8s |
40s |
| first_last_frame / reference |
Kling O1, Veo 3.1 |
180~360s |
8s |
60s |
| text_to_music |
DouBao BGM / Song |
10~25s |
5s |
10s |
|
Suno (sonic-v5) |
20~45s |
5s |
15s |
estimated_max_seconds = upper bound of the range (e.g. 60 for SeeDream 4.5, 40 for Nano Banana2, 120 for Nano Banana Pro, 180 for Kling 2.6, 360 for Kling O1).
Step 1 — Pre-Generation Notification
Before calling the create API, immediately send:
[Emoji] 开始生成 [内容类型],请稍候…
• 模型:[Model Name]
• 预计耗时:[X ~ Y 秒]
• 消耗积分:[N pts]
Emoji by content type:
- 图片 →
🎨
- 视频 →
🎬(加注:视频生成需要较长时间,我会定时汇报进度)
- 音乐 →
🎵
Cost transparency (new requirement):
- Always show credit cost with model tier context
- For expensive models (>50 pts), offer cheaper alternative proactively
- Examples:
- Balanced (default): "使用 Wan 2.6(25 积分,最新 Wan)"
- Premium (user explicit): "使用高端模型 Kling O1(48-120 积分),质量最佳"
- Premium (auto-selected): "使用 Wan 2.6(25 积分)。若需更高质量可选 Kling O1(48 积分起)"
- Budget (user asked): "使用 Vidu Q2(5 积分,最省钱)"
Adapt language to match the user (Chinese / English). For video, always add a note that it takes longer. For expensive models, always mention cheaper alternatives unless user explicitly requested premium.
Step 2 — Progress Updates
Poll the task detail API every [Poll Every] seconds per the table.
Send a progress update every [Send Progress Every] seconds.
⏳ 正在生成中… [P]%
已等待 [elapsed]s,预计最长 [max]s
Progress formula:
P = min(95, floor(elapsed_seconds / estimated_max_seconds * 100))
- Cap at 95% — never reach 100% until the API confirms
success
- If
elapsed > estimated_max: freeze at 95%, append 「快了,稍等一下…」
- For video with max=360s: at 120s → 33%, at 250s → 69%, at 400s → 95% (frozen)
Step 3 — Success Notification
When task status = success, send:
✅ [内容类型]生成成功!
• 模型:[Model Name]
• 耗时:预计 [X~Y]s,实际 [actual]s
• 消耗积分:[N pts]
[结果链接]
Step 4 — Failure Notification
When task status = failed or any API/network error, send:
❌ [内容类型]生成失败
• 原因:[natural_language_error_message]
• 建议改用:
- [Alt Model 1]([特点],[N pts])
- [Alt Model 2]([特点],[N pts])
需要我帮你用其他模型重试吗?
⚠️ CRITICAL: Error Message Translation
NEVER show technical error messages to users. Always translate API errors into natural language:
| Technical Error |
❌ Never Say |
✅ Say Instead (Chinese) |
✅ Say Instead (English) |
"Invalid product attribute" / "Insufficient points" |
Invalid product attribute |
生成参数配置异常,请稍后重试 |
Configuration error, please try again later |
Error 6006 (credit mismatch) |
Error 6006 |
积分计算异常,系统正在修复 |
Points calculation error, system is fixing |
Error 6010 (attribute_id mismatch) |
Attribute ID does not match |
模型参数不匹配,请尝试其他模型 |
Model parameters incompatible, try another model |
error 400 (bad request) |
error 400 / Bad request |
请求参数有误,请稍后重试 |
Invalid request parameters, please try again |
resource_status == 2 |
Resource status 2 / Failed |
生成过程遇到问题,建议换个模型试试 |
Generation failed, please try another model |
status == "failed" (no details) |
Task failed |
这次生成没成功,要不换个模型试试? |
Generation unsuccessful, try a different model? |
timeout |
Task timed out / Timeout error |
生成时间过长已超时,建议用更快的模型 |
Generation took too long, try a faster model |
| Network error / Connection refused |
Connection refused / Network error |
网络连接不稳定,请检查网络后重试 |
Network connection unstable, check network and retry |
| API key invalid |
Invalid API key / 401 Unauthorized |
API 密钥无效,请联系管理员 |
API key invalid, contact administrator |
| Rate limit exceeded |
429 Too Many Requests / Rate limit |
请求过于频繁,请稍等片刻再试 |
Too many requests, please wait a moment |
| Prompt moderation (Sora only) |
Content policy violation |
提示词包含敏感内容,请修改后重试 |
Prompt contains restricted content, please modify |
| Model unavailable |
Model not available / 503 Service Unavailable |
当前模型暂时不可用,建议换个模型 |
Model temporarily unavailable, try another model |
Generic fallback (when error is unknown):
- Chinese:
生成过程遇到问题,请稍后重试或换个模型试试
- English:
Generation encountered an issue, please try again or use another model
Best Practices:
- Focus on user action: Tell users what to do next, not what went wrong technically
- Be reassuring: Use phrases like "建议换个模型试试" instead of "失败了"
- Avoid blame: Never say "你的提示词有问题" → say "提示词需要调整一下"
- Provide alternatives: Always suggest 1-2 alternative models in the failure message
Failure fallback by task type:
| Task Type |
Failed Model |
First Alt |
Second Alt |
| text_to_image |
SeeDream 4.5 |
Nano Banana2 (4pts, fast) |
Nano Banana Pro (10-18pts, premium) |
| text_to_image |
Nano Banana2 |
SeeDream 4.5 (5pts, better quality) |
Nano Banana Pro (10-18pts) |
| text_to_image |
Nano Banana Pro |
SeeDream 4.5 (5pts) |
Nano Banana2 (4pts, budget) |
| image_to_image |
SeeDream 4.5 |
Nano Banana2 (4pts, fast) |
Nano Banana Pro (10pts) |
| image_to_image |
Nano Banana2 |
SeeDream 4.5 (5pts) |
Nano Banana Pro (10pts) |
| image_to_image |
Nano Banana Pro |
SeeDream 4.5 (5pts) |
Nano Banana2 (4pts) |
| text_to_video |
Kling O1 |
Wan 2.6 (25pts) |
Vidu Q2 (5pts) |
| text_to_video |
Google Veo 3.1 |
Kling O1 (48pts) |
Sora 2 Pro (122pts) |
| text_to_video |
Any |
Wan 2.6 (25pts, most popular) |
Hailuo 2.0 (5pts) |
| image_to_video |
Wan 2.6 |
Kling O1 (48pts) |
Hailuo 2.0 i2v (25pts) |
| image_to_video |
Any |
Wan 2.6 (25pts, most popular) |
Vidu Q2 Pro (20pts) |
| first_last / reference |
Kling O1 |
Kling 2.6 (80pts) |
Veo 3.1 (70pts+) |
| text_to_music |
Suno |
DouBao BGM (6pts) |
DouBao Song (6pts) |
| text_to_music |
DouBao |
Suno (21pts) |
DouBao BGM/Song (互换) |
Supported Models at a Glance
Source: production GET /open/v1/product/list (2026-02-27). Model count reduced significantly. Always query product list API at runtime.
Image Generation (3 models each)
| Category |
Name |
model_id |
Cost |
| text_to_image |
SeeDream 4.5 🌟 |
doubao-seedream-4.5 |
5 pts |
| text_to_image |
Nano Banana2 💚 |
gemini-3.1-flash-image |
4/6/10/13 pts |
| text_to_image |
Nano Banana Pro |
gemini-3-pro-image |
10/10/18 pts |
| image_to_image |
SeeDream 4.5 🌟 |
doubao-seedream-4.5 |
5 pts |
| image_to_image |
Nano Banana2 💚 |
gemini-3.1-flash-image |
4/6/10/13 pts |
| image_to_image |
Nano Banana Pro |
gemini-3-pro-image |
10 pts |
Nano Banana2 size options: 512px (4pts), 1K (6pts), 2K (10pts), 4K (13pts)
Nano Banana Pro size options: 1K (10pts), 2K (10pts), 4K (18pts for t2i / 10pts for i2i)
❌ Removed: SeeDream 3.0/4.0, Nano Banana (gemini-2.5), GPT Image 1.0/1.5, Wan 2.6 t2i/i2i, Midjourney, Imagen 4, SeedEdit 3.0
Video Generation
| Category |
Name |
model_id |
Cost Range |
| text_to_video (14) |
Wan 2.6 🔥 |
wan2.6-t2v |
25-120 pts |
|
Hailuo 2.3 |
MiniMax-Hailuo-2.3 |
32+ pts |
|
Hailuo 2.0 |
MiniMax-Hailuo-02 |
5+ pts |
|
Vidu Q2 |
viduq2 |
5-70 pts |
|
SeeDance 1.5 Pro |
doubao-seedance-1.5-pro |
20+ pts |
|
Sora 2 Pro |
sora-2-pro |
122+ pts |
|
Kling O1 |
kling-video-o1 |
48-120 pts |
|
Kling 2.6 |
kling-v2-6 |
80+ pts |
|
Google Veo 3.1 |
veo-3.1-generate-preview |
70-330 pts |
|
Pixverse V5.5 / V5 / V4.5 / V4 / V3.5 |
pixverse |
12-48 pts |
| image_to_video (14) |
Wan 2.6 🔥 |
wan2.6-i2v |
25-120 pts |
|
Hailuo 2.3 / 2.0 |
MiniMax-Hailuo-2.3/02 |
25-32 pts |
|
Vidu Q2 Pro |
viduq2-pro |
20-70 pts |
|
SeeDance 1.5 Pro |
doubao-seedance-1.5-pro |
47+ pts |
|
Sora 2 Pro |
sora-2-pro |
122+ pts |
|
Kling O1 / 2.6 |
kling-video-o1/v2-6 |
48-120 pts |
|
Google Veo 3.1 |
veo-3.1-generate-preview |
70-330 pts |
|
Pixverse V5.5-V3.5 |
pixverse |
12-48 pts |
| first_last_frame (11) |
Kling O1 🌟 |
kling-video-o1 |
48-120 pts |
|
Kling 2.6 |
kling-v2-6 |
80+ pts |
|
Others (9) |
Hailuo 2.0, Vidu Q2 Pro, SeeDance 1.5 Pro, Veo 3.1, Pixverse V5.5-V3.5 |
— |
| reference_image (6) |
Kling O1 🌟 |
kling-video-o1 |
48-120 pts |
|
Google Veo 3.1 |
veo-3.1-generate-preview |
70-330 pts |
|
Others (4) |
Vidu Q2, Pixverse V5.5/V5/V4.5 |
— |
❌ Removed video models: Vidu Q2 Turbo (viduq2-turbo), Wan 2.5/2.2 Plus, Kling 1.6/2.1/2.5, Sora 2 (non-Pro), Veo 3.0/3.1 Fast, SeeDance 1.0, Vidu Q1, Hailuo 2.3 Fast
| text_to_video | SeeDance 1.5 Pro / 1.0 Pro | doubao-seedance-1.5-pro / doubao-seedance-1.0-pro | 16 / 15 pts |
| text_to_video | Sora 2 Pro / Sora 2 | sora-2-pro / sora-2 | 120 / 35 pts |
| text_to_video | Kling O1 / 2.6 / 2.5 Turbo / 1.6 | kling-video-o1 / kling-v2-6 / kling-v2-5-turbo / kling-v1-6 | 48 / 80 / 24 / 32 pts |
| text_to_video | Google Veo 3.1 Fast / 3.1 / 3.0 | veo-3.1-fast-generate-preview / veo-3.1-generate-preview / veo-3.0-generate-preview | 55 / 140 / 280 pts |
| text_to_video | Pixverse V3.5–V5.5 | pixverse | 12 pts |
| image_to_video | Wan 2.6 / 2.6 Flash / 2.5 / 2.2 Plus | wan2.6-i2v / wan2.6-i2v-flash / wan2.5-i2v-preview / wan2.2-i2v-plus | 25 / 12 / 12 / 10 pts |
| image_to_video | Kling 2.1 Master | kling-v2-1-master | 150 pts |
| first_last_frame_to_video | Kling O1 | kling-video-o1 | 70 pts |
| reference_image_to_video | Kling O1 / Vidu Q2 / Q1 | kling-video-o1 / viduq2 / viduq1 | 48 / 10 / 25 pts |
Music Generation
| Category |
Name |
model_id |
Cost |
Notes |
| text_to_music |
Suno |
sonic |
25 pts |
sonic-v5; custom_mode, lyrics, vocal_gender |
| text_to_music |
DouBao BGM |
GenBGM |
30 pts |
Background music |
| text_to_music |
DouBao Song |
GenSong |
30 pts |
Song generation |
Always call GET /open/v1/product/list?category=<type> first to get the live attribute_id and form_config defaults required for task creation.
There are two equivalent route systems serving the same backend logic:
| Route |
Auth |
Use Case |
/open/v1/ |
Authorization: Bearer ima_* only |
Third-party / agent access |
/api/v3/ |
Token + API Key (dual auth) |
Frontend App |
This skill documents the /open/v1/ Open API. All business logic (credit validation, N-flattening, risk control) runs identically on both paths.
Environment
Base URL: https://api.imastudio.com
Required/recommended headers for all /open/v1/ endpoints:
| Header |
Required |
Value |
Notes |
Authorization |
✅ |
Bearer ima_your_api_key_here |
API key authentication |
x-app-source |
✅ |
ima_skills |
Fixed value — identifies skill-originated requests |
x_app_language |
recommended |
en / zh |
Product label language; defaults to en if omitted |
Authorization: Bearer ima_your_api_key_here
x-app-source: ima_skills
x_app_language: en
📤 When to Upload Images (Quick Reference)
The IMA Open API does NOT accept raw bytes or base64 images. All image inputs must be public HTTPS URLs.
| Task Type |
Input Required? |
Upload Before Create? |
Notes |
| text_to_image |
❌ No |
— |
Prompt only |
| image_to_image |
✅ Yes (1 image) |
✅ Upload first |
Single input image |
| text_to_video |
❌ No |
— |
Prompt only |
| image_to_video |
✅ Yes (1 image) |
✅ Upload first |
Single input image |
| first_last_frame_to_video |
✅ Yes (2 images) |
✅ Upload first |
First + last frame |
| reference_image_to_video |
✅ Yes (1+ images) |
✅ Upload first |
Reference image(s) |
| text_to_music |
❌ No |
— |
Prompt only |
Upload flow:
- User provides local file path or bytes → call
prepare_image_url() (see section below)
- User provides HTTPS URL → use directly, no upload needed
- Use the returned CDN URL (
fdl) as the value for input_images / src_img_url
Example workflow (image_to_image):
# User provides local file
image_url = prepare_image_url("/path/to/photo.jpg", api_key)
# → Returns: https://ima-ga.esxscloud.com/webAgent/privite/2026/02/27/..._uuid.jpeg
# Then create task with this URL
create_task(
task_type="image_to_image",
input_images=[image_url], # Use uploaded URL
prompt="turn into oil painting"
)
⚠️ MANDATORY: Always Query Product List First
CRITICAL: You MUST call /open/v1/product/list BEFORE creating any task.
The attribute_id field is REQUIRED in the create request. If it is 0 or missing, you get:
"Invalid product attribute" → "Insufficient points" → task fails completely.
NEVER construct a create request from the model table alone. Always fetch the product first.
How to get attribute_id (all task types)
# Query product list with the correct category
GET /open/v1/product/list?app=ima&platform=web&category=<task_type>
# task_type: text_to_image | image_to_image | text_to_video | image_to_video |
# first_last_frame_to_video | reference_image_to_video | text_to_music
# Walk the V2 tree to find your target model (type=3 leaf nodes only)
for group in response["data"]:
for version in group.get("children", []):
if version["type"] == "3" and version["model_id"] == target_model_id:
attribute_id = version["credit_rules"][0]["attribute_id"]
credit = version["credit_rules"][0]["points"]
model_version = version["id"] # = version_id / model_version
model_name = version["name"]
form_defaults = {f["field"]: f["value"] for f in version["form_config"]}
break
Quick Reference: Known attribute_ids
Pre-queried values for convenience. Always call the product list at runtime for accuracy.
| Model |
Task Type |
model_id |
attribute_id |
credit |
Notes |
| text_to_image |
|
|
|
|
|
| SeeDream 4.5 |
text_to_image |
doubao-seedream-4.5 |
2341 |
5 pts |
Default, balanced |
| Nano Banana Pro (1K) |
text_to_image |
gemini-3-pro-image |
2399 |
10 pts |
1024×1024 |
| Nano Banana Pro (2K) |
text_to_image |
gemini-3-pro-image |
2400 |
10 pts |
2048×2048 |
| Nano Banana Pro (4K) |
text_to_image |
gemini-3-pro-image |
2401 |
18 pts |
4096×4096 |
| text_to_video |
|
|
|
|
|
| Wan 2.6 (720P, 5s) |
text_to_video |
wan2.6-t2v |
2057 |
25 pts |
Default, balanced |
| Wan 2.6 (1080P, 5s) |
text_to_video |
wan2.6-t2v |
2058 |
40 pts |
— |
| Wan 2.6 (720P, 10s) |
text_to_video |
wan2.6-t2v |
2059 |
50 pts |
— |
| Wan 2.6 (1080P, 10s) |
text_to_video |
wan2.6-t2v |
2060 |
80 pts |
— |
| Wan 2.6 (720P, 15s) |
text_to_video |
wan2.6-t2v |
2061 |
75 pts |
— |
| Wan 2.6 (1080P, 15s) |
text_to_video |
wan2.6-t2v |
2062 |
120 pts |
— |
| Kling O1 (5s, std) |
text_to_video |
kling-video-o1 |
2313 |
48 pts |
Latest Kling |
| Kling O1 (5s, pro) |
text_to_video |
kling-video-o1 |
2314 |
60 pts |
— |
| Kling O1 (10s, std) |
text_to_video |
kling-video-o1 |
2315 |
96 pts |
— |
| Kling O1 (10s, pro) |
text_to_video |
kling-video-o1 |
2316 |
120 pts |
— |
| text_to_music |
|
|
|
|
|
| Suno (sonic-v4) |
text_to_music |
sonic |
2370 |
25 pts |
Default |
| DouBao BGM |
text_to_music |
GenBGM |
4399 |
30 pts |
— |
| DouBao Song |
text_to_music |
GenSong |
4398 |
30 pts |
— |
| All others |
any |
— |
→ query /open/v1/product/list |
— |
Always runtime query |
⚠️ Production warning: attribute_id and credit values change frequently in production. Always call /open/v1/product/list at runtime; above table is pre-queried reference only (2026-02-27).
Common Mistakes (and resulting errors)
| Mistake |
Error |
attribute_id is 0 or missing |
"Invalid product attribute" + "Insufficient points" |
attribute_id outdated (production changed) |
Same errors; always query product list first |
attribute_id doesn't match parameter combination |
Error 6010: "Attribute ID does not match the calculated rule" |
prompt at outer parameters[] level |
Prompt ignored; wrong routing |
cast missing from inner parameters.parameters |
Billing validation failure |
credit value wrong or missing |
Error 6006 |
model_name / model_version missing |
Wrong backend routing |
| Skipped product list, used table values directly |
All of the above |
⚠️ Critical for Google Veo 3.1 and multi-rule models:
Models like Google Veo 3.1 have multiple credit_rules, each with a different attribute_id for different parameter combinations:
720p + 4s + optimized → attribute_id A
720p + 8s + optimized → attribute_id B
4K + 4s + high → attribute_id C
The script automatically selects the correct attribute_id by matching your parameters (duration, resolution, compression_quality, generate_audio) against each
…(truncated)
1---
2name: ima-studio
3version: 1.0.3
4category: file-generation
5author: IMA Studio (imastudio.com)
6keywords: imastudio, ai creation, multimodal
7argument-hint: "[text prompt, image URL, or music description]"
8description: >
9 Use for any IMA AI content generation: images, videos, and music via IMA Open API.
10 IMPORTANT — Default model selection rule: always recommend the NEWEST and most POPULAR model,
11 NOT the cheapest. Defaults: image → SeeDream 4.5 (doubao-seedream-4.5, 5pts);
12 image budget → Nano Banana2 (gemini-3.1-flash-image, 4pts for 512px);
13 video text_to_video → Wan 2.6 (wan2.6-t2v, 25pts) — most popular, balanced cost;
14 video image_to_video → Wan 2.6 (wan2.6-i2v, 25pts);
15 music → Suno sonic (25pts).
16 Production models (2026-02-27) — Image text_to_image (3): SeeDream 4.5, Nano Banana2, Nano Banana Pro.
17 Image image_to_image (3): SeeDream 4.5, Nano Banana2, Nano Banana Pro.
18 Video text_to_video (14): Wan 2.6, Hailuo 2.0/2.3, Vidu Q2, SeeDance 1.5 Pro, Sora 2 Pro,
19 Kling O1/2.6, Google Veo 3.1, Pixverse V3.5-V5.5.
20 Video image_to_video (14): Wan 2.6, Hailuo 2.0/2.3, Vidu Q2 Pro, SeeDance 1.5 Pro, Sora 2 Pro,
21 Kling O1/2.6, Google Veo 3.1, Pixverse V3.5-V5.5.
22 Video first_last_frame_to_video (10): Hailuo 2.0, Vidu Q2 Pro, Kling O1/2.6,
23 Google Veo 3.1, Pixverse V3.5-V5.5.
24 Video reference_image_to_video (9): Vidu Q2, Kling O1, Google Veo 3.1, Pixverse (all versions).
25 Music text_to_music (3): Suno sonic/sonic-v5, DouBao BGM, DouBao Song.
26 Use this all-in-one skill when a task spans multiple media types; use the focused
27 ima-image-ai / ima-video-ai / ima-voice-ai skills for single-media workflows.
28 Requires an ima_* API key.
29metadata:
30 source: https://skillmd.com/skills/modbender/ima-studio
31---
32
33# IMA AI Creation
34
35## ⚙️ How This Skill Works
36
37**For transparency:** This skill uses a bundled Python script (`scripts/ima_create.py`) to call the IMA Open API. The script:
38- Sends your prompt to **two IMA-owned domains** (see "Network Endpoints" below)
39- Uses `--user-id` **only locally** as a key for storing your model preferences
40- Returns image/video/music URLs when generation is complete
41
42**What gets sent to IMA servers:**
43- ✅ Your prompt/description (image/video/music)
44- ✅ Model selection (SeeDream/Wan/Suno/etc.)
45- ✅ Generation parameters (size, duration, style, etc.)
46- ❌ NO API key in prompts (key is used for authentication only)
47- ❌ NO user_id (it's only used locally)
48
49**What's stored locally:**
50- `~/.openclaw/memory/ima_prefs.json` - Your model preferences (< 1 KB)
51- `~/.openclaw/logs/ima_skills/` - Generation logs (auto-deleted after 7 days)
52- See [SECURITY.md](SECURITY.md) for complete privacy policy
53
54---
55
56## 🌐 Network Endpoints Used
57
58| Domain | Owner | Purpose | Data Sent | Privacy |
59|--------|-------|---------|-----------|---------|
60| `api.imastudio.com` | IMA Studio | Main API (product list, task creation, task polling) | Prompts, model IDs, generation params, **your API key** | Standard HTTPS, data processed for AI generation |
61| `imapi.liveme.com` | IMA Studio | Image/Video upload service (presigned URL generation) | **Your API key**, file metadata (MIME type, extension) | Standard HTTPS, used for image/video tasks only |
62| `*.aliyuncs.com`, `*.esxscloud.com` | Alibaba Cloud (OSS) | Image/video storage (file upload, CDN delivery) | Raw image/video bytes (via presigned URL, **NO API key**) | IMA-managed OSS buckets, presigned URLs expire after 7 days |
63
64**Key Points:**
65- **Music tasks** (`text_to_music`) only use `api.imastudio.com`.
66- **Image/video tasks** require `imapi.liveme.com` to obtain presigned URLs for uploading input images.
67- Your API key is sent to **both `api.imastudio.com` and `imapi.liveme.com`** (both owned by IMA Studio).
68- Verify network calls: `tcpdump -i any -n 'host api.imastudio.com or host imapi.liveme.com'` (see [SECURITY.md](SECURITY.md)).
69
70---
71
72## ⚠️ Credential Security Notice
73
74**Your API key is sent to both IMA-owned domains:**
751. `Authorization: Bearer ima_xxx...` → `api.imastudio.com` (main API)
762. Query param `appUid=ima_xxx...` → `imapi.liveme.com` (upload service)
77
78**Security best practices:**
79- 🧪 **Use test keys for experiments:** Generate a separate API key for testing.
80- 🔍 **Monitor usage:** Check `https://imastudio.com/dashboard` for unauthorized activity.
81- ⏱️ **Rotate keys:** Regenerate your API key periodically (monthly recommended).
82- 📊 **Review logs:** Check `~/.openclaw/logs/ima_skills/` for unexpected API calls.
83
84**Why two domains?** IMA Studio uses a microservices architecture:
85- **`api.imastudio.com`**: Core AI generation API
86- **`imapi.liveme.com`**: Specialized image/video upload service (shared infrastructure)
87
88Both domains are operated by IMA Studio. The same API key grants access to both services.
89
90### Agent Execution (Internal Reference)
91
92> **Note for users:** You can review the script source at `scripts/ima_create.py` anytime.
93> The agent uses this script to simplify API calls. **Music tasks** use only `api.imastudio.com`, while **image/video tasks** also call `imapi.liveme.com` for file uploads (see "Network Endpoints" above).
94
95Use the bundled script internally for all task types — it ensures correct parameter construction:
96
97```bash
98# ─── Image Generation ──────────────────────────────────────────────────────────
99
100# Basic text-to-image (default model)
101python3 {baseDir}/scripts/ima_create.py \
102 --api-key $IMA_API_KEY --task-type text_to_image \
103 --model-id doubao-seedream-4.5 --prompt "a cute puppy on grass, photorealistic" \
104 --user-id {user_id} --output-json
105
106# Text-to-image with size override (Nano Banana2)
107python3 {baseDir}/scripts/ima_create.py \
108 --api-key $IMA_API_KEY --task-type text_to_image \
109 --model-id gemini-3.1-flash-image --prompt "city skyline at sunset, 4K" \
110 --size 2k --user-id {user_id} --output-json
111
112# Image-to-image with input URL
113python3 {baseDir}/scripts/ima_create.py \
114 --api-key $IMA_API_KEY --task-type image_to_image \
115 --model-id doubao-seedream-4.5 --prompt "turn into oil painting style" \
116 --input-images https://example.com/photo.jpg --user-id {user_id} --output-json
117
118# ─── Video Generation ──────────────────────────────────────────────────────────
119
120# Basic text-to-video (default model, 5s 720P)
121python3 {baseDir}/scripts/ima_create.py \
122 --api-key $IMA_API_KEY --task-type text_to_video \
123 --model-id wan2.6-t2v --prompt "a puppy dancing happily, cinematic" \
124 --user-id {user_id} --output-json
125
126# Text-to-video with extra params (10s 1080P)
127python3 {baseDir}/scripts/ima_create.py \
128 --api-key $IMA_API_KEY --task-type text_to_video \
129 --model-id wan2.6-t2v --prompt "dramatic ocean waves, sunset" \
130 --extra-params '{"duration":10,"resolution":"1080P","aspect_ratio":"16:9"}' \
131 --user-id {user_id} --output-json
132
133# Image-to-video (animate static image)
134python3 {baseDir}/scripts/ima_create.py \
135 --api-key $IMA_API_KEY --task-type image_to_video \
136 --model-id wan2.6-i2v --prompt "camera slowly zooms in, gentle movement" \
137 --input-images https://example.com/photo.jpg --user-id {user_id} --output-json
138
139# First-last frame video (two images)
140python3 {baseDir}/scripts/ima_create.py \
141 --api-key $IMA_API_KEY --task-type first_last_frame_to_video \
142 --model-id kling-video-o1 --prompt "smooth transition between frames" \
143 --input-images https://example.com/frame1.jpg https://example.com/frame2.jpg \
144 --user-id {user_id} --output-json
145
146# ─── Music Generation ──────────────────────────────────────────────────────────
147
148# Basic text-to-music (Suno default)
149python3 {baseDir}/scripts/ima_create.py \
150 --api-key $IMA_API_KEY --task-type text_to_music \
151 --model-id sonic --prompt "upbeat electronic music, 120 BPM, no vocals" \
152 --user-id {user_id} --output-json
153
154# Music with custom lyrics (Suno custom mode)
155python3 {baseDir}/scripts/ima_create.py \
156 --api-key $IMA_API_KEY --task-type text_to_music \
157 --model-id sonic --prompt "pop ballad, emotional" \
158 --extra-params '{"custom_mode":true,"lyrics":"Your custom lyrics here...","vocal_gender":"female"}' \
159 --user-id {user_id} --output-json
160
161# Background music (DouBao BGM)
162python3 {baseDir}/scripts/ima_create.py \
163 --api-key $IMA_API_KEY --task-type text_to_music \
164 --model-id GenBGM --prompt "relaxing ambient music for meditation" \
165 --user-id {user_id} --output-json
166```
167
168The script outputs JSON with `url`, `model_name`, `credit` — use these values in the UX protocol messages below. The script internals (product list query, parameter construction, polling) are invisible to users.
169
170---
171
172## Overview
173
174Call IMA Open API to create AI-generated content. All endpoints require an `ima_*` API key. The core flow is: **query products → create task → poll until done**.
175
176---
177
178## 🔒 Security & Transparency Policy
179
180> **This skill is community-maintained and open for inspection.**
181
182### ✅ What Users CAN Do
183
184**Full transparency:**
185- ✅ **Review all source code**: Check `scripts/ima_create.py` and `ima_logger.py` anytime
186- ✅ **Verify network calls**: Music tasks use `api.imastudio.com` only; image/video tasks also use `imapi.liveme.com` (see "Network Endpoints" section)
187- ✅ **Inspect local data**: View `~/.openclaw/memory/ima_prefs.json` and log files
188- ✅ **Control privacy**: Delete preferences/logs anytime, or disable file writes (see below)
189
190**Configuration allowed:**
191- ✅ **Set API key** in environment or agent config:
192 - Environment variable: `export IMA_API_KEY=ima_your_key_here`
193 - OpenClaw/MCP config: Add `IMA_API_KEY` to agent's environment configuration
194 - Get your key at: https://imastudio.com
195- ✅ **Use scoped/test keys**: Test with limited API keys, rotate after testing
196- ✅ **Disable file writes**: Make prefs/logs read-only or symlink to `/dev/null`
197
198**Data control:**
199- ✅ **View stored data**: `cat ~/.openclaw/memory/ima_prefs.json`
200- ✅ **Delete preferences**: `rm ~/.openclaw/memory/ima_prefs.json` (resets to defaults)
201- ✅ **Delete logs**: `rm -rf ~/.openclaw/logs/ima_skills/` (auto-cleanup after 7 days anyway)
202- ✅ **Review security**: See [SECURITY.md](SECURITY.md) for complete privacy policy
203
204### ⚠️ Advanced Users: Fork & Modify
205
206If you need to modify this skill for your use case:
2071. **Fork the repository** (don't modify the original)
2082. **Update your fork** with your changes
2093. **Test thoroughly** with limited API keys
2104. **Document your changes** for troubleshooting
211
212**Note:** Modified skills may break API compatibility or introduce security issues. Official support only covers the unmodified version.
213
214### ❌ What to AVOID (Security Risks)
215
216**Actions that could compromise security:**
217- ❌ Sharing API keys publicly or in skill files
218- ❌ Modifying API endpoints to unknown servers
219- ❌ Disabling SSL/TLS certificate verification
220- ❌ Logging sensitive user data (prompts, IDs, etc.)
221- ❌ Bypassing authentication or billing mechanisms
222
223**Why this matters:**
2241. **API Compatibility**: Skill logic aligns with IMA Open API schema
2252. **Security**: Malicious modifications could leak credentials or bypass billing
2263. **Support**: Modified skills may not be supported
2274. **Community**: Breaking changes affect all users
228
229### 📋 Privacy & Data Handling Summary
230
231**What this skill does with your data:**
232
233| Data Type | Sent to IMA? | Stored Locally? | User Control |
234|-----------|-------------|-----------------|--------------|
235| Prompts (image/video/music) | ✅ Yes (required for generation) | ❌ No | None (required) |
236| API key | ✅ Yes (authentication header) | ❌ No | Set via env var |
237| user_id (optional CLI arg) | ❌ **Never** (local preference key only) | ✅ Yes (as prefs file key) | Change `--user-id` value |
238| Model preferences | ❌ No | ✅ Yes (~/.openclaw) | Delete anytime |
239| Generation logs | ❌ No | ✅ Yes (~/.openclaw) | Auto-cleanup 7 days |
240
241**Privacy recommendations:**
2421. **Use test/scoped API keys** for initial testing
2432. **Note**: `--user-id` is **never sent to IMA servers** - it's only used locally as a key for storing preferences in `~/.openclaw/memory/ima_prefs.json`
2443. **Review source code** at `scripts/ima_create.py` to verify network calls (search for `create_task` function)
2454. **Rotate API keys** after testing or if compromised
246
247**Get your IMA API key:** Visit https://imastudio.com to register and get started.
248
249### 🔧 For Skill Maintainers Only
250
251**Version control:**
252- All changes must go through Git with proper version bumps (semver)
253- CHANGELOG.md must document all changes
254- Production deployments require code review
255
256如果你需要定制功能,请:
2571. Fork 这个 Skill 创建私有版本(不保证兼容性)
2582. 或者联系 IMA 技术支持申请企业定制
259```
260
261### 🔧 For Skill Maintainers Only
262
263**Version control:**
264- All changes must go through Git with proper version bumps (semver)
265- CHANGELOG.md must document all changes
266- Production deployments require code review
267
268**File checksums (optional):**
269```bash
270# Verify skill integrity
271sha256sum SKILL.md scripts/ima_create.py
272```
273
274If users report issues, verify file integrity first.
275
276---
277
278## 🧠 User Preference Memory
279
280> User preferences **override** recommended defaults across ALL task types.
281> If a user has generated before, use their preferred model — not the system default.
282
283### Storage: `~/.openclaw/memory/ima_prefs.json`
284
285Single file, shared across all IMA skills:
286
287```json
288{
289 "user_{user_id}": {
290 "text_to_image": { "model_id": "doubao-seedream-4.5", "model_name": "SeeDream 4.5", "credit": 5, "last_used": "2026-02-27T03:07:27Z" },
291 "image_to_image": { "model_id": "doubao-seedream-4.5", "model_name": "SeeDream 4.5", "credit": 5, "last_used": "2026-02-27T03:07:27Z" },
292 "text_to_video": { "model_id": "wan2.6-t2v", "model_name": "Wan 2.6", "credit": 25, "last_used": "2026-02-27T10:00:00Z" },
293 "image_to_video": { "model_id": "wan2.6-i2v", "model_name": "Wan 2.6", "credit": 25, "last_used": "2026-02-27T10:00:00Z" },
294 "first_last_frame_to_video": { "model_id": "kling-video-o1", "model_name": "Kling O1", "credit": 48, "last_used": "2026-02-26T08:00:00Z" },
295 "reference_image_to_video": { "model_id": "kling-video-o1", "model_name": "Kling O1", "credit": 48, "last_used": "2026-02-26T08:00:00Z" },
296 "text_to_music": { "model_id": "sonic", "model_name": "Suno", "credit": 25, "last_used": "2026-02-26T06:00:00Z" }
297 }
298}
299```
300
301If the file or key doesn't exist, fall back to the ⭐ Recommended Defaults below.
302
303---
304
305### Model Selection Priority (Strict Order)
306
307```
3081. User explicitly specifies a model in this message
309 → use it, save as new preference, confirm if different from old preference
3102. User has a saved preference for this task type
311 → use it, mention "根据你的使用习惯"
3123. No preference exists
313 → use ⭐ Recommended Default, save after success
314```
315
316---
317
318### When to Read (Before Every Generation)
319
320```python
321import json, os
322
323prefs_path = os.path.expanduser("~/.openclaw/memory/ima_prefs.json")
324try:
325 with open(prefs_path) as f:
326 prefs = json.load(f)
327 user_pref = prefs.get(f"user_{user_id}", {}).get(task_type)
328except (FileNotFoundError, json.JSONDecodeError):
329 user_pref = None
330
331if user_pref:
332 model_id = user_pref["model_id"]
333 model_name = user_pref["model_name"]
334 credit = user_pref["credit"]
335 source = "preference" # pre-generation message: "根据你的使用习惯"
336else:
337 model_id, model_name, credit = RECOMMENDED_DEFAULTS[task_type]
338 source = "default"
339```
340
341### When to Write (After Every Successful Generation)
342
343```python
344os.makedirs(os.path.dirname(prefs_path), exist_ok=True)
345try:
346 with open(prefs_path) as f:
347 prefs = json.load(f)
348except (FileNotFoundError, json.JSONDecodeError):
349 prefs = {}
350
351from datetime import datetime, timezone
352prefs.setdefault(f"user_{user_id}", {})[task_type] = {
353 "model_id": model_id,
354 "model_name": model_name,
355 "credit": credit,
356 "last_used": datetime.now(timezone.utc).isoformat(),
357}
358with open(prefs_path, "w") as f:
359 json.dump(prefs, f, ensure_ascii=False, indent=2)
360```
361
362### When to Update (User Explicitly Changes Model)
363
364| User Says | Action |
365|-----------|--------|
366| `用XXX` / `换成XXX` / `改用XXX` / `use XXX` | Use that model this time AND save as new preference |
367| `以后都用XXX` / `默认用XXX` / `always use XXX` | Save preference + confirm: `✅ 已记住!以后 [类型] 生成默认用 [XXX]` |
368| `换个模型` / `try another model` | Show top 3 alternatives, let user pick; save chosen |
369| `用最好的` / `best quality` | Use highest-quality model for this type; save preference |
370| `用便宜的` / `cheapest` | Use lowest-cost model; only save if user adds "以后都用" |
371| `清除我的偏好` / `reset preference` | Delete `user_{user_id}.{task_type}` from prefs file; confirm |
372
373### Pre-Generation Notification (with preference)
374
375When using a saved preference, mention it naturally:
376
377```
378🎨 根据你的使用习惯,将用 [Model Name] 帮你生成…
379• 模型:[Model Name](你的常用模型)
380• 预计耗时:[X ~ Y 秒]
381• 消耗积分:[N pts]
382```
383
384### Preference Change Confirmation
385
386When user switches to a different model than their saved preference:
387
388```
389💡 你之前喜欢用 [Old Model],这次换成了 [New Model]。
390要把 [New Model] 设为以后的默认吗?
391回复「是」保存 / 回复「否」仅本次使用
392```
393
394---
395
396## ⭐ Recommended Defaults
397
398> **These are fallback defaults — only used when no user preference exists.**
399> **Always default to the newest and most popular model. Do NOT default to the cheapest.**
400
401| Task Type | Default Model | model_id | Cost | Why |
402|-----------|--------------|----------|------|-----|
403| text_to_image | **SeeDream 4.5** | `doubao-seedream-4.5` | 5 pts | Latest doubao flagship, photorealistic 4K |
404| image_to_image | **SeeDream 4.5** | `doubao-seedream-4.5` | 5 pts | Latest, best i2i quality |
405| text_to_video | **Wan 2.6** | `wan2.6-t2v` | 25 pts | 🔥 Most popular t2v, balanced cost. Premium → Hailuo 2.3 (38 pts) |
406| image_to_video | **Wan 2.6** | `wan2.6-i2v` | 25 pts | 🔥 Most popular i2v, 1080P |
407| first_last_frame_to_video | **Kling O1** | `kling-video-o1` | 48 pts | Newest Kling reasoning model |
408| reference_image_to_video | **Kling O1** | `kling-video-o1` | 48 pts | Best reference fidelity |
409| text_to_music | **Suno (sonic-v4)** | `sonic` | 25 pts | Latest Suno engine, best quality |
410
411**Quick selection guide (production as of 2026-02-27, sorted by popularity):**
412- **Image (3 models available)** → **SeeDream 4.5** (5, default); budget → Nano Banana2 (4, 512px); premium → Nano Banana Pro (10-18)
413- **🔥 Video from text (most popular)** → **Wan 2.6** (25, balanced); premium → Hailuo 2.3 (38); budget → Vidu Q2 (5)
414- **🔥 Video from image (most popular)** → **Wan 2.6** (25)
415- Music → **Suno** (25); DouBao BGM/Song (30 each)
416- Cheapest → Nano Banana2 512px (4) for image; Vidu Q2 (5) for video
417
418**⚠️ Production Image Models (3 available):**
419- SeeDream 4.5 (`doubao-seedream-4.5`) — 5 pts, default
420- Nano Banana Pro (`gemini-3-pro-image`) — 10/10/18 pts for 1K/2K/4K
421
422**All other image models mentioned in older documentation are no longer available in production.**
423
424**🌟 Parameter Support Notes (All Task Types):**
425
426### Image Models (text_to_image / image_to_image)
427- ❌ **aspect_ratio**: NOT supported by any production image model (all produce 1:1 or fixed aspect ratio only)
428- ✅ **size**:
429 - **Nano Banana2**: 512px, 1K, 2K, 4K (via different `attribute_id`s, 4-13 pts)
430 - **Nano Banana Pro**: 1K, 2K, 4K (via different `attribute_id`s, 10-18 pts)
431 - **SeeDream 4.5**: Adaptive default only (no size control, 5 pts)
432- ❌ **8K**: No model supports 8K (max is 4K via Nano Banana Pro)
433- ❌ **Custom aspect ratios** (7:3, 4:5, etc.): Not supported. Use video models as workaround.
434- ✅ **n**: Multiple outputs supported (1-4), credit × n
435
436### Video Models (text_to_video / image_to_video / first_last_frame / reference_image)
437- ✅ **resolution**: 540P, 720P, 1080P, 2K, 4K (model-dependent, higher res = higher cost)
438- ✅ **aspect_ratio**: 16:9, 9:16, 1:1, 4:3 (model-dependent, check `form_config`)
439- ✅ **duration**: 4s, 5s, 10s, 15s (model-dependent, longer = higher cost)
440- ⚠️ **generate_audio**: Supported by Veo 3.1, Kling O1, Hailuo (check `form_config`)
441- ✅ **prompt_extend**: AI-powered prompt enhancement (most models support)
442- ✅ **negative_prompt**: Content exclusion (most models support)
443- ✅ **shot_type**: Single/multi-shot control (model-dependent)
444- ✅ **seed**: Reproducibility control (most models support, -1 = random)
445- ✅ **n**: Multiple outputs (1-4), credit × n
446
447### Music Models (text_to_music)
448- ✅ **custom_mode**: Suno only (enables vocal_gender, lyrics support)
449- ✅ **vocal_gender**: Suno only (male/female/mixed, requires custom_mode=True)
450- ✅ **lyrics**: Suno only (custom lyrics support, requires custom_mode=True)
451- ❌ **duration**: Fixed-length output (DouBao ~30s, Suno ~2min, not user-controllable)
452- ✅ **n**: Multiple outputs supported (1-2), credit × n
453
454### Common Parameter Patterns
455- **n (batch generation)**: Supported by ALL models. Cost = base_credit × n. Creates n independent resources.
456- **seed**: Supported by most models (-1 = random, >0 = reproducible results)
457- **prompt_extend**: AI-powered prompt enhancement (video models only)
458
459### Decision Tree: When User Requests Unsupported Features
460
461```
462User asks for custom aspect ratio image (e.g. "7:3 landscape")
463 → ❌ Image models don't support custom ratios
464 → ✅ Solution: "图片模型不支持自定义比例。建议用视频模型(Wan 2.6 t2v)生成16:9视频,然后截取首帧作为图片。"
465
466User asks for 8K image
467 → ❌ No model supports 8K
468 → ✅ Solution: "当前最高支持4K分辨率(Nano Banana Pro,18积分)。要使用吗?"
469
470User asks for video with audio
471 → Check model: Veo 3.1 / Kling O1 / Hailuo have generate_audio
472 → ✅ Solution: "Veo 3.1 和 Kling O1 支持音频生成(需在参数中设置 generate_audio=True)。要用哪个?"
473
474User asks for long music (e.g. "5 minute track")
475 → ❌ Duration not user-controllable
476 → ✅ Solution: "Suno 生成约2分钟音乐。需要更长时长可以生成多段后拼接。"
477
478User asks for 30s video
479 → Check model: Most models max 15s
480 → ✅ Solution: "当前最长15秒。可选模型:Wan 2.6(15s, 75积分), Kling O1(10s, 96积分)。"
481```
482
483**When user requests unsupported combinations:**
484- Any image model + custom aspect_ratio → "不支持自定义比例,建议用视频模型(Wan 2.6)生成后截取首帧"
485- Any model + 8K → "最高支持4K (Nano Banana Pro, 18 pts)"
486- Image model + 7:3 → "图片模型不支持,建议用 Wan 2.6 视频模型(支持16:9/9:16)生成后截帧"
487- Video + audio (unsupported model) → "该模型不支持音频。建议用 Veo 3.1 或 Kling O1 (支持 generate_audio 参数)"
488- Music + custom duration → "音乐时长由模型固定(Suno约2分钟,DouBao约30秒),无法自定义"
489
490
491---
492
493## 💬 User Experience Protocol (IM / Feishu / Discord)
494
495> This skill runs inside IM platforms (Feishu, Discord via OpenClaw).
496> Generation takes 10 seconds (music) up to 6 minutes (video). **Never let users wait in silence.**
497> Always follow all 4 steps below, every single time.
498
499### 🚫 Never Say to Users
500
501The following are **internal implementation details**. Never mention them in any user-facing message, under any circumstances:
502
503| ❌ Never say | ✅ What users care about |
504|-------------|--------------------------|
505| `ima_create.py` / 脚本 / script | — |
506| 自动化脚本 / automation script | — |
507| 自动处理产品列表查询 | — |
508| 自动解析参数和配置 | — |
509| 智能轮询 / polling / 轮询 | — |
510| product list / 商品列表接口 | — |
511| attribute_id / model_version / form_config | — |
512| API 调用 / HTTP 请求 | — |
513| 任何技术参数名 | 模型名称、积分、生成时间 |
514
515User messages must only contain: **model name, estimated/actual time, credits consumed, result URL, and natural language status updates.**
516
517---
518
519### Estimated Generation Time (All Task Types)
520
521| Task Type | Model | Estimated Time | Poll Every | Send Progress Every |
522|-----------|-------|---------------|------------|---------------------|
523| **text_to_image** | SeeDream 4.5 | 25~60s | 5s | 20s |
524| | Nano Banana2 💚 | 20~40s | 5s | 15s |
525| | Nano Banana Pro | 60~120s | 5s | 30s |
526| **image_to_image** | SeeDream 4.5 | 25~60s | 5s | 20s |
527| | Nano Banana2 💚 | 20~40s | 5s | 15s |
528| | Nano Banana Pro | 60~120s | 5s | 30s |
529| **text_to_video** | Wan 2.6, Hailuo 2.0/2.3, Vidu Q2, Pixverse | 60~120s | 8s | 30s |
530| | SeeDance 1.5 Pro, Kling 2.6, Veo 3.1 | 90~180s | 8s | 40s |
531| | Kling O1, Sora 2 Pro | 180~360s | 8s | 60s |
532| **image_to_video** | Same ranges as text_to_video | — | 8s | 40s |
533| **first_last_frame / reference** | Kling O1, Veo 3.1 | 180~360s | 8s | 60s |
534| **text_to_music** | DouBao BGM / Song | 10~25s | 5s | 10s |
535| | Suno (sonic-v5) | 20~45s | 5s | 15s |
536
537`estimated_max_seconds` = upper bound of the range (e.g. 60 for SeeDream 4.5, 40 for Nano Banana2, 120 for Nano Banana Pro, 180 for Kling 2.6, 360 for Kling O1).
538
539---
540
541### Step 1 — Pre-Generation Notification
542
543**Before calling the create API**, immediately send:
544
545```
546[Emoji] 开始生成 [内容类型],请稍候…
547• 模型:[Model Name]
548• 预计耗时:[X ~ Y 秒]
549• 消耗积分:[N pts]
550```
551
552**Emoji by content type:**
553- 图片 → `🎨`
554- 视频 → `🎬`(加注:视频生成需要较长时间,我会定时汇报进度)
555- 音乐 → `🎵`
556
557**Cost transparency (new requirement):**
558- Always show credit cost with model tier context
559- For expensive models (>50 pts), offer cheaper alternative proactively
560- Examples:
561 - Balanced (default): "使用 Wan 2.6(25 积分,最新 Wan)"
562 - Premium (user explicit): "使用高端模型 Kling O1(48-120 积分),质量最佳"
563 - Premium (auto-selected): "使用 Wan 2.6(25 积分)。若需更高质量可选 Kling O1(48 积分起)"
564 - Budget (user asked): "使用 Vidu Q2(5 积分,最省钱)"
565
566> Adapt language to match the user (Chinese / English). For video, always add a note that it takes longer. For expensive models, always mention cheaper alternatives unless user explicitly requested premium.
567
568---
569
570### Step 2 — Progress Updates
571
572Poll the task detail API every `[Poll Every]` seconds per the table.
573Send a progress update every `[Send Progress Every]` seconds.
574
575```
576⏳ 正在生成中… [P]%
577已等待 [elapsed]s,预计最长 [max]s
578```
579
580**Progress formula:**
581```
582P = min(95, floor(elapsed_seconds / estimated_max_seconds * 100))
583```
584
585- **Cap at 95%** — never reach 100% until the API confirms `success`
586- If `elapsed > estimated_max`: freeze at 95%, append `「快了,稍等一下…」`
587- For video with max=360s: at 120s → 33%, at 250s → 69%, at 400s → 95% (frozen)
588
589---
590
591### Step 3 — Success Notification
592
593When task status = `success`, send:
594
595```
596✅ [内容类型]生成成功!
597• 模型:[Model Name]
598• 耗时:预计 [X~Y]s,实际 [actual]s
599• 消耗积分:[N pts]
600
601[结果链接]
602```
603
604---
605
606### Step 4 — Failure Notification
607
608When task status = `failed` or any API/network error, send:
609
610```
611❌ [内容类型]生成失败
612• 原因:[natural_language_error_message]
613• 建议改用:
614 - [Alt Model 1]([特点],[N pts])
615 - [Alt Model 2]([特点],[N pts])
616
617需要我帮你用其他模型重试吗?
618```
619
620**⚠️ CRITICAL: Error Message Translation**
621
622**NEVER show technical error messages to users.** Always translate API errors into natural language:
623
624| Technical Error | ❌ Never Say | ✅ Say Instead (Chinese) | ✅ Say Instead (English) |
625|----------------|-------------|------------------------|------------------------|
626| `"Invalid product attribute"` / `"Insufficient points"` | Invalid product attribute | 生成参数配置异常,请稍后重试 | Configuration error, please try again later |
627| `Error 6006` (credit mismatch) | Error 6006 | 积分计算异常,系统正在修复 | Points calculation error, system is fixing |
628| `Error 6010` (attribute_id mismatch) | Attribute ID does not match | 模型参数不匹配,请尝试其他模型 | Model parameters incompatible, try another model |
629| `error 400` (bad request) | error 400 / Bad request | 请求参数有误,请稍后重试 | Invalid request parameters, please try again |
630| `resource_status == 2` | Resource status 2 / Failed | 生成过程遇到问题,建议换个模型试试 | Generation failed, please try another model |
631| `status == "failed"` (no details) | Task failed | 这次生成没成功,要不换个模型试试? | Generation unsuccessful, try a different model? |
632| `timeout` | Task timed out / Timeout error | 生成时间过长已超时,建议用更快的模型 | Generation took too long, try a faster model |
633| Network error / Connection refused | Connection refused / Network error | 网络连接不稳定,请检查网络后重试 | Network connection unstable, check network and retry |
634| API key invalid | Invalid API key / 401 Unauthorized | API 密钥无效,请联系管理员 | API key invalid, contact administrator |
635| Rate limit exceeded | 429 Too Many Requests / Rate limit | 请求过于频繁,请稍等片刻再试 | Too many requests, please wait a moment |
636| Prompt moderation (Sora only) | Content policy violation | 提示词包含敏感内容,请修改后重试 | Prompt contains restricted content, please modify |
637| Model unavailable | Model not available / 503 Service Unavailable | 当前模型暂时不可用,建议换个模型 | Model temporarily unavailable, try another model |
638
639**Generic fallback (when error is unknown):**
640- Chinese: `生成过程遇到问题,请稍后重试或换个模型试试`
641- English: `Generation encountered an issue, please try again or use another model`
642
643**Best Practices:**
6441. **Focus on user action**: Tell users what to do next, not what went wrong technically
6452. **Be reassuring**: Use phrases like "建议换个模型试试" instead of "失败了"
6463. **Avoid blame**: Never say "你的提示词有问题" → say "提示词需要调整一下"
6474. **Provide alternatives**: Always suggest 1-2 alternative models in the failure message
648
649**Failure fallback by task type:**
650
651| Task Type | Failed Model | First Alt | Second Alt |
652|-----------|-------------|-----------|------------|
653| text_to_image | SeeDream 4.5 | Nano Banana2 (4pts, fast) | Nano Banana Pro (10-18pts, premium) |
654| text_to_image | Nano Banana2 | SeeDream 4.5 (5pts, better quality) | Nano Banana Pro (10-18pts) |
655| text_to_image | Nano Banana Pro | SeeDream 4.5 (5pts) | Nano Banana2 (4pts, budget) |
656| image_to_image | SeeDream 4.5 | Nano Banana2 (4pts, fast) | Nano Banana Pro (10pts) |
657| image_to_image | Nano Banana2 | SeeDream 4.5 (5pts) | Nano Banana Pro (10pts) |
658| image_to_image | Nano Banana Pro | SeeDream 4.5 (5pts) | Nano Banana2 (4pts) |
659| text_to_video | Kling O1 | Wan 2.6 (25pts) | Vidu Q2 (5pts) |
660| text_to_video | Google Veo 3.1 | Kling O1 (48pts) | Sora 2 Pro (122pts) |
661| text_to_video | Any | Wan 2.6 (25pts, most popular) | Hailuo 2.0 (5pts) |
662| image_to_video | Wan 2.6 | Kling O1 (48pts) | Hailuo 2.0 i2v (25pts) |
663| image_to_video | Any | Wan 2.6 (25pts, most popular) | Vidu Q2 Pro (20pts) |
664| first_last / reference | Kling O1 | Kling 2.6 (80pts) | Veo 3.1 (70pts+) |
665| text_to_music | Suno | DouBao BGM (6pts) | DouBao Song (6pts) |
666| text_to_music | DouBao | Suno (21pts) | DouBao BGM/Song (互换) |
667
668---
669
670## Supported Models at a Glance
671
672> **Source: production `GET /open/v1/product/list` (2026-02-27).** Model count reduced significantly. Always query product list API at runtime.
673
674### Image Generation (3 models each)
675
676| Category | Name | model_id | Cost |
677|----------|------|----------|------|
678| **text_to_image** | SeeDream 4.5 🌟 | `doubao-seedream-4.5` | 5 pts |
679| text_to_image | Nano Banana2 💚 | `gemini-3.1-flash-image` | 4/6/10/13 pts |
680| text_to_image | Nano Banana Pro | `gemini-3-pro-image` | 10/10/18 pts |
681| **image_to_image** | SeeDream 4.5 🌟 | `doubao-seedream-4.5` | 5 pts |
682| image_to_image | Nano Banana2 💚 | `gemini-3.1-flash-image` | 4/6/10/13 pts |
683| image_to_image | Nano Banana Pro | `gemini-3-pro-image` | 10 pts |
684
685**Nano Banana2 size options**: 512px (4pts), 1K (6pts), 2K (10pts), 4K (13pts)
686**Nano Banana Pro size options**: 1K (10pts), 2K (10pts), 4K (18pts for t2i / 10pts for i2i)
687
688❌ **Removed**: SeeDream 3.0/4.0, Nano Banana (gemini-2.5), GPT Image 1.0/1.5, Wan 2.6 t2i/i2i, Midjourney, Imagen 4, SeedEdit 3.0
689
690### Video Generation
691
692| Category | Name | model_id | Cost Range |
693|----------|------|----------|-----------|
694| **text_to_video (14)** | Wan 2.6 🔥 | `wan2.6-t2v` | 25-120 pts |
695| | Hailuo 2.3 | `MiniMax-Hailuo-2.3` | 32+ pts |
696| | Hailuo 2.0 | `MiniMax-Hailuo-02` | 5+ pts |
697| | Vidu Q2 | `viduq2` | 5-70 pts |
698| | SeeDance 1.5 Pro | `doubao-seedance-1.5-pro` | 20+ pts |
699| | Sora 2 Pro | `sora-2-pro` | 122+ pts |
700| | Kling O1 | `kling-video-o1` | 48-120 pts |
701| | Kling 2.6 | `kling-v2-6` | 80+ pts |
702| | Google Veo 3.1 | `veo-3.1-generate-preview` | 70-330 pts |
703| | Pixverse V5.5 / V5 / V4.5 / V4 / V3.5 | `pixverse` | 12-48 pts |
704| **image_to_video (14)** | Wan 2.6 🔥 | `wan2.6-i2v` | 25-120 pts |
705| | Hailuo 2.3 / 2.0 | `MiniMax-Hailuo-2.3/02` | 25-32 pts |
706| | Vidu Q2 Pro | `viduq2-pro` | 20-70 pts |
707| | SeeDance 1.5 Pro | `doubao-seedance-1.5-pro` | 47+ pts |
708| | Sora 2 Pro | `sora-2-pro` | 122+ pts |
709| | Kling O1 / 2.6 | `kling-video-o1/v2-6` | 48-120 pts |
710| | Google Veo 3.1 | `veo-3.1-generate-preview` | 70-330 pts |
711| | Pixverse V5.5-V3.5 | `pixverse` | 12-48 pts |
712| **first_last_frame (11)** | Kling O1 🌟 | `kling-video-o1` | 48-120 pts |
713| | Kling 2.6 | `kling-v2-6` | 80+ pts |
714| | Others (9) | Hailuo 2.0, Vidu Q2 Pro, SeeDance 1.5 Pro, Veo 3.1, Pixverse V5.5-V3.5 | — |
715| **reference_image (6)** | Kling O1 🌟 | `kling-video-o1` | 48-120 pts |
716| | Google Veo 3.1 | `veo-3.1-generate-preview` | 70-330 pts |
717| | Others (4) | Vidu Q2, Pixverse V5.5/V5/V4.5 | — |
718
719❌ **Removed video models**: Vidu Q2 Turbo (viduq2-turbo), Wan 2.5/2.2 Plus, Kling 1.6/2.1/2.5, Sora 2 (non-Pro), Veo 3.0/3.1 Fast, SeeDance 1.0, Vidu Q1, Hailuo 2.3 Fast
720| text_to_video | SeeDance 1.5 Pro / 1.0 Pro | `doubao-seedance-1.5-pro` / `doubao-seedance-1.0-pro` | 16 / 15 pts |
721| text_to_video | Sora 2 Pro / Sora 2 | `sora-2-pro` / `sora-2` | 120 / 35 pts |
722| text_to_video | Kling O1 / 2.6 / 2.5 Turbo / 1.6 | `kling-video-o1` / `kling-v2-6` / `kling-v2-5-turbo` / `kling-v1-6` | 48 / 80 / 24 / 32 pts |
723| text_to_video | Google Veo 3.1 Fast / 3.1 / 3.0 | `veo-3.1-fast-generate-preview` / `veo-3.1-generate-preview` / `veo-3.0-generate-preview` | 55 / 140 / 280 pts |
724| text_to_video | Pixverse V3.5–V5.5 | `pixverse` | 12 pts |
725| image_to_video | Wan 2.6 / 2.6 Flash / 2.5 / 2.2 Plus | `wan2.6-i2v` / `wan2.6-i2v-flash` / `wan2.5-i2v-preview` / `wan2.2-i2v-plus` | 25 / 12 / 12 / 10 pts |
726| image_to_video | Kling 2.1 Master | `kling-v2-1-master` | 150 pts |
727| first_last_frame_to_video | Kling O1 | `kling-video-o1` | 70 pts |
728| reference_image_to_video | Kling O1 / Vidu Q2 / Q1 | `kling-video-o1` / `viduq2` / `viduq1` | 48 / 10 / 25 pts |
729
730### Music Generation
731
732| Category | Name | model_id | Cost | Notes |
733|----------|------|----------|------|-------|
734| text_to_music | Suno | `sonic` | 25 pts | sonic-v5; custom_mode, lyrics, vocal_gender |
735| text_to_music | DouBao BGM | `GenBGM` | 30 pts | Background music |
736| text_to_music | DouBao Song | `GenSong` | 30 pts | Song generation |
737
738> Always call `GET /open/v1/product/list?category=<type>` first to get the live `attribute_id` and `form_config` defaults required for task creation.
739
740There are two equivalent route systems serving the same backend logic:
741
742| Route | Auth | Use Case |
743|-------|------|----------|
744| `/open/v1/` | `Authorization: Bearer ima_*` only | Third-party / agent access |
745| `/api/v3/` | Token + API Key (dual auth) | Frontend App |
746
747**This skill documents the `/open/v1/` Open API.** All business logic (credit validation, N-flattening, risk control) runs identically on both paths.
748
749## Environment
750
751Base URL: `https://api.imastudio.com`
752
753Required/recommended headers for all `/open/v1/` endpoints:
754
755| Header | Required | Value | Notes |
756|--------|----------|-------|-------|
757| `Authorization` | ✅ | `Bearer ima_your_api_key_here` | API key authentication |
758| `x-app-source` | ✅ | `ima_skills` | Fixed value — identifies skill-originated requests |
759| `x_app_language` | recommended | `en` / `zh` | Product label language; defaults to `en` if omitted |
760
761```
762Authorization: Bearer ima_your_api_key_here
763x-app-source: ima_skills
764x_app_language: en
765```
766
767---
768
769## 📤 When to Upload Images (Quick Reference)
770
771**The IMA Open API does NOT accept raw bytes or base64 images. All image inputs must be public HTTPS URLs.**
772
773| Task Type | Input Required? | Upload Before Create? | Notes |
774|-----------|----------------|----------------------|-------|
775| **text_to_image** | ❌ No | — | Prompt only |
776| **image_to_image** | ✅ Yes (1 image) | ✅ Upload first | Single input image |
777| **text_to_video** | ❌ No | — | Prompt only |
778| **image_to_video** | ✅ Yes (1 image) | ✅ Upload first | Single input image |
779| **first_last_frame_to_video** | ✅ Yes (2 images) | ✅ Upload first | First + last frame |
780| **reference_image_to_video** | ✅ Yes (1+ images) | ✅ Upload first | Reference image(s) |
781| **text_to_music** | ❌ No | — | Prompt only |
782
783**Upload flow:**
7841. User provides local file path or bytes → call `prepare_image_url()` (see section below)
7852. User provides HTTPS URL → use directly, no upload needed
7863. Use the returned CDN URL (`fdl`) as the value for `input_images` / `src_img_url`
787
788**Example workflow (image_to_image):**
789```python
790# User provides local file
791image_url = prepare_image_url("/path/to/photo.jpg", api_key)
792# → Returns: https://ima-ga.esxscloud.com/webAgent/privite/2026/02/27/..._uuid.jpeg
793
794# Then create task with this URL
795create_task(
796 task_type="image_to_image",
797 input_images=[image_url], # Use uploaded URL
798 prompt="turn into oil painting"
799)
800```
801
802---
803
804## ⚠️ MANDATORY: Always Query Product List First
805
806> **CRITICAL**: You MUST call `/open/v1/product/list` BEFORE creating any task.
807> The `attribute_id` field is REQUIRED in the create request. If it is `0` or missing, you get:
808> `"Invalid product attribute"` → `"Insufficient points"` → task fails completely.
809> **NEVER construct a create request from the model table alone. Always fetch the product first.**
810
811### How to get attribute_id (all task types)
812
813```python
814# Query product list with the correct category
815GET /open/v1/product/list?app=ima&platform=web&category=<task_type>
816# task_type: text_to_image | image_to_image | text_to_video | image_to_video |
817# first_last_frame_to_video | reference_image_to_video | text_to_music
818
819# Walk the V2 tree to find your target model (type=3 leaf nodes only)
820for group in response["data"]:
821 for version in group.get("children", []):
822 if version["type"] == "3" and version["model_id"] == target_model_id:
823 attribute_id = version["credit_rules"][0]["attribute_id"]
824 credit = version["credit_rules"][0]["points"]
825 model_version = version["id"] # = version_id / model_version
826 model_name = version["name"]
827 form_defaults = {f["field"]: f["value"] for f in version["form_config"]}
828 break
829```
830
831### Quick Reference: Known attribute_ids
832
833> Pre-queried values for convenience. **Always call the product list at runtime for accuracy.**
834
835| Model | Task Type | model_id | attribute_id | credit | Notes |
836|-------|-----------|----------|-------------|--------|-------|
837| **text_to_image** |||||| |
838| SeeDream 4.5 | text_to_image | `doubao-seedream-4.5` | **2341** | 5 pts | Default, balanced |
839| Nano Banana Pro (1K) | text_to_image | `gemini-3-pro-image` | **2399** | 10 pts | 1024×1024 |
840| Nano Banana Pro (2K) | text_to_image | `gemini-3-pro-image` | **2400** | 10 pts | 2048×2048 |
841| Nano Banana Pro (4K) | text_to_image | `gemini-3-pro-image` | **2401** | 18 pts | 4096×4096 |
842| **text_to_video** |||||| |
843| Wan 2.6 (720P, 5s) | text_to_video | `wan2.6-t2v` | **2057** | 25 pts | Default, balanced |
844| Wan 2.6 (1080P, 5s) | text_to_video | `wan2.6-t2v` | **2058** | 40 pts | — |
845| Wan 2.6 (720P, 10s) | text_to_video | `wan2.6-t2v` | **2059** | 50 pts | — |
846| Wan 2.6 (1080P, 10s) | text_to_video | `wan2.6-t2v` | **2060** | 80 pts | — |
847| Wan 2.6 (720P, 15s) | text_to_video | `wan2.6-t2v` | **2061** | 75 pts | — |
848| Wan 2.6 (1080P, 15s) | text_to_video | `wan2.6-t2v` | **2062** | 120 pts | — |
849| Kling O1 (5s, std) | text_to_video | `kling-video-o1` | **2313** | 48 pts | Latest Kling |
850| Kling O1 (5s, pro) | text_to_video | `kling-video-o1` | **2314** | 60 pts | — |
851| Kling O1 (10s, std) | text_to_video | `kling-video-o1` | **2315** | 96 pts | — |
852| Kling O1 (10s, pro) | text_to_video | `kling-video-o1` | **2316** | 120 pts | — |
853| **text_to_music** |||||| |
854| Suno (sonic-v4) | text_to_music | `sonic` | **2370** | 25 pts | Default |
855| DouBao BGM | text_to_music | `GenBGM` | **4399** | 30 pts | — |
856| DouBao Song | text_to_music | `GenSong` | **4398** | 30 pts | — |
857| **All others** | any | — | → query `/open/v1/product/list` | — | Always runtime query |
858
859⚠️ **Production warning**: `attribute_id` and `credit` values change frequently in production. Always call `/open/v1/product/list` at runtime; above table is pre-queried reference only (2026-02-27).
860
861### Common Mistakes (and resulting errors)
862
863| Mistake | Error |
864|---------|-------|
865| `attribute_id` is `0` or missing | `"Invalid product attribute"` + `"Insufficient points"` |
866| `attribute_id` outdated (production changed) | Same errors; always query product list first |
867| **`attribute_id` doesn't match parameter combination** | **Error 6010: "Attribute ID does not match the calculated rule"** |
868| `prompt` at outer `parameters[]` level | Prompt ignored; wrong routing |
869| `cast` missing from inner `parameters.parameters` | Billing validation failure |
870| `credit` value wrong or missing | Error 6006 |
871| `model_name` / `model_version` missing | Wrong backend routing |
872| Skipped product list, used table values directly | All of the above |
873
874**⚠️ Critical for Google Veo 3.1 and multi-rule models:**
875
876Models like Google Veo 3.1 have **multiple `credit_rules`**, each with a different `attribute_id` for different parameter combinations:
877- `720p + 4s + optimized` → attribute_id A
878- `720p + 8s + optimized` → attribute_id B
879- `4K + 4s + high` → attribute_id C
880
881The script automatically selects the correct `attribute_id` by matching your parameters (`duration`, `resolution`, `compression_quality`, `generate_audio`) against each rule's `attributes`. If the match fails, you get error 6010.
882
883**Fix**: The bundled script now checks these video-specific parameters for smart credit_rule selection. Always use the script, not manual API construction.
884
885---
886
887## Core Flow
888
889```
8901. GET /open/v1/product/list?app=ima&platform=web&category=<type>
891 → REQUIRED: Get attribute_id, credit, model_version, model_name, form_config defaults
892
893[If input image required]
8942. Upload image → get public HTTPS URL
895 → See "Image Upload" section below
896
8973. POST /open/v1/tasks/create
898 → Must include: attribute_id, model_name, model_version, credit, cast, prompt (nested!)
899
9004. POST /open/v1/tasks/detail {"task_id": "..."}
901 → Poll until medias[].resource_status == 1
902 → Extract url from completed media
903```
904
905---
906
907## Image Upload (Required Before Image Tasks)
908
909**The IMA Open API does NOT accept raw bytes or base64 images. All image inputs must be public HTTPS URLs.**
910
911When a user provides an image (local file, bytes, base64), you must upload it first and get a URL. This is exactly what the IMA frontend does before every image task.
912
913### Real Upload Flow (from IMA Frontend Source)
914
915The frontend uses a **two-step presigned URL flow** via the IM platform:
916
917```
918Step 1: GET /api/rest/oss/getuploadtoken → returns { ful, fdl }
919 ful = presigned PUT URL (upload destination, expires ~7 days)
920 fdl = final CDN download URL (use this as input_images value)
921
922Step 2: PUT {ful} with raw image bytes + Content-Type header
923 → image is stored in Aliyun OSS: zhubite-imagent-bot.oss-us-east-1.aliyuncs.com
924 → accessible via CDN: https://ima-ga.esxscloud.com/...
925```
926
927### Step 1: Get Upload Token
928
929```
930GET https://imapi-qa.liveme.com/api/rest/oss/getuploadtoken
931```
932
933Required query parameters (11 total — sourced directly from frontend `generateUploadInfo`):
934
935| Parameter | Example | Description |
936|-----------|---------|-------------|
937| `appUid` | `ima_xxx...` | **Use IMA API key directly** — no separate login needed |
938| `appId` | `webAgent` | App identifier (fixed) |
939| `appKey` | `32jdskjdk320eew` | App secret (fixed, used for `sign` generation) |
940| `cmimToken` | `ima_xxx...` | **Use IMA API key directly** — same as appUid |
941| `sign` | `117CF6CF...` | IM auth HMAC: `SHA1("webAgent\|32jdskjdk320eew\|{timestamp}\|{nonce}").upper()` |
942| `timestamp` | `1772042430` | Unix timestamp (seconds), generated per request |
943| `nonce` | `CxI1FLI5ajLJZ1jlxZmeg` | Random nonce string, generated per request |
944| `fService` | `privite` | Fixed: storage service type |
945| `fType` | `picture` | `picture` for images, `video`, `audio` |
946| `fSuffix` | `jpeg` | File extension: `jpeg`, `png`, `mp4`, `mp3` |
947| `fContentType` | `image/jpeg` | MIME type of the file |
948
949> **简化认证**:直接使用 IMA API key 填充 `appUid` 和 `cmimToken` 参数,无需单独获取凭证。
950
951Response:
952```json
953{
954 "ful": "https://zhubite-imagent-bot.oss-us-east-1.aliyuncs.com/webAgent/privite/2026/02/26/..._uuid.jpeg?Expires=...&OSSAccessKeyId=...&Signature=...",
955 "fdl": "https://ima-ga.esxscloud.com/webAgent/privite/2026/02/26/..._uuid.jpeg",
956 "ful_expire": "...",
957 "fdl_expire": "...",
958 "fdl_key": "..."
959}
960```
961
962### Step 2: Upload Image via Presigned URL
963
964```
965PUT {ful}
966Content-Type: image/jpeg
967Body: [raw image bytes]
968```
969
970No auth headers needed — the presigned URL already encodes the credentials.
971
972### Step 3: Use `fdl` as the Image URL
973
974After the PUT succeeds, use `fdl` (the CDN URL) as the value for `input_images` / `src_img_url`.
975
976### Python Implementation
977
978```python
979import hashlib, time, uuid, requests, mimetypes
980
981# ── 🌐 IMA Upload Service Endpoint (IMA-owned, for image/video uploads) ──────
982IMA_IM_BASE = "https://imapi-qa.liveme.com" # prod: https://imapi.liveme.com
983
984# ── 🔑 Hardcoded APP_KEY (Public, Shared Across All Users) ──────────────────
985# This APP_KEY is a PUBLIC identifier used by IMA Studio's image/video upload
986# service. It is NOT a secret—it's intentionally shared across all users and
987# embedded in the IMA web frontend. This key is used to generate HMAC signatures
988# for upload token requests, but your IMA API key (ima_xxx...) is the ACTUAL
989# authentication credential. Think of APP_KEY as a "client ID" rather than a
990# "client secret."
991#
992# ⚠️ Security Note: Your ima_xxx... API key is the sensitive credential. It is
993# sent to imapi.liveme.com as query parameters (appUid, cmimToken). Always use
994# test keys for experiments and rotate your API key regularly.
995#
996# 📖 See SECURITY.md for complete disclosure and network verification guide.
997APP_ID = "webAgent"
998APP_KEY = "32jdskjdk320eew" # Public shared key (used for HMAC sign generation)
999APP_UID = "<your_app_uid>" # POST /api/v3/login/app → data.user_id
1000APP_TOKEN = "<your_app_token>" # POST /api/v3/login/app → data.token
1001
1002
1003def _gen_sign() -> tuple[str, str, str]:
1004 """Generate per-request (sign, timestamp, nonce)."""
1005 nonce = uuid.uuid4().hex[:21]
1006 ts = str(int(time.time()))
1007 raw = f"{APP_ID}|{APP_KEY}|{ts}|{nonce}"
1008 sign = hashlib.sha1(raw.encode()).hexdigest().upper()
1009 return sign, ts, nonce
1010
1011
1012def get_upload_token(app_uid: str, app_token: str,
1013 suffix: str, content_type: str) -> dict:
1014 """Step 1: Get presigned upload URL from IMA's upload service.
1015
1016 Calls GET imapi.liveme.com/api/rest/oss/getuploadtoken with exactly 11 params.
1017 Returns: { "ful": "<presigned PUT URL>", "fdl": "<CDN download URL>" }
1018
1019 Args:
1020 app_uid: Your IMA API key (ima_xxx...), used as appUid parameter
1021 app_token: Your IMA API key (ima_xxx...), used as cmimToken parameter
1022 suffix: File extension (jpeg, png, mp4, mp3)
1023 content_type: MIME type (image/jpeg, video/mp4, etc.)
1024
1025 Security Note:
1026 Your IMA API key (ima_xxx...) is sent to imapi.liveme.com as query
1027 parameters (appUid, cmimToken). This is IMA Studio's image/video upload
1028 service, separate from the main api.imastudio.com API. Both domains are
1029 owned by IMA Studio—this is part of IMA's microservices architecture.
1030
1031 Why two domains?
1032 - api.imastudio.com: Core AI generation API (product list, task creation)
1033 - imapi.liveme.com: Specialized upload service (presigned URL generation)
1034
1035 Your API key grants access to both services. For security verification,
1036 see SECURITY.md section "Network Traffic Verification."
1037 """
1038 sign, ts, nonce = _gen_sign()
1039 r = requests.get(
1040 f"{IMA_IM_BASE}/api/rest/oss/getuploadtoken",
1041 params={
1042 # App Key params
1043 "appUid": app_uid, # APP_UID
1044 "appId": APP_ID,
1045 "appKey": APP_KEY,
1046 "cmimToken": app_token, # APP_TOKEN
1047 "sign": sign,
1048 "timestamp": ts,
1049 "nonce": nonce,
1050 # File params
1051 "fService": "privite", # fixed
1052 "fType": "picture", # picture / video / audio
1053 "fSuffix": suffix, # jpeg / png / mp4 / mp3
1054 "fContentType": content_type,
1055 },
1056 )
1057 r.raise_for_status()
1058 return r.json()["data"]
1059
1060
1061def upload_image_to_oss(image_bytes: bytes, content_type: str, ful: str) -> None:
1062 """Step 2: PUT image bytes to the presigned OSS URL. No auth needed."""
1063 resp = requests.put(ful, data=image_bytes, headers={"Content-Type": content_type})
1064 resp.raise_for_status()
1065
1066
1067def prepare_image_url(source, api_key: str) -> str:
1068 """
1069 Full workflow: upload any image and return the CDN URL (fdl).
1070
1071 Args:
1072 source: file path (str), raw bytes, or already-public HTTPS URL
1073 api_key: IMA API key for upload authentication
1074
1075 Returns: public HTTPS CDN URL ready to use as input_images value
1076 """
1077 # Already a public URL → use directly, no upload needed
1078 if isinstance(source, str) and source.startswith("https://"):
1079 return source
1080
1081 # Read file bytes
1082 if isinstance(source, str):
1083 ext = source.rsplit(".", 1)[-1].lower() if "." in source else "jpeg"
1084 with open(source, "rb") as f:
1085 image_bytes = f.read()
1086 content_type = mimetypes.guess_type(source)[0] or "image/jpeg"
1087 else:
1088 image_bytes = source
1089 ext = "jpeg"
1090 content_type = "image/jpeg"
1091
1092 # Step 1: Get presigned URL using API key directly
1093 token_data = get_upload_token(api_key, ext, content_type)
1094 ful = token_data["ful"]
1095 fdl = token_data["fdl"]
1096
1097 # Step 2: Upload to OSS
1098 upload_image_to_oss(image_bytes, content_type, ful)
1099
1100 # Step 3: Return CDN URL
1101 return fdl # use this as input_images / src_img_url value
1102```
1103
1104> **OSS path format**: `webAgent/privite/{YYYY}/{MM}/{DD}/{timestamp}_{uid}_{uuid}.{ext}`
1105> **CDN base**: `https://ima-ga.esxscloud.com/`
1106> **OSS bucket**: `zhubite-imagent-bot.oss-us-east-1.aliyuncs.com`
1107
1108---
1109
1110## Quick Reference
1111
1112### Task Types (category values)
1113
1114| category | Capability | Input |
1115|----------|------------|-------|
1116| `text_to_image` | Text → Image | prompt |
1117| `image_to_image` | Image → Image | prompt + input_images |
1118| `text_to_video` | Text → Video | prompt |
1119| `image_to_video` | Image → Video | prompt + input_images |
1120| `first_last_frame_to_video` | First+Last Frame → Video | prompt + src_img_url[2] |
1121| `reference_image_to_video` | Reference Image → Video | prompt + src_img_url[1+] |
1122| `text_to_music` | Text → Music | prompt |
1123
1124### Detail API status values
1125
1126Each media in `medias[]` has two fields:
1127
1128| Field | Type | Values | Description |
1129|-------|------|--------|-------------|
1130| **`resource_status`** | int (or `null`) | `0`, `1`, `2`, `3` | 0=处理中, 1=可用, 2=失败, 3=已删除。API 可能返回 `null`,需当作 0。 |
1131| **`status`** | string | `"pending"`, `"processing"`, `"success"`, `"failed"` | 任务状态文案。轮询时以 `resource_status` 为准;`status == "failed"` 表示失败。 |
1132
1133Poll on `resource_status` first, then ensure `status` is not `"failed"`:
1134
1135| `resource_status` | `status` | Meaning | Action |
1136|-------------------|----------|---------|--------|
1137| `0` or **`null`** | `pending` / `processing` | 处理中 | Keep polling; do not stop (null = 0) |
1138| `1` | `success` (or `completed`) | **完成** | Read `url`; stop only when **all** medias are 1 |
1139| `1` | `failed` | 失败 (status 优先) | Stop, handle error |
1140| `2` | any | 失败 | Stop, handle error |
1141| `3` | any | 已删除 | Stop |
1142
1143> **Important**: (1) Treat `resource_status: null` as 0. (2) Stop only when **all** medias have `resource_status == 1`. (3) When `resource_status=1`, still check `status != "failed"`.
1144
1145---
1146
1147## API 1: Product List
1148
1149```
1150GET /open/v1/product/list?app=ima&platform=web&category=text_to_image
1151```
1152
1153Internally calls downstream `/v1/products/listv2`. Returns a **V2 tree structure**: `type=2` nodes are model groups, `type=3` nodes are versions (leaves). Only `type=3` nodes contain `credit_rules` and `form_config`.
1154
1155> `webAgent` is auto-converted to `ima` by the gateway — you can use either value for `app`.
1156
1157```json
1158[
1159 {
1160 "id": "SeeDream",
1161 "type": "2",
1162 "name": "SeeDream",
1163 "model_id": "",
1164 "children": [
1165 {
1166 "id": "doubao-seedream-4-0-250828",
1167 "type": "3",
1168 "name": "SeeDream 4.0",
1169 "model_id": "doubao-seedream-4.0",
1170 "credit_rules": [
1171 { "attribute_id": 332, "points": 5, "attributes": { "default": "enabled" } }
1172 ],
1173 "form_config": [
1174 { "field": "size", "type": "tags", "value": "1K",
1175 "options": [{"label":"1K","value":"1K"}, {"label":"2K","value":"2K"}] }
1176 ]
1177 }
1178 ]
1179 }
1180]
1181```
1182
1183**How to pick a version for task creation:**
11841. Traverse nodes to find `type=3` leaves (versions)
11852. Use `model_id` and `id` (= `model_version`) from the leaf
11863. Pick `credit_rules[].attribute_id` matching your desired quality/size (`attributes` field shows the config)
11874. Use `form_config[].value` as default `parameters` values
1188
1189> `credit_rules[].attribute_id` → required for task creation as `attribute_id`.
1190> `credit_rules[].points` → required for task creation as `credit` and `cast.points`.
1191
1192---
1193
1194## API 2: Create Task
1195
1196```
1197POST /open/v1/tasks/create
1198```
1199
1200### Request Structure
1201
1202```json
1203{
1204 "task_type": "text_to_image",
1205 "enable_multi_model": false,
1206 "src_img_url": [],
1207 "upload_img_src": "",
1208 "parameters": [
1209 {
1210 "attribute_id": 8538,
1211 "model_id": "doubao-seedream-4.5",
1212 "model_name": "SeeDream 4.5",
1213 "model_version": "doubao-seedream-4-5-251128",
1214 "app": "ima",
1215 "platform": "web",
1216 "category": "text_to_image",
1217 "credit": 5,
1218 "parameters": {
1219 "prompt": "a beautiful mountain sunset, photorealistic",
1220 "size": "4k",
1221 "n": 1,
1222 "input_images": [],
1223 "cast": {"points": 5, "attribute_id": 8538}
1224 }
1225 }
1226 ]
1227}
1228```
1229
1230### Field Reference
1231
1232| Field | Required | Description |
1233|-------|----------|-------------|
1234| `task_type` | ✅ | Must match `parameters[].category` |
1235| `parameters[].attribute_id` | ✅ | From `credit_rules[].attribute_id` in product list |
1236| `parameters[].model_id` | ✅ | From `type=3` leaf node `model_id` |
1237| `parameters[].model_version` | ✅ | From `type=3` leaf node `id` |
1238| `parameters[].app` | ✅ | Use `ima` (or `webAgent`, auto-converted) |
1239| `parameters[].platform` | ✅ | Use `web` |
1240| `parameters[].category` | ✅ | Must match top-level `task_type` |
1241| `parameters[].credit` | ✅ | Must equal `credit_rules[].points`. Error 6006 if wrong. |
1242| `parameters[].parameters.prompt` | ✅ | The actual prompt text used by downstream service |
1243| `parameters[].parameters.cast` | ✅ | `{"points": N, "attribute_id": N}` — mirrors credit |
1244| `parameters[].parameters.n` | ✅ | Number of outputs (usually `1`). Gateway flattens N>1 into separate resources. |
1245| `parameters[].parameters.input_images` | image tasks | Array of input image URLs |
1246| top-level `src_img_url` | multi-image | Array for first_last_frame / reference tasks |
1247
1248### N-Field Flattening (Gateway Internal Logic)
1249
1250When `n > 1`, the gateway automatically:
12511. Generates `n` independent `resourceBizId` values
12522. Deducts credits `n` times (one per resource)
12533. Creates `n` separate tasks in the downstream service
1254
1255Response `medias[]` will contain `n` items. Poll until **all** have `resource_status == 1`.
1256
1257### Response
1258
1259```json
1260{
1261 "code": 0,
1262 "data": {
1263 "id": "task_abc123",
1264 "biz_id": "biz_xxx",
1265 "task_type": "text_to_image",
1266 "medias": [],
1267 "generate_count": 1,
1268 "created_at": 1700000000000,
1269 "timeout_at": 1700000300000
1270 }
1271}
1272```
1273
1274`data.id` = task ID for polling. `timeout_at` = Unix ms deadline.
1275
1276---
1277
1278## API 3: Task Detail (Poll)
1279
1280```
1281POST /open/v1/tasks/detail
1282{"task_id": "<id from create response>"}
1283```
1284
1285Poll every 2–5s (8s+ for video). Completed response:
1286
1287```json
1288{
1289 "id": "task_abc",
1290 "medias": [{
1291 "resource_status": 1,
1292 "status": "success",
1293 "url": "https://cdn.../output.jpg",
1294 "cover": "https://cdn.../cover.jpg",
1295 "format": "jpg",
1296 "width": 1024,
1297 "height": 1024
1298 }]
1299}
1300```
1301
1302**Polling stop condition (must implement exactly):**
1303- Treat `resource_status: null` (or missing) as **0** (processing). Do **not** stop when you see null; backend may serialize Go `*int` as null.
1304- Stop **only when ALL** `medias[].resource_status == 1` and no `status == "failed"`. If you return on the first media with `resource_status == 1` while others are still 0, the task is not fully done and you will keep polling or get inconsistent state.
1305- Stop immediately if any `status == "failed"` or `resource_status == 2` or `resource_status == 3`.
1306
1307---
1308
1309## Task Type Examples
1310
1311### text_to_image ✅ Verified
1312No image input. `src_img_url: []`, `input_images: []`. See API 2 for full example.
1313
1314### text_to_video ✅ Verified
1315Extra fields vs text_to_image — all from `form_config` defaults:
1316
1317```json
1318{
1319 "task_type": "text_to_video",
1320 "src_img_url": [],
1321 "parameters": [{
1322 "attribute_id": 4838,
1323 "model_id": "wan2.6-t2v",
1324 "model_name": "Wan 2.6",
1325 "model_version": "wan2.6-t2v",
1326 "category": "text_to_video",
1327 "credit": 3,
1328 "app": "ima", "platform": "web",
1329 "parameters": {
1330 "prompt": "a puppy dancing happily, sunny meadow",
1331 "negative_prompt": "",
1332 "prompt_extend": false,
1333 "duration": 5,
1334 "resolution": "1080P",
1335 "aspect_ratio": "16:9",
1336 "shot_type": "single",
1337 "seed": -1,
1338 "n": 1,
1339 "input_images": [],
1340 "cast": {"points": 3, "attribute_id": 4838}
1341 }
1342 }]
1343}
1344```
1345> Video-specific fields from `form_config`: `duration` (seconds), `resolution`, `aspect_ratio`, `shot_type`, `negative_prompt`, `prompt_extend`.
1346> Poll every 8s (video generation is slower). Response `medias[].cover` = first-frame thumbnail.
1347
1348### text_to_music
1349No image input. `src_img_url: []`, `input_images: []`.
1350
1351### image_to_image ✅ Verified
1352```json
1353{
1354 "task_type": "image_to_image",
1355 "src_img_url": ["https://...input.jpg"],
1356 "parameters": [{
1357 "attribute_id": 8560,
1358 "model_id": "doubao-seedream-4.5",
1359 "model_version": "doubao-seedream-4-5-251128",
1360 "category": "image_to_image",
1361 "credit": 5,
1362 "app": "ima", "platform": "web",
1363 "parameters": {
1364 "prompt": "turn into oil painting style",
1365 "size": "4k",
1366 "n": 1,
1367 "input_images": ["https://...input.jpg"],
1368 "cast": {"points": 5, "attribute_id": 8560}
1369 }
1370 }]
1371}
1372```
1373> ⚠️ `size` must be from `form_config` options (e.g. `"2k"`, `"4k"`, `"2048x2048"`). `"adaptive"` is NOT valid for SeeDream 4.5 i2i — causes error 400.
1374> Top-level `src_img_url` **and** `parameters.input_images` must both contain the input image URL.
1375> Some i2i models (e.g. `doubao-seededit-3.0-i2i`) may not be available in test environments — fall back to SeeDream 4.5.
1376
1377### image_to_video / first_last_frame_to_video / reference_image_to_video
1378```json
1379"src_img_url": ["https://first-frame.jpg", "https://last-frame.jpg"]
1380```
1381Index 0 = first frame (or reference), index 1 = last frame (first_last_frame only).
1382
1383---
1384
1385## Common Mistakes
1386
1387| Mistake | Fix |
1388|---------|-----|
1389| `attribute_id` not from `credit_rules` | Always fetch product list first |
1390| `credit` value wrong | Must exactly match `credit_rules[].points` — error 6006 |
1391| `prompt` at wrong location | Put prompt in `parameters[].parameters.prompt` (nested), not only at top level |
1392| Polling `biz_id` instead of `id` | Use `id` (task ID) for `/tasks/detail` |
1393| Single-poll instead of loop | Poll until `resource_status == 1` for ALL medias |
1394| Missing `app` / `platform` in parameters | Required fields — use `ima` / `web` |
1395| `category` mismatch | `parameters[].category` must match top-level `task_type` |
1396| `resource_status == 2` not handled | Check for failure, don't loop forever |
1397| `status == "failed"` ignored | `resource_status=1` + `status="failed"` means actual failure |
1398| `n > 1` and only checking first media | All `n` media items must reach `resource_status == 1` |
1399
1400---
1401
1402## Complete Python Example
1403
1404See [examples.md](examples.md) for a full Python implementation covering all 7 task types.