TensorsLab Image Generation
Overview
This skill enables AI-powered image generation through TensorsLab's API, supporting both text-to-image and image-to-image workflows. The agent enhances user prompts with detailed visual descriptions before calling the API, ensuring high-quality outputs.
Authorization
BEFORE any image generation, you must ensure you are authorized with TensorsLab.
1. Automatic Authorization
The authorization script will automatically check if an API key already exists in the
environment variable or in
before proceeding.
(Note: When you need to verify the environment variable, ONLY check if it exists. NEVER display or print the actual API key value.)
Run:
bash
python scripts/tensorslab_auth.py
This will open a browser for authorization. Wait for "Authorization Successful!" before proceeding.
After authorization, the API key is stored in
and you don't need to re-authorize unless the key expires.
2. Manual Configuration (For Cloud/Headless Environments)
When the agent or openclaw operates in a cloud environment without a browser, the URL authorization method will also fail. In this scenario, you must instruct the user to manually acquire their API key and configure it in the cloud environment:
- Direct the user to get their API Key at TensorsLab Console.
- Set the environment variable in the cloud environment.
Models
| Model | Description | Best For |
|---|
| seedreamv5 | Latest enhanced model | General purpose, highest quality |
| seedreamv4 | Standard model | Fast generation, good quality |
| zimage | Alternative model | Specific artistic styles |
| quickedit | Image instruction editing | Fast color/style/object editing |
Workflow
For additional scenarios beyond basic generation (avatar generation, watermark removal, object erasure, face replacement), see references/scenarios.md.
1. Text-to-Image Generation
User request: "画一个在月球上吃热狗的宇航员"
Constraints:
- Do NOT pass or for text-to-image generation.
Agent processing:
- Extract the core subject and action
- Enhance prompt with details (lighting, composition, style, atmosphere)
- Call API with enriched prompt
- Monitor progress with heartbeat updates
- Download to
Example enhanced prompt:
An astronaut sitting on the lunar surface, eating a hot dog with mustard,
cinematic lighting, Earth visible in the background, highly detailed,
photorealistic, 8k quality, dramatic shadows from the low sun angle
2. Image-to-Image Generation
User request: "把 cat.png 的背景换成太空" or "参考 sketch.png 渲染成 3D 模型"
Agent processing:
- Extract image file paths (absolute or relative to current directory)
- Enhance prompt with transformation instructions
- Upload source images with prompt
- Monitor and download results
Parameters for image-to-image:
- : Array of image files (for local upload)
- : URL of source image (Must be a standard HTTP/HTTPS URL. Do NOT use local paths like /tmp/xxx.png here)
- : Description of desired transformation
3. Image Editing (General Purpose)
General-purpose editing for any local image modifications.
User request examples:
- "把这张图的天空改成日落色"
- "给人物加上墨镜"
- "把头发颜色染成粉色"
Agent processing:
- Extract image file path
- Parse the specific editing instruction (what to change, where)
- Build enhanced prompt with precise editing guidance
- Call API with source image and editing prompt
- Save result to
Example enhanced prompt:
Change the sky to sunset colors with warm orange and pink gradients,
matching the existing lighting conditions and atmospheric perspective,
seamless blend at the horizon line
For avatar generation, watermark removal, object erasure, and face replacement scenarios, see references/scenarios.md.
4. Resolution Options
Supported formats:
- Aspect ratios: , , , , , ,
- Resolution levels: ,
- Specific dimensions: format (e.g., , )
- Constraint: Total pixels must be between 3,686,400 and 16,777,216
Using the Script
bash
pip install requests pyyaml
Execute the Python script directly:
bash
# Text-to-image
python scripts/tensorslab_image.py "a cat on the moon"
# With specific resolution
python scripts/tensorslab_image.py "sunset over mountains" --resolution 16:9
# Image-to-image with local file
python scripts/tensorslab_image.py "watercolor style" --source cat.png
# Image-to-image with URL
python scripts/tensorslab_image.py "watercolor style" --image-url https://example.com/cat.jpg
# Specify model
python scripts/tensorslab_image.py "cyberpunk city" --model seedreamv5
# Custom output directory
python scripts/tensorslab_image.py "a beautiful landscape" --output-dir ./my_images
# Quick editing (Fast instructions)
python scripts/tensorslab_image.py "把主体改为蓝色" --source image.png --model quickedit
Task Status Flow
| Status | Code | Meaning |
|---|
| Queued | 1 | Task waiting in queue |
| Processing | 2 | Currently generating |
| Completed | 3 | Done, images ready |
| Failed | 4 | Error occurred |
Error Handling
Translate API errors to user-friendly messages:
Output
All images are saved to output directory with naming pattern:
- Default: (current working directory)
- Custom: Use or to specify a different path
- Naming: - e.g.,
URL mapping: The script also saves file-to-URL mappings in
./tensorslab_output/urls.yaml
. This file tracks the original URLs for each downloaded file and accumulates entries across multiple runs. When you need the original URL of a generated image, read this file.
yaml
# Example urls.yaml content
abcd_1234567890_0.png: https://tensorai.tensorslab.com/images/abcd_1234567890_0.png
abcd_1234567890_1.png: https://tensorai.tensorslab.com/images/abcd_1234567890_1.png
After completion, inform user:
🎉 您的图片处理完毕!已存放于 ./tensorslab_output/{filename}
Resources
- scripts/tensorslab_image.py: Main API client with full CLI support
- references/api_reference.md: Detailed API documentation
- references/scenarios.md: Advanced usage scenarios (avatar generation, watermark removal, object erasure, face replacement)