# チャットメッセージ (Anthropic)

Anthropic 互換パス：`POST /v1/messages`。Anthropic SDK またはネイティブプロトコル連携に適しています。[Messages API](https://docs.anthropic.com/en/api/messages)

* **パス**: `https://www.tokenpad.ai/v1/messages`
* **認証**: `x-api-key: sk-your_token_here`
* **必須ヘッダー**: `anthropic-version: 2023-06-01`
* **`max_tokens`**: 必須

マルチモーダルの場合、`content` は配列になります。画像は `type: image` を使用し、**base64 のみ対応**（`source.type = base64`）で、URL は非対応です。

---

## 1. テキストのみ

```bash
curl -X POST https://www.tokenpad.ai/v1/messages \
  -H "x-api-key: sk-your_token_here" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-4-6",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "こんにちは、一文で自己紹介してください。"}
    ]
  }'
```

---

## 2. マルチモーダル：画像 + テキスト（Base64）

`data` は**純粋な base64** にしてください（`data:image/...;base64,` プレフィックスは付けないでください）。

```bash
curl -X POST https://www.tokenpad.ai/v1/messages \
  -H "x-api-key: sk-your_token_here" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-4-6",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "image",
            "source": {
              "type": "base64",
              "media_type": "image/jpeg",
              "data": "<raw-base64>"
            }
          },
          { "type": "text", "text": "この画像には何がありますか？簡単に説明してください。" }
        ]
      }
    ]
  }'
```

`media_type`：`image/jpeg`、`image/png`、`image/gif`、`image/webp`。

---

## 3. マルチモーダル：複数画像の比較

複数の base64 `image` を続けて追加し、最後に `text` を配置します：

```bash
curl -X POST https://www.tokenpad.ai/v1/messages \
  -H "x-api-key: sk-your_token_here" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-4-6",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "image",
            "source": {
              "type": "base64",
              "media_type": "image/png",
              "data": "<raw-base64-a>"
            }
          },
          {
            "type": "image",
            "source": {
              "type": "base64",
              "media_type": "image/png",
              "data": "<raw-base64-b>"
            }
          },
          { "type": "text", "text": "これら2枚の画像の違いを比較してください。" }
        ]
      }
    ]
  }'
```

---

## 4. 主なパラメータ

| パラメータ | タイプ | 必須 | 説明 |
| :--- | :--- | :--- | :--- |
| `model` | string | はい | Claude モデル ID |
| `messages` | array | はい | `content`：文字列、または `[text / image(base64)]` |
| `max_tokens` | integer | はい | 最大生成トークン数 |
| `stream` | boolean | いいえ | デフォルト `false` |
| `temperature` | number | いいえ | 0~1 |
| `system` | string | いいえ | システムプロンプト（トップレベルフィールド。messages 内ではありません） |

SDK：公式 `anthropic` を使用し、`base_url="https://www.tokenpad.ai"`（自動で `/v1` が連結されます）、`api_key` に本プラットフォームのトークンを設定してください。

> OpenAI 互換チャット（`/v1/chat/completions`）についてはメニュー「チャット Chat」をご参照ください。



### 5. よくあるエラーコードとトラブルシューティング

HTTP ステータスコード、エラーボディ形式、およびシナリオ別のトラブルシューティングは各呼び出し例との重複・不整合を避けるため、専用ページにて**一元管理**しています。

👉 **[ゲートウェイよくあるエラーコードとトラブルシューティング](/docs/ja/errors/error-codes)**

**クイックリファレンス**（詳細は専用ページを参照）：

| コード | 意味 |
| :---: | :--- |
| **400** | パラメータ不正 / コンテンツモデレーションまたは著作権ブロック |
| **402** | アカウント残高不足（429 **ではありません**） |
| **429** | トークン RPS/RPM レート制限、または低残高時の実行中タスク上限超過 |
| **403** | トークン / IP / モデル権限不足（残高は 402、コンテンツ制限は 400） |
| **200 + `status: failed`** | 非同期動画など長時間タスクの業務処理失敗（ポーリング時によく発生） |

HTTP レスポンスコードはコンソールの呼び出しログ `status_code` と一致しており、`log_id` で追跡可能です。

> **メンテナンス規約**：エラー説明の追加・調整時は専用ページ `error-codes` のみを更新してください。本付録はリンク経由で自動的に最新内容を参照します。
