incorrect response structure in openapi documentation of app #5177

Closed
opened 2026-02-21 18:09:45 -05:00 by yindo · 2 comments
Owner

Originally created by @realethanhsu on GitHub (Aug 22, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.7.1

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

On the application’s accessible API page, review the example of the streamed message response structure for the /chat-messages endpoint.
image

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @realethanhsu on GitHub (Aug 22, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.7.1 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce On the application’s accessible API page, review the example of the streamed message response structure for the `/chat-messages` endpoint. <img width="1793" alt="image" src="https://github.com/user-attachments/assets/56fc872a-1bd3-4fcf-85a3-4b42cacea3a5"> ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 📚 documentation label 2026-02-21 18:09:45 -05:00
yindo closed this issue 2026-02-21 18:09:45 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 22, 2024):

@ethan-fly Hello there! I'm here to help you with bugs, questions, and becoming a contributor. Let's tackle this together while we wait for a human maintainer.

To correct the response structure in the OpenAPI documentation of the app for the /chat-messages endpoint in version 0.7.1, you need to ensure that the response format is clearly defined and matches the expected output. Here is the corrected response structure:

Response

When response_mode is blocking, return a ChatCompletionResponse object.
When response_mode is streaming, return a ChunkCompletionResponse stream.

ChatCompletionResponse

Returns the complete App result, Content-Type is application/json.

  • message_id (string): Unique message ID
  • conversation_id (string): Conversation ID
  • mode (string): App mode, fixed as chat
  • answer (string): Complete response content
  • metadata (object): Metadata
    • usage (Usage): Model usage information
    • retriever_resources (array[RetrieverResource]): Citation and Attribution List
  • created_at (int): Message creation timestamp, e.g., 1705395332

Example Response for Blocking Mode

{
    "event": "message",
    "message_id": "9da23599-e713-473b-982c-4328d4f5c78a",
    "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
    "mode": "chat",
    "answer": "iPhone 13 Pro Max specs are listed here:...",
    "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
        },
        "retriever_resources": [
            {
                "position": 1,
                "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
                "dataset_name": "iPhone",
                "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
                "document_name": "iPhone List",
                "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
                "score": 0.98457545,
                "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\""
            }
        ]
    },
    "created_at": 1705407629
}

Example Response for Streaming Mode

data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " I", "created_at": 1679586595}
data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": "'m", "created_at": 1679586595}
data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " glad", "created_at": 1679586595}
data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " to", "created_at": 1679586595}
data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " meet", "created_at": 1679586595}
data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " you", "created_at": 1679586595}

For more detailed information on how to use the API, including example requests, you can refer to the API documentation provided by Dify in the Applications -> Access API section. This documentation includes sample calls for both text-generation and conversational applications, which can help you understand how to structure your requests and handle responses effectively. The ChatMessageApi class in the api/controllers/console/app/completion.py file handles the /chat-messages endpoint and ensures the response structure is correctly implemented [1][2][3][4].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Aug 22, 2024): <!-- Greeting --> @ethan-fly Hello there! I'm here to help you with bugs, questions, and becoming a contributor. Let's tackle this together while we wait for a human maintainer. <!-- Answer --> To correct the response structure in the OpenAPI documentation of the app for the `/chat-messages` endpoint in version 0.7.1, you need to ensure that the response format is clearly defined and matches the expected output. Here is the corrected response structure: ### Response When `response_mode` is `blocking`, return a `ChatCompletionResponse` object. When `response_mode` is `streaming`, return a `ChunkCompletionResponse` stream. #### ChatCompletionResponse Returns the complete App result, `Content-Type` is `application/json`. - `message_id` (string): Unique message ID - `conversation_id` (string): Conversation ID - `mode` (string): App mode, fixed as `chat` - `answer` (string): Complete response content - `metadata` (object): Metadata - `usage` (Usage): Model usage information - `retriever_resources` (array[RetrieverResource]): Citation and Attribution List - `created_at` (int): Message creation timestamp, e.g., 1705395332 #### Example Response for Blocking Mode ```json { "event": "message", "message_id": "9da23599-e713-473b-982c-4328d4f5c78a", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "mode": "chat", "answer": "iPhone 13 Pro Max specs are listed here:...", "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 }, "retriever_resources": [ { "position": 1, "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb", "dataset_name": "iPhone", "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00", "document_name": "iPhone List", "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a", "score": 0.98457545, "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\"" } ] }, "created_at": 1705407629 } ``` #### Example Response for Streaming Mode ```streaming data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " I", "created_at": 1679586595} data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": "'m", "created_at": 1679586595} data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " glad", "created_at": 1679586595} data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " to", "created_at": 1679586595} data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " meet", "created_at": 1679586595} data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " you", "created_at": 1679586595} ``` For more detailed information on how to use the API, including example requests, you can refer to the API documentation provided by Dify in the **Applications -> Access API** section. This documentation includes sample calls for both text-generation and conversational applications, which can help you understand how to structure your requests and handle responses effectively. The `ChatMessageApi` class in the `api/controllers/console/app/completion.py` file handles the `/chat-messages` endpoint and ensures the response structure is correctly implemented <sup>[[1]](https://github.com/langgenius/dify/blob/main/web/app/components/develop/template/template_advanced_chat.en.mdx)</sup><sup>[[2]](https://github.com/langgenius/dify-docs/blob/main/en/guides/application-publishing/developing-with-apis.md)</sup><sup>[[3]](https://github.com/langgenius/dify/blob/main/web/app/components/develop/template/template_chat.en.mdx)</sup><sup>[[4]](https://github.com/langgenius/dify/blob/main/api/controllers/console/app/completion.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@dosubot[bot] commented on GitHub (Aug 22, 2024):

