> ## 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-4.1`、`gpt-5.5` などの OpenAI 視覚モデル
* `data:image/...;base64,...` data URL と公開 `https://` URL の両方が利用可能
* `message.content` は現在プレーン文字列で返却されます

> 推奨手順：ローカル画像はまず [画像アップロード API](/jp/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 を拒否 | [アップロード API](/jp/upload) または base64 を使用 |
| Content-Type が `image/*` ではない | URL が HTML やログインページにリダイレクトしている                       | 画像直リンクであることを確認                          |
| ファイル 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`](/jp/upload) で 72 時間有効な `media.crazyrouter.com/...` URL を取得し、それを `image_url` に渡す
* 小さい（\< 1MB）画像、使い捨ての画像：base64 data URL を直接送り、追加リクエストを省く
* 複数画像入力、`detail` パラメータなどの高度な使い方：OpenAI 上流で対応済みなので、OpenAI 公式仕様どおりに送れば動作します
