mirror of
https://github.com/langgenius/dify-official-plugins.git
synced 2026-07-21 17:45:23 -04:00
tongyi raise InvalidApiKey when attempting to use international endpoint and fail #855
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Kylin0123 on GitHub (Dec 5, 2025).
Self Checks
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:

The code of root case:

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
@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_urlfor 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 persistentInvalidApiKeyerrors 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