メインコンテンツへスキップ
Endpoint: POST /messages Claude を Messages API 経由で呼び出します。
多くの統合は Create Chat Completion を推奨します。Anthropic ネイティブ形式が必要な場合にこのエンドポイントを使ってください。
import requests

response = requests.post(
    "https://api.yourouter.ai/v1/messages",
    headers={
        "Authorization": "Bearer YOUR_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())

パラメータ

model
string
必須
対象モデル ID。
messages
array
必須
Claude メッセージ形式の履歴。
stream
boolean
デフォルト:"false"
true で SSE。

画像入力

ビジョン対応では messages に画像ブロックを含めます。
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>"
            }
          }
        ]
      }
    ]
  }'
全体の導線は マルチモーダル を参照してください。