Canghe Image Generation
Generate images using the Canghe AI API with gemini-3-pro-image-preview model.
⚠️ 需要 API Key
使用本 skill 前,请先访问 https://api.canghe.ai/ 注册并获取 API Key。 获取后通过环境变量
CANGHE_API_KEY或--api-key参数传入。
API Information
- Endpoint:
https://api.canghe.ai/v1/chat/completions - Model:
gemini-3-pro-image-preview - Method: POST
Request Format
{
"model": "gemini-3-pro-image-preview",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Image generation prompt"
},
{
"type": "image_url",
"image_url": {
"url": "reference image URL (optional)"
}
}
]
}
],
"max_tokens": 4096
}
Usage
Text-to-Image
Generate image from text prompt only:
python3 scripts/generate_image.py "A beautiful sunset over mountains"
Image-to-Image (with reference)
Generate image using a reference image:
python3 scripts/generate_image.py "Transform this into oil painting style" --reference /path/to/image.jpg
Or with URL:
python3 scripts/generate_image.py "Add cyberpunk elements" --reference-url "https://example.com/image.jpg"
Programmatic Usage
from scripts.generate_image import generate_image
# Text-to-image
result = generate_image("A cute cat wearing a hat")
print(result["image_url"])
# With reference image
result = generate_image("Make this watercolor style", reference_image_path="/path/to/image.jpg")
print(result["image_url"])
Authentication
获取 API Key: 访问 https://api.canghe.ai/ 注册账号并获取 API Key。
设置 API Key 的方式:
export CANGHE_API_KEY="your-api-key-here"
Or pass it as a command-line argument:
python3 scripts/generate_image.py "prompt" --api-key "your-api-key"
Output
The API returns an image URL that can be downloaded or displayed. The script will:
- Save the generated image to the specified output path
- Print the image URL
- Return metadata about the generation