Dans Token Plan, intégrez les modèles de génération d'images, de vidéo et de synthèse vocale via le mécanisme d'extension de chaque outil (Skill, Slash Command ou Agent).
Exemple : Intégrer un modèle de génération d'images dans Claude Code
Cet exemple illustre l'intégration d'un modèle de génération d'images dans Claude Code au moyen d'une Slash Command. La procédure est similaire pour les autres outils ; seuls le mécanisme d'extension et le chemin du fichier de configuration diffèrent.
Étape 1 : Créer une Slash Command
Définissez la clé API spécifique au plan (préfixée par sk-sp-) comme variable d'environnement $ANTHROPIC_AUTH_TOKEN pour authentifier les requêtes curl lors des étapes suivantes.
Créez le fichier .claude/commands/text-to-image.md à la racine de votre projet avec le contenu suivant :
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.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.
Étape 2 : Générer une image
Dans Claude Code, saisissez /text-to-image draw a cat. Pour utiliser un modèle de génération d'images autre que le modèle par défaut, précisez son nom dans la commande, par exemple /text-to-image draw a cat using wan2.7-image.
Exemple : Intégrer un modèle de génération vidéo dans Claude Code
Cet exemple montre comment intégrer un modèle de génération vidéo dans Claude Code à l'aide d'une Slash Command. La génération vidéo repose sur une API asynchrone dont le flux de travail comprend trois phases : soumission de la tâche, interrogation de l'état, puis téléchargement de la vidéo.
Étape 1 : Créer une Slash Command
Définissez la clé API spécifique au plan (préfixée par sk-sp-) comme variable d'environnement $ANTHROPIC_AUTH_TOKEN pour authentifier les requêtes curl lors des étapes suivantes.
Créez le fichier .claude/commands/text-to-video.md à la racine de votre projet avec le contenu suivant :
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:
#!/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.
Étape 2 : Générer une vidéo
Dans Claude Code, saisissez /text-to-video a white cat sunbathing on a balcony. Pour utiliser un autre modèle de génération vidéo, indiquez son nom dans la commande, par exemple /text-to-video generate a video of a cat jumping using happyhorse-1.1-r2v.
Exemple : Intégrer un modèle de synthèse vocale dans Claude Code
Cet exemple détaille l'intégration d'un modèle de synthèse vocale dans Claude Code via une Slash Command. La synthèse vocale s'appuie sur une API synchrone compatible avec les modes streaming et non-streaming.
Étape 1 : Créer une Slash Command
Définissez la clé API spécifique au plan (préfixée par sk-sp-) comme variable d'environnement $ANTHROPIC_AUTH_TOKEN pour authentifier les requêtes curl lors des étapes suivantes.
Créez le fichier .claude/commands/text-to-speech.md à la racine de votre projet avec le contenu suivant :
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.ap-southeast-1.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.
Étape 2 : Synthétiser la parole
Dans Claude Code, saisissez /text-to-speech Hello, welcome to Model Studio.
Autres outils
Le tableau ci-dessous récapitule le mécanisme d'extension et le chemin du fichier de configuration des principaux outils de codage IA compatibles avec les extensions. Enregistrez le contenu identique à celui de l'exemple Claude Code ci-dessus dans le chemin correspondant.
Outil | Mécanisme d'extension | Chemin du fichier de configuration |
|---|---|---|
Claude Code | Slash Command |
|
Codex | Skill |
|
Qwen Code | Skill |
|
OpenCode | Agent |
|
OpenClaw | Skill |
|
Hermes Agent | Skill |
|
Qoder | Skill |
|
RemarqueLes outils basés sur des Skills (Codex, Qwen Code, OpenClaw, Hermes Agent, Qoder) exigent un en-tête YAML au début du fichier de configuration :
---
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 ...)
L'Agent OpenCode nécessite un format d'en-tête différent :
---
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 ...)