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).
Example: Integrate an image generation model in 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
Set the plan-specific API Key (prefixed with sk-sp-) as the environment variable $ANTHROPIC_AUTH_TOKEN for curl authentication in subsequent steps.
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 (e.g., "model=wan2.7-image" or "use wan2.7-image to draw"), you must use exactly that model name and must not fall back to the default; use the default 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 Model Studio 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.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[*].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.
Example: Integrate a video generation model in Claude Code
This example shows how to integrate a video generation model in Claude Code using a Slash Command. Video generation uses an asynchronous API with the workflow: submit task, poll status, and download video.
Step 1: Create a Slash Command
Set the plan-specific API Key (prefixed with sk-sp-) as the environment variable $ANTHROPIC_AUTH_TOKEN for curl authentication in subsequent steps.
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.cn-beijing.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.cn-beijing.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.
Step 2: Generate a video
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.
Example: Integrate a speech synthesis model in Claude Code
This example shows how to integrate a speech synthesis model in Claude Code using a Slash Command. Speech synthesis uses a synchronous API and supports both non-streaming and streaming modes.
Step 1: Create a Slash Command
Set the plan-specific API Key (prefixed with sk-sp-) as the environment variable $ANTHROPIC_AUTH_TOKEN for curl authentication in subsequent steps.
Create the file .claude/commands/text-to-speech.md in your project root directory with the following content:
Call the Token Plan speech synthesis API to convert text to an audio file.
User request: $ARGUMENTS
## Steps
1. Extract text (the text to synthesize), voice (voice style, default longanhuan_v3.6), format (audio format, default mp3), and sample_rate (sample rate, default 24000) from the user request. If the user explicitly specifies a model, use that model name; otherwise default to qwen-audio-3.0-tts-plus.
2. Call the API to synthesize speech (use the Bash tool to run curl):
```
curl -s -X POST "https://token-plan.cn-beijing.maas.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer" \
-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-o "speech_$(date +%Y%m%d_%H%M%S).<format>" \
-d '{
"model": "<model>",
"input": {
"text": "<text>",
"voice": "<voice>",
"format": "<format>",
"sample_rate": <sample_rate>
}
}'
```
3. Display the generated audio file path to the user.
Step 2: Synthesize speech
In Claude Code, type /text-to-speech Hello, welcome to Model Studio.
Other tools
The following table lists the extension mechanism and configuration file path for mainstream AI coding tools that support extensions. Save the same content from the Claude Code example above to the corresponding path.
|
Tool |
Extension mechanism |
Configuration file path |
|
Claude Code |
Slash Command |
|
|
Codex |
Skill |
|
|
Qwen Code |
Skill |
|
|
OpenCode |
Agent |
|
|
OpenClaw |
Skill |
|
|
Hermes Agent |
Skill |
|
|
Qoder |
Skill |
|
Skill-based tools (Codex, Qwen Code, OpenClaw, Hermes Agent, Qoder) require YAML front matter at the beginning of the configuration 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 Claude Code example above ...)
OpenCode Agent requires a different front matter format:
---
description: "Call the Token Plan text-to-image model to generate images from text descriptions."
mode: subagent
tools:
bash: true
write: false
edit: false
---
(... same content as the Claude Code example above ...)