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

# Create Message

> Anthropic Messages API で Claude と対話します。

**Endpoint:** `POST /messages`

Claude を Messages API 経由で呼び出します。

<Note>
  多くの統合は [Create Chat Completion](/ja/api-reference/chat/create) を推奨します。Anthropic ネイティブ形式が必要な場合にこのエンドポイントを使ってください。
</Note>

<CodeGroup>
  ```python Python theme={null}
  import os
  import requests

  response = requests.post(
      "https://api.yourouter.ai/v1/messages",
      headers={
          "Authorization": f"Bearer {os.environ['YOUROUTER_API_KEY']}",
          "Content-Type": "application/json",
          "anthropic-version": "2023-06-01",
          "vendor": "anthropic"
      },
      json={
          "model": "claude-3-5-sonnet-20240620",
          "messages": [{"role": "user", "content": "Hello"}]
      }
  )
  print(response.json())
  ```

  ```bash cURL theme={null}
  curl https://api.yourouter.ai/v1/messages \
    -H "Authorization: Bearer $YOUROUTER_API_KEY" \
    -H "Content-Type: application/json" \
    -H "anthropic-version: 2023-06-01" \
    -H "vendor: anthropic" \
    -d '{"model": "claude-3-5-sonnet-20240620", "messages": [{"role": "user", "content": "Hello"}]}'
  ```
</CodeGroup>

## パラメータ

<ResponseField name="model" type="string" required>
  対象モデル ID。
</ResponseField>

<ResponseField name="messages" type="array" required>
  Claude メッセージ形式の履歴。
</ResponseField>

<ResponseField name="stream" type="boolean" default="false">
  `true` の場合、結果は Server-Sent Events として返されます。
</ResponseField>

## 画像入力

ビジョン対応では `messages` に画像ブロックを含めます。

```bash theme={null}
curl https://api.yourouter.ai/v1/messages \
  -H "Authorization: Bearer $YOUROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -H "vendor: anthropic" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 300,
    "messages": [
      {
        "role": "user",
        "content": [
          { "type": "text", "text": "Describe this image in one sentence." },
          {
            "type": "image",
            "source": {
              "type": "base64",
              "media_type": "image/jpeg",
              "data": "<BASE64_IMAGE>"
            }
          }
        ]
      }
    ]
  }'
```

## PDF 入力

PDF に対応する Claude モデルでは、`document` コンテンツブロックを送り、`source.media_type` を `application/pdf` に設定します。`data` フィールドには PDF の生バイト列を base64 エンコードした値を入れます。

```bash theme={null}
curl https://api.yourouter.ai/v1/messages \
  -H "Authorization: Bearer $YOUROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -H "vendor: anthropic" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "document",
            "source": {
              "type": "base64",
              "media_type": "application/pdf",
              "data": "<BASE64_PDF>"
            }
          },
          {
            "type": "text",
            "text": "Summarize this PDF and list risks to watch."
          }
        ]
      }
    ]
  }'
```

<Note>
  Claude の PDF 対応は具体的なモデルに依存します。標準的で暗号化されていない PDF を使い、リクエスト本文サイズとページ数を制御してください。大きい文書は分割して処理します。
</Note>

より広い連携パスは [マルチモーダル](/ja/guides/multimodal) を参照してください。
