Image generation, video generation, and speech synthesis models in Token Plan must be integrated through each tool's extension mechanism (Skill, Slash Command, or Agent).
Overview
AI coding tools cannot call image, video, or speech synthesis models directly through model configuration. Integrate them through each tool's extension mechanism instead.
Set your plan-specific API Key (prefixed with sk-sp-) as the $ANTHROPIC_AUTH_TOKEN environment variable. The examples below use this variable for authentication.
Example: Claude Code
This example shows how to integrate an image generation model in Claude Code using a Slash Command. The process is similar for other tools, with differences in extension mechanism and configuration file path.
Step 1: Create a Slash Command
Create the file .claude/commands/text-to-image.md in your project root directory with the following content:
Call the Token Plan text-to-image API to generate an image based on a description.
User request: $ARGUMENTS
## Steps
1. Extract prompt (image description), model, and size (default: `1024*1024`) from the user request. If the user explicitly specifies a model (for example, `model=wan2.7-image` or `use wan2.7-image to draw`), use that model name exactly and do not fall back to the default; use `qwen-image-2.0` only when no model is specified. Common image generation models include `qwen-image-2.0`, `qwen-image-2.0-pro`, `wan2.7-image`, and `wan2.7-image-pro`; see the QwenCloud model list for the full set.
2. Call the API to generate an image (use the Bash tool to run curl):
```
curl -s -X POST "https://token-plan.ap-southeast-1.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[*].message.content[*].image in the response JSON.
4. Download the image to the current directory with curl -s -o "generated_$(date +%Y%m%d_%H%M%S).png" "<URL>".
5. Display the generated image file path to the user.
Step 2: Generate an image
In Claude Code, type /text-to-image draw a cat. To use an image generation model other than the default, include the model name in the command, for example /text-to-image draw a cat using wan2.7-image.
Integrate video generation models
Video generation models also use tool extension mechanisms. The key difference from image generation is that video generation uses an asynchronous task pattern: submit a task, poll for the result, then download the video file.
Supported video generation models
| Model | Function | Description |
|---|
| happyhorse-1.1-t2v | Text-to-video | Generate a video from a text description |
| happyhorse-1.1-i2v | Image-to-video | Generate a video from a first-frame image with a text description |
| happyhorse-1.1-r2v | Reference-to-video | Generate a video from reference images with a text description |
Example: Claude Code
Create the file .claude/commands/text-to-video.md in your project root directory with the following content:
Call the Token Plan text-to-video API to generate a video based on a description and automatically download it locally.
User request: $ARGUMENTS
## Steps
1. Extract prompt (video description), model (default happyhorse-1.1-t2v), resolution (default 720P), ratio (default 16:9), and duration (default 5 seconds) from the user request. If the user explicitly specifies a model (e.g., "model=happyhorse-1.1-r2v"), you must use exactly that model name.
2. Use the Bash tool to run the following script, which submits the task, waits for completion, and downloads the video in one go:
```bash
#!/bin/bash
set -e
TASK_RESPONSE=$(curl -s -X POST "https://token-plan.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis" \
-H "X-DashScope-Async: enable" \
-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "<model>",
"input": {"prompt": "<prompt>"},
"parameters": {"resolution": "<resolution>", "ratio": "<ratio>", "duration": <duration>}
}')
TASK_ID=$(echo "$TASK_RESPONSE" | grep -o '"task_id":"[^"]*"' | head -1 | cut -d'"' -f4)
if [ -z "$TASK_ID" ]; then echo "Submission failed: $TASK_RESPONSE"; exit 1; fi
echo "Task submitted, ID: $TASK_ID. Waiting for generation..."
while true; do
sleep 15
STATUS_RESPONSE=$(curl -s "https://token-plan.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/$TASK_ID" \
-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN")
STATUS=$(echo "$STATUS_RESPONSE" | grep -o '"task_status":"[^"]*"' | cut -d'"' -f4)
if [ "$STATUS" = "SUCCEEDED" ]; then
VIDEO_URL=$(echo "$STATUS_RESPONSE" | grep -o '"video_url":"[^"]*"' | cut -d'"' -f4)
OUTPUT="generated_$(date +%Y%m%d_%H%M%S).mp4"
curl -s -o "$OUTPUT" "$VIDEO_URL"
echo "Video downloaded: $(pwd)/$OUTPUT"
exit 0
elif [ "$STATUS" = "FAILED" ]; then
echo "Generation failed: $STATUS_RESPONSE"; exit 1
fi
echo "Generating..."
done
```
3. Display the generated video file path to the user.
In Claude Code, type /text-to-video a white cat sunbathing on a balcony. To use a different video generation model, include the model name in the command, for example /text-to-video generate a video of a cat jumping using happyhorse-1.1-r2v.
The configuration for other tools is the same as for image generation. Save the content to a text-to-video.md (or SKILL.md) file at the corresponding path listed in the Other tools table below.
Integrate speech synthesis models
Speech synthesis models use the DashScope WebSocket SDK. Install the DashScope Python SDK to use them.
Supported speech synthesis models
| Model | Description |
|---|
| qwen-audio-3.0-tts-plus | High-quality speech synthesis with fine-grained control. Supports multiple languages, dialects, and voice cloning. |
Example: Claude Code
Install the dependency:
Create the file .claude/commands/text-to-speech.md in your project root directory with the following content:
Call the Token Plan text-to-speech API to convert text to an audio file.
User request: $ARGUMENTS
## Steps
1. Extract text (the content to read aloud) and voice (default: longxiaochun) from the user request.
2. Use the Bash tool to run the following Python script to generate audio:
```python
import os
import dashscope
from dashscope.audio.tts_v2 import SpeechSynthesizer, AudioFormat
from datetime import datetime
dashscope.api_key = os.environ.get("ANTHROPIC_AUTH_TOKEN")
dashscope.base_websocket_api_url = "wss://token-plan.ap-southeast-1.maas.aliyuncs.com/api-ws/v1/inference"
synthesizer = SpeechSynthesizer(
model="qwen-audio-3.0-tts-plus",
voice="<voice>",
format=AudioFormat.MP3_22050HZ_MONO_256KBPS,
)
audio = synthesizer.call("<text>")
filename = f"speech_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp3"
with open(filename, "wb") as f:
f.write(audio)
print(f"Audio saved: {filename}")
```
3. Display the generated audio file path to the user.
In Claude Code, type /text-to-speech Hello, welcome to Qwen Cloud.
The following table lists the extension mechanism and configuration file path for each tool. Save the same content from the image generation example to the corresponding path.
| Tool | Extension mechanism | Configuration file path |
|---|
| Claude Code | Slash Command | .claude/commands/text-to-image.md |
| Codex | Skill | ~/.codex/skills/token-plan-image/SKILL.md |
| Qwen Code | Skill | ~/.qwen/skills/text-to-image/SKILL.md |
| OpenCode | Agent | .opencode/agents/text-to-image.md |
| OpenClaw | Skill | ~/.openclaw/workspace/skills/token-plan-image/SKILL.md |
| Hermes Agent | Skill | ~/.hermes/skills/media/text-to-image/SKILL.md |
| Qoder | Skill | ~/.qoder/skills/text-to-image/SKILL.md |
Skill-based tools (Codex, Qwen Code, OpenClaw, Hermes Agent, Qoder) require YAML front matter at the beginning of the file:
---
name: "token-plan-image"
description: "Call the Token Plan text-to-image model to generate images from text descriptions. Activates when the user asks to draw or generate images."
---
(... same content as the image generation example above ...)