OpenAI-API-compatible Model throws "Non-JSON encountered." error #45

Closed
opened 2026-02-16 10:17:51 -05:00 by yindo · 16 comments
Owner

Originally created by @TinyFatty on GitHub (Mar 6, 2025).

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 Dify issues & Dify Official Plugins, 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

1.0.0

Plugin version

Built-in LLM block(I don't see any version here)

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

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

1.0.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I used OpenAI-API-compatible Models (offered by China Telecom) in workflow LLM blocks and it throws "Non-JSON encountered." error (3 blocks share the same configuration, Deepseek official api and Silconflow deepseek api return the correct answer).

Here is the configuration for all

Image

Here is the error message

Image

OUTPUT data:

{
  "text": "",
  "usage": {
    "prompt_tokens": 0,
    "prompt_unit_price": "0",
    "prompt_price_unit": "0",
    "prompt_price": "0",
    "completion_tokens": 0,
    "completion_unit_price": "0",
    "completion_price_unit": "0",
    "completion_price": "0",
    "total_tokens": 0,
    "total_price": "0",
    "currency": "USD",
    "latency": 0.9801772950013401
  },
  "finish_reason": "Non-JSON encountered."
}

It takes only 1 second and no token is used,so I think the error occurs before the model starts reasoning.
Then I tested this model with python scripts

import openai

client= openai.OpenAI(base_url="***",
                           api_key="***")


response = client.chat.completions.create(
    model="7ba7726dad4c4ea4ab7f39c7741aea68",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Who are you?"}
    ],
    temperature=0.7
)

It shows the corrent answer
{"code":0,"id":"chatcmpl-00-89c57718adba43dd5650511e4ecece0f-ba26f79321d736fa-01","choices":[{"index":0,"message":{"content":"<think>\nGreetings! I'm DeepSeek-R1, an artificial intelligence assistant created by DeepSeek. I'm at your service and would be delighted to assist you with any inquiries or tasks you may have.\n</think>\n\nGreetings! I'm DeepSeek-R1, an artificial intelligence assistant created by DeepSeek. I'm at your service and would be delighted to assist you with any inquiries or tasks you may have.","role":"assistant"},"finish_reason":"stop"}],"created":1741254044,"model":"DeepSeek-R1","object":"chat.completion","usage":{"completion_tokens":83,"prompt_tokens":16,"total_tokens":99}}
Is there any special configuration I missed for OpenAI-API-compatible Model?

✔️ Error log

OUTPUT data:

