> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hingnet.com.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用示例

> 即梦模型的实际调用示例

## 快速开始

> 注意：即梦系列（4.0 / 3.0 / agent）已改为按次计费，系统固定生成 4 张图片。

### 文生图（单张）

```bash theme={null}
curl https://models.hingnet.com.cn/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "jimeng-4.0",
    "prompt": "一只可爱的熊猫在图书馆看书",
    "size": "1024x1024"
  }'
```

### 文生图（多张）

```bash theme={null}
curl https://models.hingnet.com.cn/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "jimeng-3.0",
    "prompt": "未来城市的夜景，赛博朋克风格",
    "n": 4,
    "size": "1792x1024"
  }'
```

### 图生图

```bash theme={null}
curl https://models.hingnet.com.cn/v1/images/edits \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "image=@original.png" \
  -F "model=jimeng-4.0" \
  -F "prompt=添加科幻元素和霓虹灯效果" \
  -F "n=1"
```

***

## Python 示例

### 文生图

```python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://models.hingnet.com.cn/v1"
)

response = client.images.generate(
    model="jimeng-4.0",
    prompt="一只可爱的熊猫在图书馆看书",
    size="1024x1024"
)

print(response.data[0].url)
```

### 图生图

```python theme={null}
with open("input.png", "rb") as image_file:
    response = client.images.edit(
        image=image_file,
        model="jimeng-4.0",
        prompt="添加科幻元素"
    )

print(response.data[0].url)
```

### 批量生成

```python theme={null}
prompts = [
    "熊猫在图书馆看书",
    "熊猫在公园散步",
    "熊猫在竹林里休息"
]

for prompt in prompts:
    response = client.images.generate(
        model="jimeng-3.0",
        prompt=prompt,
        n=1
    )
    print(f"{prompt}: {response.data[0].url}")
```

### 错误处理

```python theme={null}
from openai import OpenAI, APIError, RateLimitError

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://models.hingnet.com.cn/v1"
)

try:
    response = client.images.generate(
        model="jimeng-4.0",
        prompt="测试图片",
        n=1
    )
    print(response.data[0].url)
    
except RateLimitError:
    print("请求频率过高，请稍后重试")
    
except APIError as e:
    print(f"API 错误: {e}")
```

### 下载生成的图片

```python theme={null}
import requests

response = client.images.generate(
    model="jimeng-4.0",
    prompt="一只可爱的熊猫",
    n=1
)

image_url = response.data[0].url

# 下载图片
img_data = requests.get(image_url).content
with open('output.png', 'wb') as f:
    f.write(img_data)
```

***

## 模型选择建议

| 场景         | 推荐模型           | 理由        |
| ---------- | -------------- | --------- |
| 商业设计、高质量海报 | `jimeng-4.0`   | 画质最佳，细节丰富 |
| 快速原型、批量生成  | `jimeng-3.0`   | 速度快，性价比高  |
| 多轮对话式创作    | `jimeng-agent` | 智能理解上下文   |
