Knowledge retrieval POST endpoints randomly returning 400 errors #7190

Closed
opened 2026-02-21 18:19:20 -05:00 by yindo · 3 comments
Owner

Originally created by @sugoh on GitHub (Dec 13, 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.13.2

Cloud or Self Hosted

Cloud

Steps to reproduce

  1. Create a HTTP Request block
  2. Set it to POST https://api.dify.ai/v1/datasets/{DATASET_ID}/retrieve
  3. Set headers Content-Type to application/json
  4. Add the following as a raw body (side note: the docs have conflicting information on what this request body should be):
{
	"query": "{{#sys.query#}}",
	"retrieval_model": {
        "search_method": "hybrid_search",
        "reranking_enable": false,
        "reranking_mode": null,
        "reranking_model": {
            "reranking_provider_name": "",
            "reranking_model_name": ""
        },
        "weights": 0.7,
        "top_k": 4,
        "score_threshold_enabled": false,
        "score_threshold": null
    }
}
  1. Open up preview and start chatting. Type "Hello world" followed by shift + return. Hit "return", check workflow process.

✔️ Expected Behavior

200 response

Actual Behavior

Sometimes the request works, sometimes it doesn't. We've tested it using the exact same query string and have seen both 200 and 400 responses.

When it goes wrong, this happens:
Inspecting the Workflow process shows that the HTTP request has been parsed as:

{
  "request": "POST /v1/datasets/{xxxxxxx}7/retrieve HTTP/1.1\r\nHost: api.dify.ai\r\nContent-Type: application/json\r\nAuthorization: ***************************************\r\nContent-Length: 456\r\n\r\n{\n\t\"query\": \"I bought a pair of shoes 10 days ago and I want to return it.\n\",\n\t\"retrieval_model\": {\n        \"search_method\": \"hybrid_search\",\n        \"reranking_enable\": false,\n        \"reranking_mode\": null,\n        \"reranking_model\": {\n            \"reranking_provider_name\": \"\",\n            \"reranking_model_name\": \"\"\n        },\n        \"weights\": 0.7,\n        \"top_k\": 4,\n        \"score_threshold_enabled\": false,\n        \"score_threshold\": null\n    }\n}"
}

and the response is:

{
  "status_code": 400,
  "body": "{\"code\": \"bad_request\", \"message\": \"The browser (or proxy) sent a request that this server could not understand.\", \"status\": 400}\n",
  "headers": {
    "date": "Fri, 13 Dec 2024 12:27:51 GMT",
    "content-type": "application/json",
    "content-length": "130",
    "connection": "keep-alive",
    "access-control-allow-origin": "*",
    "x-env": "PRODUCTION",
    "x-version": "0.13.2",
    "cf-cache-status": "DYNAMIC",
    "report-to": "{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v4?s=uqH%2Ft4P%2BZyrd1%2Fx2s7x%2Bxkv2ctMJd%2BxLJ856n42Kt82ovRXtH%2BtAxkXMXdGVs0DmzsUNixso1NUksP%2FfkvmDCVnbFYl5HkVR%2Bhb4ED61se%2BTQmzc3nZib0GC9HXZ\"}],\"group\":\"cf-nel\",\"max_age\":604800}",
    "nel": "{\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}",
    "strict-transport-security": "max-age=31536000; includeSubDomains",
    "x-content-type-options": "nosniff",
    "x-frame-options": "DENY",
    "server": "cloudflare",
    "cf-ray": "8f15f35ba9148bbe-IAD",
    "server-timing": "cfL4;desc=\"?proto=TCP&rtt=2081&min_rtt=1357&rtt_var=1026&sent=4&recv=7&lost=0&retrans=0&sent_bytes=2827&recv_bytes=1478&delivery_rate=2134119&cwnd=251&unsent_bytes=0&cid=77161576d4e8b5c1&ts=60&x=0\""
  },
  "files": []
}
Originally created by @sugoh on GitHub (Dec 13, 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.13.2 ### Cloud or Self Hosted Cloud ### Steps to reproduce 1. Create a HTTP Request block 2. Set it to POST `https://api.dify.ai/v1/datasets/{DATASET_ID}/retrieve` 3. Set headers `Content-Type` to `application/json` 4. Add the following as a raw body (side note: the docs have conflicting information on what this request body should be): ```json { "query": "{{#sys.query#}}", "retrieval_model": { "search_method": "hybrid_search", "reranking_enable": false, "reranking_mode": null, "reranking_model": { "reranking_provider_name": "", "reranking_model_name": "" }, "weights": 0.7, "top_k": 4, "score_threshold_enabled": false, "score_threshold": null } } ``` 5. Open up preview and start chatting. Type "Hello world" followed by shift + return. Hit "return", check workflow process. ### ✔️ Expected Behavior `200` response ### ❌ Actual Behavior Sometimes the request works, sometimes it doesn't. We've tested it using the exact same query string and have seen both `200` and `400` responses. When it goes wrong, this happens: Inspecting the Workflow process shows that the HTTP request has been parsed as: ``` { "request": "POST /v1/datasets/{xxxxxxx}7/retrieve HTTP/1.1\r\nHost: api.dify.ai\r\nContent-Type: application/json\r\nAuthorization: ***************************************\r\nContent-Length: 456\r\n\r\n{\n\t\"query\": \"I bought a pair of shoes 10 days ago and I want to return it.\n\",\n\t\"retrieval_model\": {\n \"search_method\": \"hybrid_search\",\n \"reranking_enable\": false,\n \"reranking_mode\": null,\n \"reranking_model\": {\n \"reranking_provider_name\": \"\",\n \"reranking_model_name\": \"\"\n },\n \"weights\": 0.7,\n \"top_k\": 4,\n \"score_threshold_enabled\": false,\n \"score_threshold\": null\n }\n}" } ``` and the response is: ``` { "status_code": 400, "body": "{\"code\": \"bad_request\", \"message\": \"The browser (or proxy) sent a request that this server could not understand.\", \"status\": 400}\n", "headers": { "date": "Fri, 13 Dec 2024 12:27:51 GMT", "content-type": "application/json", "content-length": "130", "connection": "keep-alive", "access-control-allow-origin": "*", "x-env": "PRODUCTION", "x-version": "0.13.2", "cf-cache-status": "DYNAMIC", "report-to": "{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v4?s=uqH%2Ft4P%2BZyrd1%2Fx2s7x%2Bxkv2ctMJd%2BxLJ856n42Kt82ovRXtH%2BtAxkXMXdGVs0DmzsUNixso1NUksP%2FfkvmDCVnbFYl5HkVR%2Bhb4ED61se%2BTQmzc3nZib0GC9HXZ\"}],\"group\":\"cf-nel\",\"max_age\":604800}", "nel": "{\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}", "strict-transport-security": "max-age=31536000; includeSubDomains", "x-content-type-options": "nosniff", "x-frame-options": "DENY", "server": "cloudflare", "cf-ray": "8f15f35ba9148bbe-IAD", "server-timing": "cfL4;desc=\"?proto=TCP&rtt=2081&min_rtt=1357&rtt_var=1026&sent=4&recv=7&lost=0&retrans=0&sent_bytes=2827&recv_bytes=1478&delivery_rate=2134119&cwnd=251&unsent_bytes=0&cid=77161576d4e8b5c1&ts=60&x=0\"" }, "files": [] } ```
yindo added the 🐞 bugcloud labels 2026-02-21 18:19:20 -05:00
yindo closed this issue 2026-02-21 18:19:21 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Dec 13, 2024):

The 400 Bad Request error you're encountering with the Dify knowledge retrieval POST endpoint could be due to several factors. Here are some potential causes and solutions:

  1. Request Body Format: Ensure that the JSON request body is correctly formatted and includes all required fields. According to the documentation, the query field and the retrieval_model object should be properly structured. Double-check that the JSON is valid and that all necessary fields are included [1].

  2. Validation Errors: The Dify API might return a 400 error if there are validation issues with the request. This could include missing required fields or incorrect data types. Make sure that fields like query, retrieval_model, search_method, weights, and top_k are correctly specified.

  3. Rate Limiting: If your requests are being sent in quick succession, you might be hitting a rate limit, which can cause inconsistent responses. The Dify codebase includes rate limiting mechanisms that could affect the consistency of responses if the limit is exceeded [2].

  4. Error Codes and Messages: The Dify API provides specific error codes and messages for 400 errors. Check if the response includes any of these codes, as they can give more insight into what might be going wrong. For example, errors like app_unavailable, not_completion_app, or provider_not_initialize could indicate specific issues with the app configuration or provider credentials [3].

  5. Logging and Debugging: Utilize the logging capabilities in the Dify platform to trace the processing of your requests. This can help identify where the error is occurring in the workflow [4].

By addressing these areas, you may be able to resolve the issue or at least gain more insight into why the 400 errors are occurring.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot[bot] commented on GitHub (Dec 13, 2024): <!-- Answer --> The 400 Bad Request error you're encountering with the Dify knowledge retrieval POST endpoint could be due to several factors. Here are some potential causes and solutions: 1. **Request Body Format**: Ensure that the JSON request body is correctly formatted and includes all required fields. According to the documentation, the `query` field and the `retrieval_model` object should be properly structured. Double-check that the JSON is valid and that all necessary fields are included <sup>[[1]](https://github.com/langgenius/dify-docs/blob/main/en/.gitbook/assets/Dify-test.openapi.json)</sup>. 2. **Validation Errors**: The Dify API might return a 400 error if there are validation issues with the request. This could include missing required fields or incorrect data types. Make sure that fields like `query`, `retrieval_model`, `search_method`, `weights`, and `top_k` are correctly specified. 3. **Rate Limiting**: If your requests are being sent in quick succession, you might be hitting a rate limit, which can cause inconsistent responses. The Dify codebase includes rate limiting mechanisms that could affect the consistency of responses if the limit is exceeded <sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/app/features/rate_limiting/rate_limit.py)</sup>. 4. **Error Codes and Messages**: The Dify API provides specific error codes and messages for 400 errors. Check if the response includes any of these codes, as they can give more insight into what might be going wrong. For example, errors like `app_unavailable`, `not_completion_app`, or `provider_not_initialize` could indicate specific issues with the app configuration or provider credentials <sup>[[3]](https://github.com/langgenius/dify/blob/main/api/controllers/web/error.py)</sup>. 5. **Logging and Debugging**: Utilize the logging capabilities in the Dify platform to trace the processing of your requests. This can help identify where the error is occurring in the workflow <sup>[[4]](https://github.com/langgenius/dify/blob/main/api/core/workflow/nodes/knowledge_retrieval/knowledge_retrieval_node.py)</sup>. By addressing these areas, you may be able to resolve the issue or at least gain more insight into why the 400 errors are occurring. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/4f9557e3-b7e4-4667-9b0f-47c9d130f3ad?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/4f9557e3-b7e4-4667-9b0f-47c9d130f3ad?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/4f9557e3-b7e4-4667-9b0f-47c9d130f3ad?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/4f9557e3-b7e4-4667-9b0f-47c9d130f3ad?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/4f9557e3-b7e4-4667-9b0f-47c9d130f3ad?feedback_type=hallucination) | [Other](https://app.dosu.dev/response-feedback/4f9557e3-b7e4-4667-9b0f-47c9d130f3ad?feedback_type=other)</sup>
Author
Owner

@blacktail commented on GitHub (Dec 13, 2024):

I also meet this issue when i added a http node in my workflow, And the http is for calling the endpoint https://api.dify.ai/v1/datasets/{DATASET_ID}/retrieve.
I checked the Dify's requests in browser's devtool, and find it may be caused by some special characters in the query string, such as the \n.

Details:
First, i did following configuration for the HTTP node:
image

Then when i input a query which contains a \n, i input this by using Dify's UI and press (Shift + Return)
Hello, who are\nyou?, then the 400 error occurs.
image
And i found the Dify is sending out the query like this:
image

Then i try to switch the Body option to JSON
image
And found it's now successful, and the Dify is sending out the query:
image

Not sure if this is a bug for raw format of BODY in HTTP Request node on Dify side, Could Dify detect this kind of escape issues and make the error not happen? Thanks a lot.

@blacktail commented on GitHub (Dec 13, 2024): I also meet this issue when i added a http node in my workflow, And the http is for calling the endpoint `https://api.dify.ai/v1/datasets/{DATASET_ID}/retrieve`. I checked the Dify's requests in browser's devtool, and find it may be caused by some special characters in the query string, such as the `\n`. Details: First, i did following configuration for the HTTP node: ![image](https://github.com/user-attachments/assets/1073a9fc-1f4b-4a38-929d-737280e66234) Then when i input a query which contains a `\n`, i input this by using Dify's UI and press (Shift + Return) `Hello, who are\nyou?`, then the 400 error occurs. ![image](https://github.com/user-attachments/assets/724675be-4a6a-48ba-8645-392ac78f9a79) And i found the Dify is sending out the query like this: ![image](https://github.com/user-attachments/assets/2cdf4b50-0d76-4a66-b69c-3cda3a4ec936) Then i try to switch the Body option to JSON ![image](https://github.com/user-attachments/assets/9431e147-a191-4c4e-a97f-c2dc176798db) And found it's now successful, and the Dify is sending out the query: ![image](https://github.com/user-attachments/assets/a147e6e3-42b9-411c-9dea-46afd1ebb3fb) Not sure if this is a bug for raw format of BODY in HTTP Request node on Dify side, Could Dify detect this kind of escape issues and make the error not happen? Thanks a lot.
Author
Owner

@dosubot[bot] commented on GitHub (Jan 21, 2025):

Hi, @sugoh. I'm Dosu, and I'm helping the Dify team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • Inconsistent 400 errors from knowledge retrieval POST endpoints in Dify version 0.13.2.
  • Potential causes included request body format issues and special characters in the query string.
  • "Blacktail" suggested switching the request body format to JSON, which resolved the issue.
  • You acknowledged the resolution with a thumbs-up reaction.

Next Steps:

  • Please confirm if this issue is still relevant to the latest version of Dify. If so, you can keep the discussion open by commenting here.
  • If there are no further updates, this issue will be automatically closed in 15 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Jan 21, 2025): Hi, @sugoh. I'm [Dosu](https://dosu.dev), and I'm helping the Dify team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - Inconsistent 400 errors from knowledge retrieval POST endpoints in Dify version 0.13.2. - Potential causes included request body format issues and special characters in the query string. - "Blacktail" suggested switching the request body format to JSON, which resolved the issue. - You acknowledged the resolution with a thumbs-up reaction. **Next Steps:** - Please confirm if this issue is still relevant to the latest version of Dify. If so, you can keep the discussion open by commenting here. - If there are no further updates, this issue will be automatically closed in 15 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#7190