{
  "text": "",
  "usage": {
    "prompt_tokens": 0,
    "prompt_unit_price": "0",
    "prompt_price_unit": "0",
    "prompt_price": "0",
    "completion_tokens": 0,
    "completion_unit_price": "0",
    "completion_price_unit": "0",
    "completion_price": "0",
    "total_tokens": 0,
    "total_price": "0",
    "currency": "USD",
    "latency": 0.9801772950013401
  },
  "finish_reason": "Non-JSON encountered."
}
Originally created by @TinyFatty on GitHub (Mar 6, 2025). ### 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 [Dify issues](https://github.com/langgenius/dify/issues) & [Dify Official Plugins](https://github.com/langgenius/dify-official-plugins/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 1.0.0 ### Plugin version Built-in LLM block(I don't see any version here) ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce ### 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 1.0.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce I used OpenAI-API-compatible Models (offered by China Telecom) in workflow LLM blocks and it throws "Non-JSON encountered." error (3 blocks share the same configuration, Deepseek official api and Silconflow deepseek api return the correct answer). Here is the configuration for all ![Image](https://github.com/user-attachments/assets/6ec57804-e8f2-4a07-b91d-cacfae723f12) Here is the error message ![Image](https://github.com/user-attachments/assets/a1ec4818-bd12-4e5e-8304-c3971cf8f863) OUTPUT data: ``` { "text": "", "usage": { "prompt_tokens": 0, "prompt_unit_price": "0", "prompt_price_unit": "0", "prompt_price": "0", "completion_tokens": 0, "completion_unit_price": "0", "completion_price_unit": "0", "completion_price": "0", "total_tokens": 0, "total_price": "0", "currency": "USD", "latency": 0.9801772950013401 }, "finish_reason": "Non-JSON encountered." } ``` It takes only 1 second and no token is used,so I think the error occurs before the model starts reasoning. Then I tested this model with python scripts ``` import openai client= openai.OpenAI(base_url="***", api_key="***") response = client.chat.completions.create( model="7ba7726dad4c4ea4ab7f39c7741aea68", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Who are you?"} ], temperature=0.7 ) ``` It shows the corrent answer `{"code":0,"id":"chatcmpl-00-89c57718adba43dd5650511e4ecece0f-ba26f79321d736fa-01","choices":[{"index":0,"message":{"content":"<think>\nGreetings! I'm DeepSeek-R1, an artificial intelligence assistant created by DeepSeek. I'm at your service and would be delighted to assist you with any inquiries or tasks you may have.\n</think>\n\nGreetings! I'm DeepSeek-R1, an artificial intelligence assistant created by DeepSeek. I'm at your service and would be delighted to assist you with any inquiries or tasks you may have.","role":"assistant"},"finish_reason":"stop"}],"created":1741254044,"model":"DeepSeek-R1","object":"chat.completion","usage":{"completion_tokens":83,"prompt_tokens":16,"total_tokens":99}}` Is there any special configuration I missed for OpenAI-API-compatible Model? ### ✔️ Error log OUTPUT data: ``` { "text": "", "usage": { "prompt_tokens": 0, "prompt_unit_price": "0", "prompt_price_unit": "0", "prompt_price": "0", "completion_tokens": 0, "completion_unit_price": "0", "completion_price_unit": "0", "completion_price": "0", "total_tokens": 0, "total_price": "0", "currency": "USD", "latency": 0.9801772950013401 }, "finish_reason": "Non-JSON encountered." } ```
yindo added the bug label 2026-02-16 10:17:51 -05:00
yindo closed this issue 2026-02-16 10:17:51 -05:00
Author
Owner

@TinyFatty commented on GitHub (Mar 6, 2025):

Additional Information。
I rolled back to ver 0.15.3. The same model worked fine.
So I think maybe ver 1.0.0 changed something and didn't mention it.

@TinyFatty commented on GitHub (Mar 6, 2025): Additional Information。 I rolled back to ver 0.15.3. The same model worked fine. So I think maybe ver 1.0.0 changed something and didn't mention it.
Author
Owner

@ccll commented on GitHub (Mar 6, 2025):

Same here with 1.0.0, and works as @TinyFatty says in 0.15.3

The model API works with curl and the returned streaming JSONL is correct.

@ccll commented on GitHub (Mar 6, 2025): Same here with 1.0.0, and works as @TinyFatty says in 0.15.3 The model API works with `curl` and the returned streaming JSONL is correct.
Author
Owner

@oiisongyu commented on GitHub (Mar 13, 2025):

Same here.
In the Dify version 1.0.0 and above, there is a new parameter named "API endpoint中的模型名称" in the openai-api-compatible configuration page. However, in version 0.15.3, this parameter doesn't exist, and the Q&A functionality works properly.

@oiisongyu commented on GitHub (Mar 13, 2025): Same here. In the Dify version 1.0.0 and above, there is a new parameter named "API endpoint中的模型名称" in the openai-api-compatible configuration page. However, in version 0.15.3, this parameter doesn't exist, and the Q&A functionality works properly.
Author
Owner

@zouxiaodong commented on GitHub (Mar 14, 2025):

same here

@zouxiaodong commented on GitHub (Mar 14, 2025): same here
Author
Owner

@westdata commented on GitHub (Mar 15, 2025):

same here

@westdata commented on GitHub (Mar 15, 2025): same here
Author
Owner

@zouxiaodong commented on GitHub (Mar 16, 2025):

same error after upgrading to version 1.0.1, model using ctyun xirang deepseek-r1 :https://www.ctyun.cn/act/xirang/deepseek

@zouxiaodong commented on GitHub (Mar 16, 2025): same error after upgrading to version 1.0.1, model using ctyun xirang deepseek-r1 :https://www.ctyun.cn/act/xirang/deepseek
Author
Owner

