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

# Create a message

Anthropic Messages APIフォーマットを使用してメッセージを作成します。テキスト、画像、PDF、ツール、拡張思考に対応しています。

## 認証

<ParamField header="Authorization" type="string" required>
  Bearerトークン。APIキーをAuthorizationヘッダーのBearerトークンとして使用してください。

  Format: `Bearer <SUNRA_KEY>`
</ParamField>

## リクエスト

このエンドポイントはJSONオブジェクトを受け付けます。

<ParamField body="model" type="string" required>
  プロンプトを補完するモデル。利用可能なモデルは [sunra.ai/models](https://sunra.ai/models) で確認できます。
</ParamField>

<ParamField body="messages" type="object[]" required>
  入力メッセージ。各入力メッセージには`role`と`content`があります。

  <Expandable title="プロパティ">
    <ParamField body="role" type="string" required>
      メッセージ作成者のロール。サポートされている値: `user`, `assistant`。
    </ParamField>

    <ParamField body="content" type="string | object[]" required>
      メッセージの内容。単一の文字列またはコンテンツブロックの配列を指定できます。

      <Expandable title="コンテンツブロックタイプ">
        <ParamField body="type" type="string" required>
          コンテンツブロックのタイプ。サポートされている値: `text`, `image`, `tool_use`, `tool_result`。
        </ParamField>

        <ParamField body="text" type="string">
          テキストコンテンツ。typeが`text`の場合に使用されます。
        </ParamField>

        <ParamField body="source" type="object">
          画像ソース。typeが`image`の場合に使用されます。

          <Expandable title="プロパティ">
            <ParamField body="type" type="string" required>
              ソースタイプ。サポートされている値: `base64`, `url`。
            </ParamField>

            <ParamField body="media_type" type="string" required>
              画像のメディアタイプ。例: `image/jpeg`, `image/png`, `image/gif`, `image/webp`。
            </ParamField>

            <ParamField body="data" type="string">
              Base64エンコードされた画像データ。ソースタイプが`base64`の場合に必須です。
            </ParamField>

            <ParamField body="url" type="string">
              画像のURL。ソースタイプが`url`の場合に必須です。
            </ParamField>
          </Expandable>
        </ParamField>
      </Expandable>
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="max_tokens" type="integer" required>
  停止前に生成するトークンの最大数。モデルがこの最大値に達する前に停止する場合があることにご注意ください。
</ParamField>

<ParamField body="system" type="string | object[]">
  システムプロンプト。モデルにコンテキストと指示を提供する方法です。文字列またはコンテンツブロックの配列を指定できます。
</ParamField>

<ParamField body="stream" type="boolean" default={false}>
  サーバー送信イベント（SSE）を使用してレスポンスをインクリメンタルにストリーミングするかどうか。
</ParamField>

<ParamField body="temperature" type="number" default={1}>
  レスポンスに注入されるランダム性の量。0.0から1.0の範囲。分析的/多肢選択タスクには0.0に近い`temperature`を、創造的・生成的タスクには1.0に近い値を使用してください。
</ParamField>

<ParamField body="top_p" type="number">
  核サンプリングを使用します。核サンプリングでは、後続の各トークンについて確率の降順で全オプションの累積分布を計算し、`top_p`で指定された特定の確率に達した時点で打ち切ります。
</ParamField>

<ParamField body="top_k" type="integer">
  各後続トークンについて上位K個のオプションからのみサンプリングします。確率の低い「ロングテール」レスポンスを除去するために使用されます。上級ユースケースにのみ推奨されます。
</ParamField>

<ParamField body="stop_sequences" type="string[]">
  モデルの生成を停止させるカスタムテキストシーケンス。返されるテキストには停止シーケンスは含まれません。
</ParamField>

<ParamField body="tools" type="object[]">
  モデルが使用する可能性のあるツールの定義。

  <Expandable title="プロパティ">
    <ParamField body="name" type="string" required>
      ツールの名前。
    </ParamField>

    <ParamField body="description" type="string">
      このツールが何をするかの説明。
    </ParamField>

    <ParamField body="input_schema" type="object" required>
      このツールの入力のJSONスキーマ。ツールが受け入れる`input`の形状を定義します。
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="tool_choice" type="object">
  モデルが提供されたツールをどのように使用するか。

  <Expandable title="プロパティ">
    <ParamField body="type" type="string" required>
      サポートされている値: `auto`（デフォルト、モデルが判断）, `any`（モデルはツールを使用する必要がある）, `tool`（モデルは特定のツールを使用する必要がある）。
    </ParamField>

    <ParamField body="name" type="string">
      使用するツールの名前。typeが`tool`の場合に必須です。
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="metadata" type="object">
  リクエストに関するメタデータを記述するオブジェクト。

  <Expandable title="プロパティ">
    <ParamField body="user_id" type="string">
      リクエストに関連付けられたユーザーの外部識別子。
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="thinking" type="object">
  拡張思考の設定。有効にすると、モデルは応答する前に思考します。

  <Expandable title="プロパティ">
    <ParamField body="type" type="string" required>
      `enabled`である必要があります。
    </ParamField>

    <ParamField body="budget_tokens" type="integer" required>
      思考に使用するトークンの最大数。1024以上である必要があります。
    </ParamField>
  </Expandable>
</ParamField>

## レスポンス

メッセージの成功レスポンス。

<ResponseField name="id" type="string">
  一意のメッセージ識別子。例: `msg_01XFDUDYJgAACzvnptvVoYEL`。
</ResponseField>

<ResponseField name="type" type="string">
  オブジェクトタイプ。常に`message`。
</ResponseField>

<ResponseField name="role" type="string">
  生成されたメッセージの会話ロール。常に`assistant`。
</ResponseField>

<ResponseField name="content" type="object[]">
  モデルによって生成されたコンテンツ。これはコンテンツブロックの配列です。

  <Expandable title="プロパティ">
    <ResponseField name="type" type="string">
      コンテンツブロックのタイプ。`text`、`tool_use`、または`thinking`。
    </ResponseField>

    <ResponseField name="text" type="string">
      生成されたテキスト。typeが`text`の場合に存在します。
    </ResponseField>

    <ResponseField name="id" type="string">
      ツール使用ブロックのID。typeが`tool_use`の場合に存在します。
    </ResponseField>

    <ResponseField name="name" type="string">
      ツールの名前。typeが`tool_use`の場合に存在します。
    </ResponseField>

    <ResponseField name="input" type="object">
      ツールへの入力。typeが`tool_use`の場合に存在します。
    </ResponseField>

    <ResponseField name="thinking" type="string">
      思考コンテンツ。typeが`thinking`の場合に存在します。
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="model" type="string">
  リクエストを処理したモデル。
</ResponseField>

<ResponseField name="stop_reason" type="string | null">
  モデルが停止した理由。`end_turn`（モデルが自然な停止点に達した）、`max_tokens`（`max_tokens`またはモデルの最大値を超えた）、`stop_sequence`（カスタム停止シーケンスの1つが生成された）、または`tool_use`（モデルが1つ以上のツールを呼び出した）。
</ResponseField>

<ResponseField name="stop_sequence" type="string | null">
  どのカスタム停止シーケンスが生成されたか（該当する場合）。
</ResponseField>

<ResponseField name="usage" type="object">
  課金およびレート制限の使用状況。3つの入力バケットは相互排他的です — [トークン使用量](/ja/llm/token-usage)を参照してください。

  <Expandable title="プロパティ">
    <ResponseField name="input_tokens" type="integer">
      使用された新規の入力トークン数。両方のキャッシュバケットを除きます。
    </ResponseField>

    <ResponseField name="output_tokens" type="integer">
      使用された出力トークン数。
    </ResponseField>

    <ResponseField name="total_tokens" type="integer">
      すべての入力バケットと`output_tokens`の合計。streamingのレスポンスでは省略されます。
    </ResponseField>

    <ResponseField name="cache_creation_input_tokens" type="integer">
      キャッシュエントリの作成に使用された入力トークン数。
    </ResponseField>

    <ResponseField name="cache_read_input_tokens" type="integer">
      キャッシュから読み取られた入力トークン数。
    </ResponseField>

    <ResponseField name="sunra_usage_semantics" type="string | null">
      Sunraがこのレスポンスを正規化した場合に`anthropic.exclusive.v1`として存在します。数値から規約を推測するのではなく、この値に対してアサートしてください。[トークン使用量](/ja/llm/token-usage)を参照してください。
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api-llm.sunra.ai/v1/messages \
    -H "Authorization: Bearer <SUNRA_KEY>" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "anthropic/claude-sonnet-4-20250514",
      "max_tokens": 1024,
      "messages": [
        {
          "role": "user",
          "content": "Hello, how are you?"
        }
      ]
    }'
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api-llm.sunra.ai/v1/messages",
      headers={
          "Authorization": "Bearer <SUNRA_KEY>",
          "Content-Type": "application/json"
      },
      json={
          "model": "anthropic/claude-sonnet-4-20250514",
          "max_tokens": 1024,
          "messages": [
              {"role": "user", "content": "Hello, how are you?"}
          ]
      }
  )
  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch("https://api-llm.sunra.ai/v1/messages", {
    method: "POST",
    headers: {
      "Authorization": "Bearer <SUNRA_KEY>",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      model: "anthropic/claude-sonnet-4-20250514",
      max_tokens: 1024,
      messages: [
        { role: "user", content: "Hello, how are you?" }
      ]
    })
  });
  const data = await response.json();
  console.log(data);
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "msg_01XFDUDYJgAACzvnptvVoYEL",
    "type": "message",
    "role": "assistant",
    "content": [
      {
        "type": "text",
        "text": "Hello! I'm doing well, thank you for asking. How can I help you today?"
      }
    ],
    "model": "anthropic/claude-sonnet-4-20250514",
    "stop_reason": "end_turn",
    "stop_sequence": null,
    "usage": {
      "input_tokens": 12,
      "output_tokens": 19,
      "total_tokens": 31,
      "sunra_usage_semantics": "anthropic.exclusive.v1"
    }
  }
  ```
</ResponseExample>
