使用 Coze AI 平台生成图像。支持文本到图像生成,自动进行 Base64 编码以便内联预览。适用于需要创建图像的场景...
Generate images from text prompts using the Coze AI platform. This skill handles the complete workflow: submitting prompts, parsing SSE responses, downloading images, and returning Base64-encoded data URIs for inline display.
python
from coze_image_skill import run
result = run({
"text": "一只可爱的小猫,毛茸茸的,大眼睛,坐在窗台上",
"api_token": "your_coze_api_token"
})
# Result contains:
# - image: data:image/jpeg;base64,... (inline Base64)
# - mime_type: image/jpeg
# - filename: generated-image.jpeg
# - source_url: original image URL
python
result = run({
"prompt": "a cute orange cat playing on grass, sunny day",
"api_token": "your_token",
"project_id": "your_project_id",
"session_id": "your_session_id",
"timeout": 90,
"include_debug": True
})
Set these in your OpenClaw configuration or .env file:
VariableDescriptionDefaultIMAGE_API_TOKENCoze API authentication tokenRequiredIMAGE_API_URLCoze stream_run endpointhttps://6fj9k4p9x3.coze.site/stream_run``IMAGE_API_PROJECT_IDCoze project ID7621854258107039796``IMAGE_API_SESSION_IDCoze session IDmT8SQeCGgTMZNBsJEiRuN``IMAGE_API_TIMEOUTRequest timeout in seconds60
ParameterTypeDescriptiontext or promptstringImage generation prompt (required)api_tokenstringCoze API token (or use env var)project_idstringCoze project ID (or use env var)session_idstringCoze session ID (or use env var)timeoutintRequest timeout in secondsinclude_debugboolInclude debug info in responsestrictboolRaise exceptions instead of returning error object
json
{
"image": "data:image/jpeg;base64,/9j/4AAQSkZJRg...",
"mime_type": "image/jpeg",
"filename": "generated-image.jpeg",
"source_url": "https://..."
}
json
{
"error": "Error message describing what went wrong",
"image": null,
"mime_type": null,
"filename": null,
"source_url": null
}
Install the skill via ClawHub: bash
openclaw skills install coze-image
Configure your API token: bash
openclaw config set IMAGE_API_TOKEN your_token_here
Generate your first image: text
Generate a picture of a sunset over the ocean
This means the Coze project returned text instead of an image. Make sure:
MIT License - See license file for details.
For issues or questions, please open an issue on the ClawHub repository.