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

# 完了メッセージを送信

> テキスト生成アプリケーションにリクエストを送信します。



## OpenAPI

````yaml /ja/api-reference/openapi_completion.json post /completion-messages
openapi: 3.0.1
info:
  title: Completion アプリ API
  description: テキスト生成アプリケーションはセッションなしで動作し、翻訳、記事作成、要約 AI などに最適です。
  version: 1.0.0
servers:
  - url: https://{api_base_url}
    description: テキスト生成アプリ API のベース URL です。セルフホスト環境では、独自の API ベース URL に置き換えてください。
    variables:
      api_base_url:
        default: api.dify.ai/v1
        description: API ベース URL のホストとパス（`https://` を除く）。
security:
  - ApiKeyAuth: []
tags:
  - name: 完了メッセージ
    description: テキスト生成に関連する操作です。
  - name: ファイル操作
    description: ファイル管理に関連する操作です。
  - name: エンドユーザー
    description: エンドユーザー情報に関連する操作です。
  - name: メッセージフィードバック
    description: ユーザーフィードバックに関連する操作です。
  - name: 音声・テキスト変換
    description: テキスト読み上げと音声認識に関連する操作です。
  - name: アプリケーション設定
    description: アプリケーション設定と情報を取得する操作です。
paths:
  /completion-messages:
    post:
      tags:
        - 完了メッセージ
      summary: 完了メッセージを送信
      description: テキスト生成アプリケーションにリクエストを送信します。
      operationId: createCompletionMessageJp
      requestBody:
        description: テキスト生成メッセージを作成するためのリクエストボディ。
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CompletionRequest'
            examples:
              streaming_example:
                summary: リクエスト例 - ストリーミングモード
                value:
                  inputs:
                    city: San Francisco
                  query: Translate 'hello' to Spanish.
                  response_mode: streaming
                  user: abc-123
                  files:
                    - type: image
                      transfer_method: remote_url
                      url: https://cloud.dify.ai/logo/logo-site.png
              blocking_example:
                summary: リクエスト例 - ブロッキングモード
                value:
                  inputs:
                    city: New York
                  query: 'Summarize the following text: ...'
                  response_mode: blocking
                  user: def-456
      responses:
        '200':
          description: >-
            リクエスト成功。コンテンツタイプと構造はリクエストの `response_mode` パラメータに依存します。


            - `response_mode` が `blocking` の場合、 `application/json` で
            `CompletionResponse` オブジェクトを返します。

            - `response_mode` が `streaming` の場合、 `text/event-stream` で
            `ChunkCompletionEvent` オブジェクトのストリームを返します。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CompletionResponse'
              examples:
                blockingResponse:
                  summary: レスポンス例 - ブロッキングモード
                  value:
                    event: message
                    task_id: c3800678-a077-43df-a102-53f23ed20b88
                    id: b01a39de-3480-4f3e-9f1e-4841a80f8e5e
                    message_id: 9da23599-e713-473b-982c-4328d4f5c78a
                    mode: completion
                    answer: Hello World!...
                    metadata:
                      usage:
                        prompt_tokens: 1033
                        prompt_unit_price: '0.001'
                        prompt_price_unit: '0.001'
                        prompt_price: '0.0010330'
                        completion_tokens: 128
                        completion_unit_price: '0.002'
                        completion_price_unit: '0.001'
                        completion_price: '0.0002560'
                        total_tokens: 1161
                        total_price: '0.0012890'
                        currency: USD
                        latency: 0.7682376249867957
                    created_at: 1705407629
            text/event-stream:
              schema:
                type: string
                description: >-
                  サーバー送信イベント (SSE) のストリームです。各イベントは `data: ` プレフィックス付きの JSON
                  オブジェクトで、2 つの改行で終了します。


                  **SSE パースガイド：**各イベントは `data: ` プレフィックス付きの JSON
                  オブジェクトの行で、`\n\n` で終了します。JSON をパースする前に `data: `
                  プレフィックスを除去してください。JSON 内の `event`
                  フィールドがイベントタイプを決定します。終了イベント（`message_end`、`error`
                  など）を受信するとストリームは終了します。`ping` イベント（10
                  秒ごとに接続維持のために送信）は無視してください。ストリーム内でエラーイベントが発生しても HTTP ステータスコードは常に
                  `200` です。
              examples:
                streamingResponse:
                  summary: レスポンス例 - ストリーミングモード
                  value: >+
                    data: {"event": "message", "task_id":
                    "900bbd43-dc0b-4383-a372-aa6e6c414227", "message_id":
                    "5ad4cb98-f0c7-4085-b384-88c403be6290", "answer": " I",
                    "created_at": 1679586595}


                    data: {"event": "message", "task_id":
                    "900bbd43-dc0b-4383-a372-aa6e6c414227", "message_id":
                    "5ad4cb98-f0c7-4085-b384-88c403be6290", "answer": "'m",
                    "created_at": 1679586595}


                    data: {"event": "message_end", "task_id":
                    "900bbd43-dc0b-4383-a372-aa6e6c414227", "id":
                    "5e52ce04-874b-4d27-9045-b3bc80def685", "message_id":
                    "5ad4cb98-f0c7-4085-b384-88c403be6290", "metadata":
                    {"usage": {"prompt_tokens": 1033, "prompt_unit_price":
                    "0.001", "prompt_price_unit": "0.001", "prompt_price":
                    "0.0010330", "completion_tokens": 135,
                    "completion_unit_price": "0.002", "completion_price_unit":
                    "0.001", "completion_price": "0.0002700", "total_tokens":
                    1168, "total_price": "0.0013030", "currency": "USD",
                    "latency": 1.381760165997548}}}

        '400':
          description: |-
            - `app_unavailable` : アプリケーションが利用できないか、設定が正しくありません。
            - `provider_not_initialize` : 有効なモデルプロバイダーの認証情報が見つかりません。
            - `provider_quota_exceeded` : モデルプロバイダーのクォータが使い切られました。
            - `model_currently_not_support` : 現在のモデルは利用できません。
            - `completion_request_error` : テキスト生成に失敗しました。
          content:
            application/json:
              examples:
                app_unavailable:
                  summary: app_unavailable
                  value:
                    status: 400
                    code: app_unavailable
                    message: App unavailable, please check your app configurations.
                provider_not_initialize:
                  summary: provider_not_initialize
                  value:
                    status: 400
                    code: provider_not_initialize
                    message: >-
                      No valid model provider credentials found. Please go to
                      Settings -> Model Provider to complete your provider
                      credentials.
                provider_quota_exceeded:
                  summary: provider_quota_exceeded
                  value:
                    status: 400
                    code: provider_quota_exceeded
                    message: >-
                      Your quota for Dify Hosted OpenAI has been exhausted.
                      Please go to Settings -> Model Provider to complete your
                      own provider credentials.
                model_currently_not_support:
                  summary: model_currently_not_support
                  value:
                    status: 400
                    code: model_currently_not_support
                    message: >-
                      Dify Hosted OpenAI trial currently not support the GPT-4
                      model.
                completion_request_error:
                  summary: completion_request_error
                  value:
                    status: 400
                    code: completion_request_error
                    message: Completion request failed.
        '429':
          description: '`too_many_requests` : このアプリケーションへの同時リクエストが多すぎます。'
          content:
            application/json:
              examples:
                too_many_requests:
                  summary: too_many_requests
                  value:
                    status: 429
                    code: too_many_requests
                    message: Too many requests. Please try again later.
        '500':
          description: '`internal_server_error` : 内部サーバーエラー。'
          content:
            application/json:
              examples:
                internal_server_error:
                  summary: internal_server_error
                  value:
                    status: 500
                    code: internal_server_error
                    message: Internal server error.
