Skip to main content
Best Practices

Integrate multimodal generation models

Integrate image generation models with Token Plan through tool extension mechanisms

Image generation models must be integrated through each tool's extension mechanism (Skill, Slash Command, or Agent).

Overview

AI coding tools cannot call image generation models directly through model configuration. Integrate them through each tool's extension mechanism instead.

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 (default: qwen-image-2.0), and size (default: `1024*1024`) from the user request.

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.

Other tools

The following table lists the extension mechanism and configuration file path for each tool. Save the same content from the Claude Code example to the corresponding path.
ToolExtension mechanismConfiguration file path
Claude CodeSlash Command.claude/commands/text-to-image.md
CodexSkill~/.codex/skills/token-plan-image/SKILL.md
Qwen CodeSkill~/.qwen/skills/text-to-image/SKILL.md
OpenCodeAgent.opencode/agents/text-to-image.md
OpenClawSkill~/.openclaw/workspace/skills/token-plan-image/SKILL.md
Hermes AgentSkill~/.hermes/skills/media/text-to-image/SKILL.md
Skill-based tools (Codex, Qwen Code, OpenClaw, Hermes Agent) 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 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 ...)