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

# 聊天识图

> OpenAI 风格的图片输入，覆盖 base64 与远程 URL 两种用法

> 更新日期：2026-06-06

# 聊天识图

```
POST /v1/chat/completions
```

Crazyrouter 生产环境已验证支持 OpenAI 风格 `image_url` 输入的常用模型：

* `gpt-4o`、`gpt-4o-mini`、`gpt-5.5`、`gpt-5.5` 等 OpenAI 视觉模型
* 输入支持 `data:image/...;base64,...` data URL 与公网 `https://` URL 两种形式
* 返回的 `message.content` 当前是普通字符串

> 推荐顺序：本地图先用 [图片上传接口](/upload) 转成 `media.crazyrouter.com` 临时 URL，再传入 `image_url`；或直接发送 base64 data URL。远程公网 URL 也可用，但要满足下文"远程 URL 限制"。

***

## 用 base64 data URL（最稳）

```bash theme={null}
curl https://api.crazyrouter.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [
      {
        "role": "user",
        "content": [
          {"type": "text", "text": "What color is this image?"},
          {
            "type": "image_url",
            "image_url": {
              "url": "data:image/png;base64,iVBORw0KGgoAAA..."
            }
          }
        ]
      }
    ],
    "max_tokens": 100
  }'
```

返回示例：

```json theme={null}
{
  "model": "gpt-4o-mini",
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "Red."
      }
    }
  ]
}
```

***

## 用远程 https URL

```bash theme={null}
curl https://api.crazyrouter.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [
      {
        "role": "user",
        "content": [
          {"type": "text", "text": "Describe in 5 words."},
          {
            "type": "image_url",
            "image_url": {
              "url": "https://www.gstatic.com/webp/gallery/1.jpg"
            }
          }
        ]
      }
    ],
    "max_tokens": 40
  }'
```

### 远程 URL 限制

URL 必须是 **Crazyrouter 服务端可访问**的图片地址，仅"浏览器能打开"是不够的。常见失败原因：

| 失败模式                     | 原因                                          | 解决方法                          |
| ------------------------ | ------------------------------------------- | ----------------------------- |
| 域名无法解析                   | 私网地址、拼写错误                                   | 改用公网 https URL                |
| 403 Forbidden            | 部分 CDN（如 wikimedia、私有 S3）限制服务端 UA / Referer | 改走 [图片上传接口](/upload) 或 base64 |
| Content-Type 非 `image/*` | URL 返回 HTML 页面或重定向到登录页                      | 确认 URL 直链可下载                  |
| 文件超过 20MB                | 单文件大小限制                                     | 压缩或裁剪后上传                      |

如果你看到错误信息 `Unable to process the image you provided. Please verify the image URL is publicly accessible, or upload it as base64.`，说明 URL 在服务端不可达，按上表排查。

***

## 推荐做法

* 内部素材、私有图、不确定可达性的图：先调 [`POST /v1/files/uploads`](/upload) 拿到 `media.crazyrouter.com/...` 的 72 小时临时 URL，再传给 `image_url`
* 体积小（\< 1MB）或一次性图：直接 base64 data URL，避免一次额外的上传请求
* 多图、`detail` 参数等高级用法：当前 OpenAI 上游均支持，按 OpenAI 官方协议传即可
