Integrate the image generation model
Call a Token Plan image generation model from an Agent tool, generate an image from a text description, and download it locally.
Supported models
| Model | Description |
|---|---|
qwen-image-3.0-pro | Qwen Image Generation and Editing 3.0 Pro, supports text-to-image and image-to-image |
qwen-image-2.0-pro | Qwen Image Generation 2.0 Pro |
qwen-image-2.0 | Qwen Image Generation 2.0 |
wan2.7-image | Wan image generation |
wan2.7-image-pro | Wan image generation Pro |
For more models, see models supported by Token Plan.
Prerequisites
- A Token Plan subscription and an API key that starts with
sk-sp-. For details, see Integration overview. - Your AI coding tool supports Slash Commands. For configuration paths of other tools, see Other tools.
Interface
POST https://token-plan.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
Use Authorization: Bearer $ANTHROPIC_AUTH_TOKEN in the request header. For the request body and response fields, see the sections below.
Step 1: Create a Slash Command
Configure the Token Plan API key as the environment variable $ANTHROPIC_AUTH_TOKEN.
Create .claude/commands/text-to-image.md in the project root and add the following content:
Call the Token Plan image generation API to generate an image from a description and download it locally.
Image description: $ARGUMENTS
## Steps
1. Extract the prompt (image description), model (default: qwen-image-2.0), and size (default: 1024*1024) from the description. If the description specifies a model, use that model.
2. Use the Bash tool to run the following command:
```bash
curl -s -X POST "https://token-plan.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation" \
-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "<model>",
"input": {"messages": [{"role": "user", "content": [{"text": "<prompt>"}]}]},
"parameters": {"size": "<size>"}
}'
```
3. Extract the image URL from `output.choices[0].message.content[0].image` in the response JSON.
4. Download the image with `curl -s -o "generated_$(date +%Y%m%d_%H%M%S).png" "<URL>"`.
5. Output the path of the generated image file.
Step 2: Generate an image
In Claude Code, enter /text-to-image draw a cat. To use another model, specify the model in the command, for example /text-to-image use wan2.7-image to draw a cat.
Request parameters
| Parameter | Required | Description |
|---|---|---|
model | Yes | Image generation model ID. |
input.messages[0].content[0].text | Yes | Image description. |
parameters.size | No | Image size, for example 1024*1024. If omitted, the model selects a size automatically. |
For more parameters, see Qwen Image Generation and Editing API.
Response
- Image URL:
output.choices[0].message.content[0].image. - Usage:
usage.image_count,usage.width,usage.height. - Image URLs expire. Download the image promptly.
Limits
- Image sizes and supported models depend on each model's documentation.
- Billing is based on the number of output images. Actual Credits consumption is shown in Usage in the console.
Other tools
For extension mechanisms and configuration paths of other tools, see Integration overview. Save the Slash Command above to the corresponding path.