@Lamber-maybe commented on GitHub (Mar 17, 2025):

same here

@Lamber-maybe commented on GitHub (Mar 17, 2025): same here
Author
Owner

@zouxiaodong commented on GitHub (Mar 17, 2025):

Image

The root cause of the issue is that the data returned by Ctyun Xirang does not include a space after "data:". However, the source code currently assumes that there will be a space after "data:". To fix this, we can modify the source code to remove the dependency on the space after "data:", ensuring compatibility with the data format provided by Ctyun Xirang.

@zouxiaodong commented on GitHub (Mar 17, 2025): ![Image](https://github.com/user-attachments/assets/28e6c324-0c25-43d5-a47f-07181d90ec62) The root cause of the issue is that the data returned by Ctyun Xirang does not include a space after "data:". However, the source code currently assumes that there will be a space after "data:". To fix this, we can modify the source code to remove the dependency on the space after "data:", ensuring compatibility with the data format provided by Ctyun Xirang.
Author
Owner

@lastchiliarch commented on GitHub (Mar 20, 2025):

same problem. any progress?

@lastchiliarch commented on GitHub (Mar 20, 2025): same problem. any progress?
Author
Owner

@XiaoCC commented on GitHub (Mar 24, 2025):

Image

The root cause of the issue is that the data returned by Ctyun Xirang does not include a space after "data:". However, the source code currently assumes that there will be a space after "data:". To fix this, we can modify the source code to remove the dependency on the space after "data:", ensuring compatibility with the data format provided by Ctyun Xirang.

提交一个pr修复吧

@XiaoCC commented on GitHub (Mar 24, 2025): > ![Image](https://github.com/user-attachments/assets/28e6c324-0c25-43d5-a47f-07181d90ec62) > > The root cause of the issue is that the data returned by Ctyun Xirang does not include a space after "data:". However, the source code currently assumes that there will be a space after "data:". To fix this, we can modify the source code to remove the dependency on the space after "data:", ensuring compatibility with the data format provided by Ctyun Xirang. 提交一个pr修复吧
Author
Owner

@Aniwine commented on GitHub (Mar 25, 2025):

Image

The root cause of the issue is that the data returned by Ctyun Xirang does not include a space after "data:". However, the source code currently assumes that there will be a space after "data:". To fix this, we can modify the source code to remove the dependency on the space after "data:", ensuring compatibility with the data format provided by Ctyun Xirang.问题的根本原因是秋云西郎返回的数据在 “data:” 后面没有空格。但是,源代码当前假定 “data:” 后面会有一个空格。为了解决这个问题,我们可以修改源码,去掉对 “data:” 后面空格的依赖,保证与秋云西郎提供的数据格式兼容。

Hi, thanks for your solution, but where is the file?

@Aniwine commented on GitHub (Mar 25, 2025): > ![Image](https://github.com/user-attachments/assets/28e6c324-0c25-43d5-a47f-07181d90ec62) > > The root cause of the issue is that the data returned by Ctyun Xirang does not include a space after "data:". However, the source code currently assumes that there will be a space after "data:". To fix this, we can modify the source code to remove the dependency on the space after "data:", ensuring compatibility with the data format provided by Ctyun Xirang.问题的根本原因是秋云西郎返回的数据在 “data:” 后面没有空格。但是,源代码当前假定 “data:” 后面会有一个空格。为了解决这个问题,我们可以修改源码,去掉对 “data:” 后面空格的依赖,保证与秋云西郎提供的数据格式兼容。 Hi, thanks for your solution, but where is the file?
Author
Owner

@Aniwine commented on GitHub (Mar 26, 2025):

Image
The root cause of the issue is that the data returned by Ctyun Xirang does not include a space after "data:". However, the source code currently assumes that there will be a space after "data:". To fix this, we can modify the source code to remove the dependency on the space after "data:", ensuring compatibility with the data format provided by Ctyun Xirang.问题的根本原因是秋云西郎返回的数据在 “data:” 后面没有空格。但是,源代码当前假定 “data:” 后面会有一个空格。为了解决这个问题,我们可以修改源码,去掉对 “data:” 后面空格的依赖,保证与秋云西郎提供的数据格式兼容。

Hi, thanks for your solution, but where is the file?

I have already solved it by this method, in plugin-daemon's container,find the openai_compatible's llm.py of the package called dify-plugin,which located in langgenius/openai_api_compatible-0.0.11@410445eba2fa0f693d26dea2c3b9ffe51ad0777e021146ff877af6098412efc7/.venv/lib/python3.12/site-packages/dify_plugin/interfaces/model/openai_compatible/llm.py.Then modify it as above, it works for me!!

@Aniwine commented on GitHub (Mar 26, 2025): > > ![Image](https://github.com/user-attachments/assets/28e6c324-0c25-43d5-a47f-07181d90ec62) > > The root cause of the issue is that the data returned by Ctyun Xirang does not include a space after "data:". However, the source code currently assumes that there will be a space after "data:". To fix this, we can modify the source code to remove the dependency on the space after "data:", ensuring compatibility with the data format provided by Ctyun Xirang.问题的根本原因是秋云西郎返回的数据在 “data:” 后面没有空格。但是,源代码当前假定 “data:” 后面会有一个空格。为了解决这个问题,我们可以修改源码,去掉对 “data:” 后面空格的依赖,保证与秋云西郎提供的数据格式兼容。 > > Hi, thanks for your solution, but where is the file? I have already solved it by this method, in plugin-daemon's container,find the openai_compatible's llm.py of the package called dify-plugin,which located in langgenius/openai_api_compatible-0.0.11@410445eba2fa0f693d26dea2c3b9ffe51ad0777e021146ff877af6098412efc7/.venv/lib/python3.12/site-packages/dify_plugin/interfaces/model/openai_compatible/llm.py.Then modify it as above, it works for me!!
Author
Owner

@Osama-Faza commented on GitHub (Jun 15, 2025):

I'm facing this issue on the cloud Dify website, version 1.4.2.
Is there anything I can do to fix the problem from my end, or do I have to wait for a pull request to be made and merged?

@Osama-Faza commented on GitHub (Jun 15, 2025): I'm facing this issue on the cloud Dify website, version 1.4.2. Is there anything I can do to fix the problem from my end, or do I have to wait for a pull request to be made and merged?
Author
Owner

@dwdcth commented on GitHub (Jul 14, 2025):

Same here.
Please solve it

@dwdcth commented on GitHub (Jul 14, 2025): Same here. Please solve it
Author
Owner

@shun-qi commented on GitHub (Jul 22, 2025):

same here
please !!!!!

@shun-qi commented on GitHub (Jul 22, 2025): same here please !!!!!
Author
Owner

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

Hi, @TinyFatty. I'm Dosu, and I'm helping the dify-official-plugins team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported a "Non-JSON encountered." error with China Telecom OpenAI-API-compatible models on Dify v1.0.0, while v0.15.3 worked fine.
  • I identified the root cause as the source code assuming a space after "data:" in the returned data, which was not always present.
  • I found a workaround by modifying the llm.py file in the dify-plugin package to remove the space dependency.
  • Users on cloud versions like 1.4.2 also experienced this issue and are awaiting an official fix or PR.

Next Steps:

  • Please confirm if this issue is still relevant with the latest version of dify-official-plugins by commenting here.
  • If no further activity occurs, I will automatically close this issue in 5 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Aug 21, 2025): Hi, @TinyFatty. I'm [Dosu](https://dosu.dev), and I'm helping the dify-official-plugins team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported a "Non-JSON encountered." error with China Telecom OpenAI-API-compatible models on Dify v1.0.0, while v0.15.3 worked fine. - I identified the root cause as the source code assuming a space after "data:" in the returned data, which was not always present. - I found a workaround by modifying the llm.py file in the dify-plugin package to remove the space dependency. - Users on cloud versions like 1.4.2 also experienced this issue and are awaiting an official fix or PR. **Next Steps:** - Please confirm if this issue is still relevant with the latest version of dify-official-plugins by commenting here. - If no further activity occurs, I will automatically close this issue in 5 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-official-plugins#45