@ethan-fly Hello there! I'm here to help you with bugs, questions, and becoming a contributor. Let's tackle this together while we wait for a human maintainer.

To correct the response structure in the OpenAPI documentation of the app for the /chat-messages endpoint in version 0.7.1, you need to ensure that the response format is clearly defined and matches the expected output. Here is the corrected response structure:

Response

When response_mode is blocking, return a ChatCompletionResponse object.
When response_mode is streaming, return a ChunkCompletionResponse stream.

ChatCompletionResponse

Returns the complete App result, Content-Type is application/json.

  • message_id (string): Unique message ID
  • conversation_id (string): Conversation ID
  • mode (string): App mode, fixed as chat
  • answer (string): Complete response content
  • metadata (object): Metadata
    • usage (Usage): Model usage information
    • retriever_resources (array[RetrieverResource]): Citation and Attribution List
  • created_at (int): Message creation timestamp, e.g., 1705395332

Example Response for Blocking Mode

{
    "event": "message",
    "message_id": "9da23599-e713-473b-982c-4328d4f5c78a",
    "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
    "mode": "chat",
    "answer": "iPhone 13 Pro Max specs are listed here:...",
    "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
        },
        "retriever_resources": [
            {
                "position": 1,
                "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
                "dataset_name": "iPhone",
                "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
                "document_name": "iPhone List",
                "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
                "score": 0.98457545,
                "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\""
            }
        ]
    },
    "created_at": 1705407629
}

Example Response for Streaming Mode

data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " I", "created_at": 1679586595}
data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": "'m", "created_at": 1679586595}
data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " glad", "created_at": 1679586595}
data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " to", "created_at": 1679586595}
data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " meet", "created_at": 1679586595}
data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " you", "created_at": 1679586595}

For more detailed information on how to use the API, including example requests, you can refer to the API documentation provided by Dify in the Applications -> Access API section. This documentation includes sample calls for both text-generation and conversational applications, which can help you understand how to structure your requests and handle responses effectively. The ChatMessageApi class in the api/controllers/console/app/completion.py file handles the /chat-messages endpoint and ensures the response structure is correctly implemented [1][2][3][4].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Aug 22, 2024): <!-- Greeting --> @ethan-fly Hello there! I'm here to help you with bugs, questions, and becoming a contributor. Let's tackle this together while we wait for a human maintainer. <!-- Answer --> To correct the response structure in the OpenAPI documentation of the app for the `/chat-messages` endpoint in version 0.7.1, you need to ensure that the response format is clearly defined and matches the expected output. Here is the corrected response structure: ### Response When `response_mode` is `blocking`, return a `ChatCompletionResponse` object. When `response_mode` is `streaming`, return a `ChunkCompletionResponse` stream. #### ChatCompletionResponse Returns the complete App result, `Content-Type` is `application/json`. - `message_id` (string): Unique message ID - `conversation_id` (string): Conversation ID - `mode` (string): App mode, fixed as `chat` - `answer` (string): Complete response content - `metadata` (object): Metadata - `usage` (Usage): Model usage information - `retriever_resources` (array[RetrieverResource]): Citation and Attribution List - `created_at` (int): Message creation timestamp, e.g., 1705395332 #### Example Response for Blocking Mode ```json { "event": "message", "message_id": "9da23599-e713-473b-982c-4328d4f5c78a", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "mode": "chat", "answer": "iPhone 13 Pro Max specs are listed here:...", "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 }, "retriever_resources": [ { "position": 1, "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb", "dataset_name": "iPhone", "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00", "document_name": "iPhone List", "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a", "score": 0.98457545, "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\"" } ] }, "created_at": 1705407629 } ``` #### Example Response for Streaming Mode ```streaming data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " I", "created_at": 1679586595} data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": "'m", "created_at": 1679586595} data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " glad", "created_at": 1679586595} data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " to", "created_at": 1679586595} data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " meet", "created_at": 1679586595} data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " you", "created_at": 1679586595} ``` For more detailed information on how to use the API, including example requests, you can refer to the API documentation provided by Dify in the **Applications -> Access API** section. This documentation includes sample calls for both text-generation and conversational applications, which can help you understand how to structure your requests and handle responses effectively. The `ChatMessageApi` class in the `api/controllers/console/app/completion.py` file handles the `/chat-messages` endpoint and ensures the response structure is correctly implemented <sup>[[1]](https://github.com/langgenius/dify/blob/main/web/app/components/develop/template/template_advanced_chat.en.mdx)</sup><sup>[[2]](https://github.com/langgenius/dify-docs/blob/main/en/guides/application-publishing/developing-with-apis.md)</sup><sup>[[3]](https://github.com/langgenius/dify/blob/main/web/app/components/develop/template/template_chat.en.mdx)</sup><sup>[[4]](https://github.com/langgenius/dify/blob/main/api/controllers/console/app/completion.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5177