tongyi raise InvalidApiKey when attempting to use international endpoint and fail #855

Closed
opened 2026-02-16 10:20:44 -05:00 by yindo · 1 comment
Owner

Originally created by @Kylin0123 on GitHub (Dec 5, 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.3.0

Plugin version

0.1.3

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

We encountered a bug using the latest version of Tongyi: if a user configures a DashScope key for the China site but enables the international site endpoint, it forces all base_http_url instances within the Tongyi plugin process to be set to the international site endpoint, making it impossible to switch back to the China site endpoint. Due to the lack of interoperability between the two DashScope sites, the plugin continuously reports "InvalidApiKey" errors until the plugin daemon process is manually restarted. We found that the code globally overrides the base_url for the entire DashScope SDK module, which needs to be fixed.

Tongyi plugin raise error:
Image

The code of root case:
Image

Tongyi official doc:
https://help.aliyun.com/zh/model-studio/error-code?scm=20140722.S_help%40%40%E6%96%87%E6%A1%A3%40%402712216._.ID_help%40%40%E6%96%87%E6%A1%A3%40%402712216-RL_401-LOC_doc%7EUND%7Eab-OR_ser-PAR1_212a5d4017649278824978378d24bd-V_4-PAR3_o-RE_new5-P0_1-P1_0&spm=a2c4g.11186623.help-search.i1#:~:text=%E5%8F%91%E8%B5%B7%E8%B0%83%E7%94%A8%E3%80%82-,401%2DNOT%20AUTHORIZED,-Access%20denied%3A%20Either

✔️ Error log

No response

Originally created by @Kylin0123 on GitHub (Dec 5, 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.3.0 ### Plugin version 0.1.3 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce We encountered a bug using the latest version of Tongyi: if a user configures a DashScope key for the China site but enables the international site endpoint, it forces all base_http_url instances within the Tongyi plugin process to be set to the international site endpoint, making it impossible to switch back to the China site endpoint. Due to the lack of interoperability between the two DashScope sites, the plugin continuously reports "InvalidApiKey" errors until the plugin daemon process is manually restarted. We found that the code globally overrides the base_url for the entire DashScope SDK module, which needs to be fixed. Tongyi plugin raise error: <img width="518" height="686" alt="Image" src="https://github.com/user-attachments/assets/9e4e73ed-2fc2-4b4b-b96e-cb0a0f206d74" /> The code of root case: <img width="1086" height="539" alt="Image" src="https://github.com/user-attachments/assets/022b5c66-43e9-4e9a-ab4d-a0c2aae8f8d8" /> Tongyi official doc: https://help.aliyun.com/zh/model-studio/error-code?scm=20140722.S_help%40%40%E6%96%87%E6%A1%A3%40%402712216._.ID_help%40%40%E6%96%87%E6%A1%A3%40%402712216-RL_401-LOC_doc%7EUND%7Eab-OR_ser-PAR1_212a5d4017649278824978378d24bd-V_4-PAR3_o-RE_new5-P0_1-P1_0&spm=a2c4g.11186623.help-search.i1#:~:text=%E5%8F%91%E8%B5%B7%E8%B0%83%E7%94%A8%E3%80%82-,401%2DNOT%20AUTHORIZED,-Access%20denied%3A%20Either ### ✔️ Error log _No response_
yindo added the bug label 2026-02-16 10:20:44 -05:00
yindo closed this issue 2026-02-16 10:20:44 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Dec 5, 2025):

Hi @Kylin0123! I'm Dosu and I’m helping the dify-official-plugins team.

This is a confirmed bug in the Tongyi plugin: when you enable the international endpoint, the code globally overrides the DashScope SDK's base_http_api_url for the entire process. This means all subsequent API calls use the international endpoint, and you can't switch back to the China endpoint without restarting the plugin process. Since DashScope API keys are not interoperable between China and international endpoints, this causes persistent InvalidApiKey errors if the endpoint and key don't match. The same global override happens for the API key itself, so both are shared across all plugin invocations in the process. There is currently no per-request or per-instance configuration for these settings in the plugin code, so the only reliable workaround is to restart the plugin process after changing the endpoint configuration. This matches the root cause described in the code and is confirmed by multiple user reports and maintainer comments (source, source, source).

The official Tongyi documentation for error codes confirms that a 401 error (InvalidApiKey) means the API key and endpoint do not match or the key is not authorized for the endpoint you are using (doc link).

There is no documented fix or workaround other than restarting the process after changing endpoints. Refactoring the plugin to support per-request or per-instance endpoint configuration would be needed to fully resolve this.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Dec 5, 2025): <!-- Greeting --> Hi @Kylin0123! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the dify-official-plugins team. <!-- Answer --> This is a confirmed bug in the Tongyi plugin: when you enable the international endpoint, the code globally overrides the DashScope SDK's `base_http_api_url` for the entire process. This means all subsequent API calls use the international endpoint, and you can't switch back to the China endpoint without restarting the plugin process. Since DashScope API keys are not interoperable between China and international endpoints, this causes persistent `InvalidApiKey` errors if the endpoint and key don't match. The same global override happens for the API key itself, so both are shared across all plugin invocations in the process. There is currently no per-request or per-instance configuration for these settings in the plugin code, so the only reliable workaround is to restart the plugin process after changing the endpoint configuration. This matches the root cause described in the code and is confirmed by multiple user reports and maintainer comments ([source](https://github.com/langgenius/dify-official-plugins/blob/2f7b43a664042ad311bf848c41fd924f67121738/models/tongyi/models/llm/llm.py#L182-L757), [source](https://github.com/langgenius/dify-official-plugins/issues/1287), [source](https://github.com/langgenius/dify-official-plugins/issues/1399)). The official Tongyi documentation for error codes confirms that a 401 error (`InvalidApiKey`) means the API key and endpoint do not match or the key is not authorized for the endpoint you are using ([doc link](https://help.aliyun.com/zh/model-studio/error-code?scm=20140722.S_help%40%40%E6%96%87%E6%A1%A3%40%402712216._.ID_help%40%40%E6%96%87%E6%A1%A3%40%402712216-RL_401-LOC_doc%7EUND%7Eab-OR_ser-PAR1_212a5d4017649278824978378d24bd-V_4-PAR3_o-RE_new5-P0_1-P1_0&spm=a2c4g.11186623.help-search.i1#:~:text=%E5%8F%91%E8%B5%B7%E8%B0%83%E7%94%A8%E3%80%82-,401%2DNOT%20AUTHORIZED,-Access%20denied%3A%20Either)). There is no documented fix or workaround other than restarting the process after changing endpoints. Refactoring the plugin to support per-request or per-instance endpoint configuration would be needed to fully resolve this. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/4f3f6eed-13ea-42f9-9573-99ab8f10f9e5?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/4f3f6eed-13ea-42f9-9573-99ab8f10f9e5?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/4f3f6eed-13ea-42f9-9573-99ab8f10f9e5?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/4f3f6eed-13ea-42f9-9573-99ab8f10f9e5?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/4f3f6eed-13ea-42f9-9573-99ab8f10f9e5?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/4f3f6eed-13ea-42f9-9573-99ab8f10f9e5?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/4f3f6eed-13ea-42f9-9573-99ab8f10f9e5?feedback_type=other)</sup> [![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20confirmed%20bug%20in%20the%20Tongyi%20plugin%3A%20when%20you%20enable%20the%20international%20endpoint%2C%20the%20code%20globally%20overrides%20the%20DashScope%20SDK%27s%20%60base_http_api_url%60%20for%20the%20entire%20process.%20This%20means%20all%20subsequent%20API%20calls%20use%20the%20international%20endpoint%2C%20and%20you%20can%27t%20switch%20back%20to%20the%20China%20endpoint%20without%20restarting%20the%20plugin%20process.%20Since%20DashScope%20API%20keys%20are%20not%20interoperable%20between%20China%20and%20international%20endpoints%2C%20this%20causes%20persistent%20%60InvalidApiKey%60%20errors%20if%20the%20endpoint%20and%20key%20don%27t%20match.%20The%20same%20global%20override%20happens%20for%20the%20API%20key%20itself%2C%20so%20both%20are%20shared%20across%20all%20plugin%20invocations%20in%20the%20process.%20There%20is%20currently%20no%20per-request%20or%20per-instance%20configuration%20for%20these%20settings%20in%20the%20plugin%20code%2C%20so%20the%20only%20reliable%20workaround%20is%20to%20restart%20the%20plugin%20process%20after%20changing%20the%20endpoint%20configuration.%20This%20matches%20the%20root%20cause%20described%20in%20the%20code%20and%20is%20confirmed%20by%20multiple%20user%20reports%20and%20maintainer%20comments%20%28%5Bsource%5D%28https%3A//github.com/langgenius/dify-official-plugins/blob/2f7b43a664042ad311bf848c41fd924f67121738/models/tongyi/models/llm/llm.py%23L182-L757%29%2C%20%5Bsource%5D%28https%3A//github.com/langgenius/dify-official-plugins/issues/1287%29%2C%20%5Bsource%5D%28https%3A//github.com/langgenius/dify-official-plugins/issues/1399%29%29.%20%0A%0AThe%20official%20Tongyi%20documentation%20for%20error%20codes%20confirms%20that%20a%20401%20error%20%28%60InvalidApiKey%60%29%20means%20the%20API%20key%20and%20endpoint%20do%20not%20match%20or%20the%20key%20is%20not%20authorized%20for%20the%20endpoint%20you%20are%20using%20%28%5Bdoc%20link%5D%28https%3A//help.aliyun.com/zh/model-studio/error-code%3Fscm%3D20140722.S_help%2540%2540%25E6%2596%2587%25E6%25A1%25A3%2540%25402712216._.ID_help%2540%2540%25E6%2596%2587%25E6%25A1%25A3%2540%25402712216-RL_401-LOC_doc%257EUND%257Eab-OR_ser-PAR1_212a5d4017649278824978378d24bd-V_4-PAR3_o-RE_new5-P0_1-P1_0%26spm%3Da2c4g.11186623.help-search.i1%23%3A~%3Atext%3D%25E5%258F%2591%25E8%25B5%25B7%25E8%25B0%2583%25E7%2594%25A8%25E3%2580%2582-%2C401%252DNOT%2520AUTHORIZED%2C-Access%2520denied%253A%2520Either%29%29.%0A%0AThere%20is%20no%20documented%20fix%20or%20workaround%20other%20than%20restarting%20the%20process%20after%20changing%20endpoints.%20Refactoring%20the%20plugin%20to%20support%20per-request%20or%20per-instance%20endpoint%20configuration%20would%20be%20needed%20to%20fully%20resolve%20this.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify-official-plugins/issues/2182)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-official-plugins#855