hansonyyds/modelscope-image-gen/modelscope-api

Claude Code and agent skill by hansonyyds/modelscope-image-gen

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

This skill should be used when the user asks to "call ModelScope API", "generate images with ModelScope", "configure ModelScope", or mentions ModelScope API endpoints, authentication, async task polling, or image generation workflows. Provides comprehensive guidance for ModelScope image generation API integration.

Install

npx vskill@latest install hansonyyds/modelscope-image-gen/modelscope-api

Semi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard

SKILL.md

ModelScope API Integration

This skill provides comprehensive knowledge for integrating with ModelScope's image generation API, including authentication, async task handling, and error management.

Core Concepts

ModelScope provides an async image generation API that requires:

  1. API authentication via Bearer token
  2. Async task submission and polling
  3. Image retrieval and local storage

API Endpoints

Base URL
https://api-inference.modelscope.cn/
Key Endpoints
EndpointMethodPurpose
/v1/images/generationsPOSTSubmit image generation task
/v1/tasks/{task_id}GETPoll task status
/v1/tasks/{task_id}/resultGETRetrieve completed image

Authentication

All requests require the Authorization header:

python
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}

The API key is stored in ~/.modelscope-image-gen/modelscope-image-gen.local.md configuration file.

Image Generation Workflow

Step 1: Submit Generation Request

Submit an async image generation request:

python
response = requests.post(
f"{base_url}v1/images/generations",
headers={**common_headers, "X-ModelScope-Async-Mode": "true"},
data=json.dumps({
"model": "Tongyi-MAI/Z-Image-Turbo",
"prompt": "A golden cat"
}, ensure_ascii=False).encode('utf-8')
)
task_id = response.json()["task_id"]
Step 2: Poll Task Status

Continuously poll until completion:

python
while True:
result = requests.get(
f"{base_url}v1/tasks/{task_id}",
headers={**common_headers, "X-ModelScope-Task-Type": "image_generation"},
)
data = result.json()
if data.get("status") == "succeeded":
break
elif data.get("status") == "failed":
raise Exception(data.get("error", "Generation failed"))
time.sleep(2)
Step 3: Retrieve Image

Extract and save the generated image:

python
image_url = data["result"]["url"]
image_response = requests.get(image_url)
img = Image.open(BytesIO(image_response.content))
img.save(f"{output_dir}/{filename}.png")

Request Parameters

Required Parameters
ParameterTypeDescription
modelstringModelScope model ID (e.g., "Tongyi-MAI/Z-Image-Turbo")
promptstringImage generation prompt
Optional Parameters
ParameterTypeDescription
widthintImage width (default: 1024)
heightintImage height (default: 1024)
num_inference_stepsintNumber of inference steps

Error Handling

Common Errors
ErrorCauseSolution
401 UnauthorizedInvalid API tokenCheck token in configuration
429 Rate LimitToo many requestsWait and retry
500 Internal ErrorServer errorRetry with exponential backoff
TimeoutTask taking too longIncrease timeout setting
Retry Strategy

Implement exponential backoff for retries:

python
max_retries = 3
for attempt in range(max_retries):
try:
response = requests.post(...)
break
except requests.exceptions.RequestException as e:
if attempt == max_retries - 1:
raise
wait_time = 2 ** attempt
time.sleep(wait_time)

Additional Resources

Utility Scripts

The following scripts are available in this skill:

  • `scripts/image-gen.py` - Complete image generation implementation with async polling and error handling
Example Files

Working examples in examples/:

  • `batch-prompts.txt` - Example batch generation prompts

Configuration Management

Read configuration from ~/.modelscope-image-gen/modelscope-image-gen.local.md:

python
import yaml
import re
from pathlib import Path
def read_config():
config_dir = Path.home() / ".modelscope-image-gen"
config_path = config_dir / "modelscope-image-gen.local.md"
with open(config_path, 'r') as f:
content = f.read()
# Extract YAML frontmatter
match = re.match(r'^---\n(.*?)\n---', content, re.DOTALL)
if match:
config = yaml.safe_load(match.group(1))
return config.get('api_key'), config.get('default_model', 'Tongyi-MAI/Z-Image-Turbo')
raise Exception("Invalid configuration file")

Best Practices

  1. Always use async mode for image generation to handle long-running tasks
  2. Implement timeout handling to prevent indefinite polling
  3. Save images immediately after successful retrieval
  4. Handle rate limiting with proper backoff strategies
  5. Validate prompts before submission to avoid wasted API calls
  6. Log all API interactions for debugging and monitoring

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Refreshed 7 Apr 2026, 7 months ago.

Extension points

  • configConfiguration overrides

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/hansonyyds/modelscope-image-gen/modelscope-api/badge)](https://verified-skill.com/skills/hansonyyds/modelscope-image-gen/modelscope-api)

Something wrong with this skill or its page? Tell us.