> ## 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 response

OpenAI Responses APIフォーマットを使用して、ストリーミングまたは非ストリーミングのレスポンスを作成します。

## 認証

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

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

## リクエスト

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

<ParamField body="model" type="string" required>
  レスポンス生成に使用するモデルID。利用可能なモデルは [sunra.ai/models](https://sunra.ai/models) で確認できます。
</ParamField>

<ParamField body="input" type="string | object[]">
  レスポンスリクエストの入力。文字列または入力アイテムの配列を指定できます。

  <Expandable title="プロパティ（配列の場合）">
    <ParamField body="type" type="string">
      入力アイテムのタイプ。サポートされている値: `message`, `item_reference`。
    </ParamField>

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

    <ParamField body="content" type="string | object[]">
      入力メッセージの内容。文字列またはコンテンツパーツの配列を指定できます。
    </ParamField>

    <ParamField body="id" type="string">
      アイテムのID。会話履歴内の`assistant`メッセージに必須です。
    </ParamField>

    <ParamField body="status" type="string">
      アイテムのステータス。会話履歴内の`assistant`メッセージに必須です。
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="instructions" type="string | null">
  モデルのコンテキストの最初のアイテムとしてシステム（または開発者）メッセージを挿入します。`input`と共に使用する場合、instructionsは入力の先頭に挿入されます。
</ParamField>

<ParamField body="stream" type="boolean" default={false}>
  `true`に設定すると、サーバー送信イベント（SSE）を使用してレスポンスがストリーミングされます。
</ParamField>

<ParamField body="max_output_tokens" type="integer">
  可視出力トークンと推論トークンを含む、出力トークン数の上限。
</ParamField>

<ParamField body="temperature" type="number" default={1}>
  0から2の間のサンプリング温度。値が高いほどランダム性が増加します。
</ParamField>

<ParamField body="top_p" type="number" default={1}>
  核サンプリングパラメータ。temperatureによるサンプリングの代替です。
</ParamField>

<ParamField body="frequency_penalty" type="number" default={0}>
  -2.0から2.0の間の数値。正の値は、テキスト中の既存の頻度に基づいて新しいトークンにペナルティを課します。
</ParamField>

<ParamField body="presence_penalty" type="number" default={0}>
  -2.0から2.0の間の数値。正の値は、テキスト中に既に出現しているかどうかに基づいて新しいトークンにペナルティを課します。
</ParamField>

<ParamField body="tools" type="object[]">
  モデルが呼び出す可能性のあるツールの配列。

  <Expandable title="プロパティ">
    <ParamField body="type" type="string" required>
      ツールのタイプ。サポートされている値: `function`, `web_search_preview`。
    </ParamField>

    <ParamField body="name" type="string">
      関数の名前。typeが`function`の場合に必須です。
    </ParamField>

    <ParamField body="description" type="string">
      関数の説明。
    </ParamField>

    <ParamField body="parameters" type="object">
      関数パラメータを定義するJSONスキーマオブジェクト。
    </ParamField>

    <ParamField body="strict" type="boolean" default={false}>
      厳密なスキーマ準拠を有効にするかどうか。
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="tool_choice" type="string | object">
  ツール選択の動作を制御します。サポートされている文字列値: `none`, `auto`, `required`。特定の関数を指定することもできます。
</ParamField>

<ParamField body="parallel_tool_calls" type="boolean" default={true}>
  モデルがツール呼び出しを並列に実行することを許可するかどうか。
</ParamField>

<ParamField body="text" type="object">
  テキストレスポンスフォーマットの設定。

  <Expandable title="プロパティ">
    <ParamField body="format" type="object">
      テキストフォーマットの設定。

      <Expandable title="プロパティ">
        <ParamField body="type" type="string" required>
          フォーマットタイプ。サポートされている値: `text`, `json_object`, `json_schema`。
        </ParamField>

        <ParamField body="name" type="string">
          レスポンスフォーマットの名前。typeが`json_schema`の場合に必須です。
        </ParamField>

        <ParamField body="schema" type="object">
          JSONスキーマ。typeが`json_schema`の場合に必須です。
        </ParamField>

        <ParamField body="strict" type="boolean">
          厳密なスキーマ準拠を有効にするかどうか。
        </ParamField>
      </Expandable>
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="reasoning" type="object">
  推論出力の設定。

  <Expandable title="プロパティ">
    <ParamField body="effort" type="string">
      推論の労力を制約します。サポートされている値: `low`, `medium`, `high`。
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="store" type="boolean" default={true}>
  生成されたレスポンスを後で取得するために保存するかどうか。
</ParamField>

<ParamField body="metadata" type="object">
  レスポンスに添付できる16個のキーと値のペアのセット。キーは最大64文字の文字列です。値は最大512文字の文字列です。
</ParamField>

<ParamField body="user" type="string">
  エンドユーザーを表す一意の識別子。最大128文字。
</ParamField>

## レスポンス

成功レスポンスオブジェクト。

<ResponseField name="id" type="string">
  一意のレスポンス識別子。
</ResponseField>

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

<ResponseField name="created_at" type="number">
  レスポンスが作成された時のUnixタイムスタンプ（秒単位）。
</ResponseField>

<ResponseField name="status" type="string">
  レスポンスのステータス。可能な値: `completed`, `failed`, `in_progress`, `cancelled`。
</ResponseField>

<ResponseField name="model" type="string">
  レスポンス生成に使用されたモデル。
</ResponseField>

<ResponseField name="output" type="object[]">
  モデルによって生成されたコンテンツアイテムの配列。

  <Expandable title="プロパティ">
    <ResponseField name="type" type="string">
      出力アイテムのタイプ。例: `message`。
    </ResponseField>

    <ResponseField name="id" type="string">
      出力アイテムの一意のID。
    </ResponseField>

    <ResponseField name="role" type="string">
      ロール。常に`assistant`。
    </ResponseField>

    <ResponseField name="status" type="string">
      メッセージのステータス。例: `completed`。
    </ResponseField>

    <ResponseField name="content" type="object[]">
      出力メッセージの内容。

      <Expandable title="プロパティ">
        <ResponseField name="type" type="string">
          コンテンツタイプ。例: `output_text`。
        </ResponseField>

        <ResponseField name="text" type="string">
          生成されたテキストコンテンツ。
        </ResponseField>

        <ResponseField name="annotations" type="object[]">
          コンテンツのアノテーション（例: ウェブ検索からの引用）。
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="usage" type="object">
  レスポンスのトークン使用統計。

  <Expandable title="プロパティ">
    <ResponseField name="input_tokens" type="integer">
      入力トークン数。
    </ResponseField>

    <ResponseField name="output_tokens" type="integer">
      出力トークン数。
    </ResponseField>

    <ResponseField name="total_tokens" type="integer">
      合計トークン数。
    </ResponseField>

    <ResponseField name="input_tokens_details" type="object">
      入力トークンの内訳。

      <Expandable title="プロパティ">
        <ResponseField name="cached_tokens" type="integer">
          キャッシュされたトークン数。
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="output_tokens_details" type="object">
      出力トークンの内訳。

      <Expandable title="プロパティ">
        <ResponseField name="reasoning_tokens" type="integer">
          推論トークン数。
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="temperature" type="number">
  使用されたサンプリング温度。
</ResponseField>

<ResponseField name="top_p" type="number">
  使用された核サンプリング値。
</ResponseField>

<ResponseField name="max_output_tokens" type="integer | null">
  使用された最大出力トークン設定。
</ResponseField>

<ResponseField name="error" type="object | null">
  生成が失敗した場合のエラーオブジェクト。
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api-llm.sunra.ai/v1/responses \
    -H "Authorization: Bearer <SUNRA_KEY>" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "openai/gpt-4o",
      "input": [
        {
          "type": "message",
          "role": "user",
          "content": "Hello, how are you?"
        }
      ]
    }'
  ```

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

  response = requests.post(
      "https://api-llm.sunra.ai/v1/responses",
      headers={
          "Authorization": "Bearer <SUNRA_KEY>",
          "Content-Type": "application/json"
      },
      json={
          "model": "openai/gpt-4o",
          "input": [
              {
                  "type": "message",
                  "role": "user",
                  "content": "Hello, how are you?"
              }
          ]
      }
  )
  print(response.json())
  ```

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

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "resp-abc123",
    "object": "response",
    "created_at": 1704067200,
    "status": "completed",
    "model": "openai/gpt-4o",
    "output": [
      {
        "type": "message",
        "id": "msg_abc123",
        "role": "assistant",
        "status": "completed",
        "content": [
          {
            "type": "output_text",
            "text": "Hello! I'm doing well, thank you for asking. How can I help you today?",
            "annotations": []
          }
        ]
      }
    ],
    "temperature": 1.0,
    "top_p": 1.0,
    "max_output_tokens": null,
    "usage": {
      "input_tokens": 15,
      "output_tokens": 18,
      "total_tokens": 33,
      "input_tokens_details": {
        "cached_tokens": 0
      },
      "output_tokens_details": {
        "reasoning_tokens": 0
      }
    },
    "error": null
  }
  ```
</ResponseExample>
