Skip to main content

Integrate an image generation model

Call Token Plan image generation models in Agent tools to generate images from text descriptions and download them locally.

Supported models

ModelDescription
qwen-image-3.0-proQwen Image Generation and Editing 3.0 Pro, supports text-to-image and image-to-image
qwen-image-2.0-proQwen Image Generation 2.0 Pro (Team Edition only)
qwen-image-2.0Qwen Image Generation 2.0 (Team Edition only)
wan2.7-imageWan image generation
wan2.7-image-proWan image generation Pro
For more models, see models supported by Token Plan Personal Edition and Team Edition.

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.

Endpoint

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-3.0-pro), 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 to generate the image:

```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 generated image file path.

Step 2: Generate an image

In Claude Code, enter /text-to-image Draw a cat. To use another model, specify the model name in the instruction, for example /text-to-image Draw a cat with wan2.7-image.

Request parameters

ParameterRequiredDescription
modelYesImage generation model ID.
input.messages[0].content[0].textYesImage description.
parameters.sizeNoImage size, for example 1024*1024. If omitted, the model selects the size.
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 them promptly.

Limits

  • Supported image sizes and models depend on each model's documentation.
  • Billing is based on the number of output images. Actual consumption is shown in the console usage statistics.

Other tools

For extension mechanisms and configuration paths of other tools, see Integration overview. Save the Slash Command content above to the corresponding path.