> ## 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.

# API 调用与调试

> 即梦模型的 API 接口说明和常见问题排查

## 接口概览

即梦模型使用 OpenAI 兼容接口：

* **Base URL**：`https://models.hingnet.com.cn`
* **认证方式**：`Authorization: Bearer YOUR_API_KEY`

支持的接口：

* 文生图：`POST /v1/images/generations`
* 图生图：`POST /v1/images/edits`

提示：即梦系列（4.0 / 3.0 / agent）按次计费（0.8 RMB/次）并固定生成 4 张图片；

***

## 文生图接口

<ParamField path="model" type="string" required>
  模型名称：`jimeng-4.0` / `jimeng-3.0` / `jimeng-agent`
</ParamField>

<ParamField path="prompt" type="string" required>
  文本描述（支持中英文）
</ParamField>

<ParamField path="n" type="integer" default="4">
  生成数量。即梦系列（4.0 / 3.0 / agent）固定生成 4 张。
</ParamField>

<ParamField path="size" type="string" default="1024x1024">
  分辨率：`1024x1024` / `1024x1792` / `1792x1024`
</ParamField>

<ParamField path="response_format" type="string" default="url">
  返回格式
</ParamField>

<RequestExample>
  ```bash cURL 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": "一只可爱的熊猫在图书馆看书",
      "n": 1,
      "size": "1024x1024"
    }'
  ```

  ```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="一只可爱的熊猫在图书馆看书",
      n=1,
      size="1024x1024"
  )

  print(response.data[0].url)
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "created": 1700000000,
    "data": [
      {
        "url": "https://cdn.example.com/images/abc123.png"
      }
    ]
  }
  ```
</ResponseExample>

***

## 图生图接口

使用 `multipart/form-data` 格式上传图片。

<ParamField path="image" type="file" required>
  原始图片文件（PNG/JPEG）
</ParamField>

<ParamField path="model" type="string" required>
  模型名称
</ParamField>

<ParamField path="prompt" type="string">
  修改描述
</ParamField>

<ParamField path="n" type="integer" default="1">
  生成数量
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl https://models.hingnet.com.cn/v1/images/edits \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -F "image=@input.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"
  )

  with open("input.png", "rb") as image_file:
      response = client.images.edit(
          image=image_file,
          model="jimeng-4.0",
          prompt="添加科幻元素",
          n=1
      )

  print(response.data[0].url)
  ```
</RequestExample>