components:
  schemas:
    CompletionRequest:
      type: object
      required:
        - inputs
        - user
      properties:
        inputs:
          type: object
          description: >-
            アプリで定義されたさまざまな変数の値を入力できます。キーと値のペアを含み、各キーは特定の変数に対応し、各値はその変数の具体的な値です。アプリが期待する変数名と型については、[アプリケーションのパラメータ情報を取得](/api-reference/アプリケーション設定/アプリケーションのパラメータ情報を取得)
            レスポンスの `user_input_form` フィールドを参照してください。
          additionalProperties: true
        query:
          type: string
          default: ''
          description: >-
            処理対象の入力テキストです。これはレガシーパラメータであり、新しいアプリではクエリを `inputs`
            オブジェクト内で渡す必要があります。
        response_mode:
          type: string
          enum:
            - streaming
            - blocking
          description: >-
            レスポンスの返却モード。`streaming`（推奨）は SSE を使用します。`blocking`
            は完了後に返却します（長時間の処理では中断される場合があります）。Cloudflare のタイムアウトは `100 s`
            です。省略した場合、デフォルトでブロッキングモードになります。
        user:
          type: string
          description: >-
            ユーザー識別子。アプリケーション内で一意です。この識別子はデータアクセスの範囲を制限します。メッセージとファイルは同じ `user`
            値でクエリした場合のみ表示されます。
        files:
          type: array
          items:
            $ref: '#/components/schemas/InputFileObject'
          description: >-
            マルチモーダル理解用のファイルリストです。画像、ドキュメント、音声、動画を含みます。ローカルファイルを添付するには、まず
            [ファイルをアップロード](/api-reference/ファイル操作/ファイルをアップロード) でアップロードし、返された `id`
            を `upload_file_id` として `transfer_method: local_file` で使用します。
    CompletionResponse:
      type: object
      properties:
        event:
          type: string
          description: イベントタイプ。`message` に固定されています。
        task_id:
          type: string
          format: uuid
          description: リクエスト追跡および [生成を停止](/api-reference/完了メッセージ/生成を停止) API 用のタスク ID です。
        id:
          type: string
          format: uuid
          description: このレスポンスイベントの一意 ID です。
        message_id:
          type: string
          format: uuid
          description: >-
            一意のメッセージ ID です。フィードバックや推奨質問のエンドポイントを呼び出す際に `message_id`
            パラメータとして使用します。
        mode:
          type: string
          description: アプリモード、`completion` 固定です。
        answer:
          type: string
          description: 完全なレスポンスコンテンツ。
        metadata:
          type: object
          description: 使用量と検索リソースを含むメタデータ。
          properties:
            usage:
              $ref: '#/components/schemas/Usage'
            retriever_resources:
              type: array
              description: 使用された検索リソースのリスト。
              items:
                $ref: '#/components/schemas/RetrieverResource'
        created_at:
          type: integer
          format: int64
          description: メッセージ作成タイムスタンプ（Unix エポック秒）。
    InputFileObject:
      type: object
      required:
        - type
        - transfer_method
      properties:
        type:
          type: string
          enum:
            - image
            - document
            - audio
            - video
            - custom
          description: ファイルタイプ。
        transfer_method:
          type: string
          enum:
            - remote_url
            - local_file
          description: 転送方法です。ファイル URL の場合は `remote_url`、アップロードファイルの場合は `local_file` です。
        url:
          type: string
          format: url
          description: ファイル URL（`transfer_method` が `remote_url` の場合）です。
        upload_file_id:
          type: string
          description: >-
            事前に [ファイルをアップロード](/api-reference/ファイル操作/ファイルをアップロード) API
            でアップロードして取得したファイル ID です（`transfer_method` が `local_file` の場合に使用）。
      anyOf:
        - properties:
            transfer_method:
              enum:
                - remote_url
            url:
              type: string
              format: url
          required:
            - url
          not:
            required:
              - upload_file_id
        - properties:
            transfer_method:
              enum:
                - local_file
            upload_file_id:
              type: string
          required:
            - upload_file_id
          not:
            required:
              - url
    Usage:
      type: object
      properties:
        prompt_tokens:
          type: integer
          description: プロンプト内のトークン数。
        prompt_unit_price:
          type: string
          format: decimal
          description: プロンプトトークンあたりの単価。
        prompt_price_unit:
          type: string
          format: decimal
          description: プロンプトトークンの価格単位。
        prompt_price:
          type: string
          format: decimal
          description: プロンプトトークンの合計価格。
        completion_tokens:
          type: integer
          description: 補完のトークン数。
        completion_unit_price:
          type: string
          format: decimal
          description: 補完トークンあたりの単価。
        completion_price_unit:
          type: string
          format: decimal
          description: 補完トークンの価格単位。
        completion_price:
          type: string
          format: decimal
          description: 補完トークンの合計価格。
        total_tokens:
          type: integer
          description: 使用されたトークンの合計数。
        total_price:
          type: string
          format: decimal
          description: すべてのトークンの合計価格。
        currency:
          type: string
          description: 課金通貨。
        latency:
          type: number
          format: double
          description: レイテンシ（秒）。
    RetrieverResource:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: 検索リソースの一意の ID。
        message_id:
          type: string
          format: uuid
          description: このリソースが属するメッセージの ID。
        position:
          type: integer
          description: リスト内のリソースの位置。
        dataset_id:
          type: string
          format: uuid
          description: ナレッジベース ID。
        dataset_name:
          type: string
          description: ナレッジベース名。
        document_id:
          type: string
          format: uuid
          description: ドキュメント ID。
        document_name:
          type: string
          description: ドキュメント名。
        data_source_type:
          type: string
          description: データソースのタイプ。
        segment_id:
          type: string
          format: uuid
          description: ドキュメント内の特定のチャンクの ID。
        score:
          type: number
          format: float
          description: リソースの関連性スコア。
        hit_count:
          type: integer
          description: このチャンクがヒットした回数。
        word_count:
          type: integer
          description: チャンクの単語数。
        segment_position:
          type: integer
          description: ドキュメント内のチャンクの位置。
        index_node_hash:
          type: string
          description: インデックスノードのハッシュ。
        content:
          type: string
          description: リソースからのコンテンツスニペット。
        summary:
          type: string
          nullable: true
          description: チャンクコンテンツの要約。
        created_at:
          type: integer
          format: int64
          description: 作成タイムスタンプ（Unix エポック秒）。
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API_KEY
      description: >-
        API Key 認証です。すべての API リクエストにおいて、`Authorization` HTTP ヘッダーに `Bearer `
        プレフィックスを付けた API Key を含めてください。例：`Authorization: Bearer {API_KEY}`。**API
        Key はサーバーサイドに保存し、クライアントサイドで共有・保存しないことを強く推奨します。API Key
        の漏洩は深刻な結果につながる可能性があります。**

````