Run failed: [openai_api_compatible] Error: PluginInvokeError: {"args":{},"error_type":"KeyError","message":"'choices'"} #262

Closed
opened 2026-02-16 10:18:39 -05:00 by yindo · 3 comments
Owner

Originally created by @Kevinhuhu on GitHub (May 8, 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 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.3.1

Cloud or Self Hosted

Self Hosted (Docker), Cloud

Steps to reproduce

After updating to version 1.3.1, using the openai_api_compatible plugin to call OpenAI API-compatible endpoints results in errors. This worked properly before version 1.3.1. The same error persists even when trying other OpenAI API-compatible endpoints.
Error details:
Run failed: [openai_api_compatible] Error: PluginInvokeError: {"args":{},"error_type":"KeyError","message":"'choices'"}

✔️ Expected Behavior

Expected to return properly.

Actual Behavior

Run failed: [openai_api_compatible] Error: PluginInvokeError: {"args":{},"error_type":"KeyError","message":"'choices'"}

but use other tool(like postman),the api return like:
{
"id": "my_chatId",
"model": "",
"usage": {
"prompt_tokens": 1,
"completion_tokens": 1,
"total_tokens": 1
},
"choices": [
{
"message": {
"role": "assistant",
"content": "\n# 抖音会员通功能详解\n\n抖音会员通是系统与抖音平台深度整合的会员管理解决方案,帮助商家实现抖音流量到私域会员的高效转化。\n\n## 主要功能亮点\n\n1. 会员体系双向打通\n - 自动同步抖音会员到银豹系统\n - 会员数据实时更新\n\n2. 智能会员管理\n - 自动识别新老会员\n - 支持自定义会员标签\n - 会员消费行为追踪\n\n3. 营销工具整合\n - 会员专享商品设置\n - 精准营销活动推送\n - 团购券核销一体化\n\n## 典型应用场景\n\n1. 会员获取\n - 设置"会员专享品",吸引用户入会\n - 非会员需先入会才能购买特定商品\n\n2. 会员运营\n - 根据消费行为进行会员分层\n - 推送个性化营销活动\n - 提升复购率和客单价\n\n3. 数据洞察\n - 分析会员消费偏好\n - 优化商品结构和营销策略\n\n## 开通流程\n\n1. 联系抖音BD开通会员通服务\n2. 在银豹后台完成配置:\n - 路径:营销 > 抖音团购 > 会员通\n - 设置自动打标规则\n - 配置会员专享商品\n\n## 成功案例\n\n某品牌使用后效果:\n- 单周GMV突破4万元\n- 2周新增会员3000+\n- 会员复购率提升35%\n\n如需详细了解配置方法,可参考[官方接入指南]。"
},
"finish_reason": "stop",
"index": 0
}
]
}

Originally created by @Kevinhuhu on GitHub (May 8, 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 [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.3.1 ### Cloud or Self Hosted Self Hosted (Docker), Cloud ### Steps to reproduce After updating to version 1.3.1, using the openai_api_compatible plugin to call OpenAI API-compatible endpoints results in errors. This worked properly before version 1.3.1. The same error persists even when trying other OpenAI API-compatible endpoints. Error details: Run failed: [openai_api_compatible] Error: PluginInvokeError: {"args":{},"error_type":"KeyError","message":"'choices'"} ### ✔️ Expected Behavior Expected to return properly. ### ❌ Actual Behavior Run failed: [openai_api_compatible] Error: PluginInvokeError: {"args":{},"error_type":"KeyError","message":"'choices'"} but use other tool(like postman),the api return like: { "id": "my_chatId", "model": "", "usage": { "prompt_tokens": 1, "completion_tokens": 1, "total_tokens": 1 }, "choices": [ { "message": { "role": "assistant", "content": "\n# 抖音会员通功能详解\n\n抖音会员通是系统与抖音平台深度整合的会员管理解决方案,帮助商家实现抖音流量到私域会员的高效转化。\n\n## 主要功能亮点\n\n1. **会员体系双向打通**\n - 自动同步抖音会员到银豹系统\n - 会员数据实时更新\n\n2. **智能会员管理**\n - 自动识别新老会员\n - 支持自定义会员标签\n - 会员消费行为追踪\n\n3. **营销工具整合**\n - 会员专享商品设置\n - 精准营销活动推送\n - 团购券核销一体化\n\n## 典型应用场景\n\n1. **会员获取**\n - 设置\"会员专享品\",吸引用户入会\n - 非会员需先入会才能购买特定商品\n\n2. **会员运营**\n - 根据消费行为进行会员分层\n - 推送个性化营销活动\n - 提升复购率和客单价\n\n3. **数据洞察**\n - 分析会员消费偏好\n - 优化商品结构和营销策略\n\n## 开通流程\n\n1. 联系抖音BD开通会员通服务\n2. 在银豹后台完成配置:\n - 路径:营销 > 抖音团购 > 会员通\n - 设置自动打标规则\n - 配置会员专享商品\n\n## 成功案例\n\n某品牌使用后效果:\n- 单周GMV突破4万元\n- 2周新增会员3000+\n- 会员复购率提升35%\n\n如需详细了解配置方法,可参考[官方接入指南]。" }, "finish_reason": "stop", "index": 0 } ] }
yindo closed this issue 2026-02-16 10:18:39 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (May 8, 2025):

The KeyError related to the 'choices' field in the openai_api_compatible plugin suggests that the plugin is attempting to access the 'choices' field in the API response, but it is not finding it. This issue might be due to changes in how the plugin processes API responses in version 1.3.1.

To handle this, ensure that the plugin is correctly configured to parse the API response structure. The openai_api_compatible plugin should expect a response structure that includes a choices field, which is a list of ChatCompletionChoice objects. Each object should contain a message with content and other attributes [1].

Here are a few steps you can take to troubleshoot and resolve the issue:

  1. Verify Response Structure: Ensure that the API response from the OpenAI API-compatible endpoint includes the choices field as expected. The response should match the structure you provided in your example.

  2. Check Plugin Configuration: Review the plugin's configuration to ensure it is set up to handle the expected response format. This includes verifying any recent changes in the plugin's code that might affect how it processes the choices field.

  3. Error Handling: Consider implementing error handling in the plugin to gracefully manage cases where the choices field might be missing or malformed. This can prevent KeyError exceptions from disrupting the plugin's operation.

  4. Review Recent Changes: If the issue arose after updating to version 1.3.1, review the release notes or change logs for any modifications that might affect the plugin's behavior.

If these steps do not resolve the issue, you may need to investigate further into the plugin's code or consult with the development team for more specific guidance.

To continue talking to Dosu, mention @dosu.


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

@dosubot[bot] commented on GitHub (May 8, 2025): <!-- Answer --> The `KeyError` related to the `'choices'` field in the `openai_api_compatible` plugin suggests that the plugin is attempting to access the `'choices'` field in the API response, but it is not finding it. This issue might be due to changes in how the plugin processes API responses in version 1.3.1. To handle this, ensure that the plugin is correctly configured to parse the API response structure. The `openai_api_compatible` plugin should expect a response structure that includes a `choices` field, which is a list of `ChatCompletionChoice` objects. Each object should contain a `message` with content and other attributes <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/tests/integration_tests/model_runtime/__mock/openai_chat.py)</sup>. Here are a few steps you can take to troubleshoot and resolve the issue: 1. **Verify Response Structure**: Ensure that the API response from the OpenAI API-compatible endpoint includes the `choices` field as expected. The response should match the structure you provided in your example. 2. **Check Plugin Configuration**: Review the plugin's configuration to ensure it is set up to handle the expected response format. This includes verifying any recent changes in the plugin's code that might affect how it processes the `choices` field. 3. **Error Handling**: Consider implementing error handling in the plugin to gracefully manage cases where the `choices` field might be missing or malformed. This can prevent `KeyError` exceptions from disrupting the plugin's operation. 4. **Review Recent Changes**: If the issue arose after updating to version 1.3.1, review the release notes or change logs for any modifications that might affect the plugin's behavior. If these steps do not resolve the issue, you may need to investigate further into the plugin's code or consult with the development team for more specific guidance. <!-- 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/30fca7a3-209a-4f04-8401-38af59fb247d?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/30fca7a3-209a-4f04-8401-38af59fb247d?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/30fca7a3-209a-4f04-8401-38af59fb247d?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/30fca7a3-209a-4f04-8401-38af59fb247d?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/30fca7a3-209a-4f04-8401-38af59fb247d?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/30fca7a3-209a-4f04-8401-38af59fb247d?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/30fca7a3-209a-4f04-8401-38af59fb247d?feedback_type=other)</sup>
Author
Owner

@Kevinhuhu commented on GitHub (May 9, 2025):

It appears to be an issue with streaming output. Can the openai_api_compatible support a parameter to disable streaming output? Previous versions seemed to default to non-streaming output.

@Kevinhuhu commented on GitHub (May 9, 2025): It appears to be an issue with streaming output. Can the openai_api_compatible support a parameter to disable streaming output? Previous versions seemed to default to non-streaming output.
Author
Owner

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

Hi, @Kevinhuhu. 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 KeyError for the 'choices' field in the openai_api_compatible plugin after updating to version 1.3.1.
  • The error occurs despite the API response including 'choices', and seems related to streaming output mode.
  • Previous versions defaulted to non-streaming; you requested a parameter to disable streaming in the plugin.
  • A contributor suggested verifying response structure, plugin configuration, and adding error handling for missing 'choices'.
  • The issue remains unresolved and may require further investigation or a plugin update to handle streaming mode properly.

Next Steps:

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

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Aug 18, 2025): Hi, @Kevinhuhu. 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 KeyError for the 'choices' field in the openai_api_compatible plugin after updating to version 1.3.1. - The error occurs despite the API response including 'choices', and seems related to streaming output mode. - Previous versions defaulted to non-streaming; you requested a parameter to disable streaming in the plugin. - A contributor suggested verifying response structure, plugin configuration, and adding error handling for missing 'choices'. - The issue remains unresolved and may require further investigation or a plugin update to handle streaming mode properly. **Next Steps:** - Please confirm if this issue is still relevant with the latest version of the dify-official-plugins repository by commenting here. - If no response is received, 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#262