# Canghe Image Gen

> Generate images using Canghe AI API (gemini-3-pro-image-preview model). Supports text-to-image generation and image-to-image generation with reference images. Use when user asks to "generate image", "create image", "draw image", "生图", "生成图片", "垫图生图", or any image generation tasks requiring Canghe AI API.

- Skill: `freestylefly/canghe-image-gen-2` (Agent Skill, multi-file: 3 files)
- Install (CLI): `npx skillmds@latest add freestylefly/canghe-image-gen-2`
- Raw SKILL.md: https://api.skillmd.com/api/skills/freestylefly/canghe-image-gen-2/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: freestylefly (https://skillmd.com/u/freestylefly)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/freestylefly/canghe-image-gen-2

---


# 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

```json
{
  "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:

```bash
python3 scripts/generate_image.py "A beautiful sunset over mountains"
```

### Image-to-Image (with reference)

Generate image using a reference image:

```bash
python3 scripts/generate_image.py "Transform this into oil painting style" --reference /path/to/image.jpg
```

Or with URL:

```bash
python3 scripts/generate_image.py "Add cyberpunk elements" --reference-url "https://example.com/image.jpg"
```

### Programmatic Usage

```python
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 的方式：

```bash
export CANGHE_API_KEY="your-api-key-here"
```

Or pass it as a command-line argument:

```bash
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:
1. Save the generated image to the specified output path
2. Print the image URL
3. Return metadata about the generation

