the api key does not change when modify external knowledge api #13691

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

Originally created by @zhangqinli123 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)

Steps to reproduce

when update the external api , it will call the http://x.x.x.x:x/console/api/datasets/external-knowledge-api/xxxxxxxxxxxxxxxx
with api_key [HIDDEN]

Image

In the code ' update_external_knowledge_api ', when api_key equals to HIDDEN_VALUE, it will get the value from settings_dict , which leads to the value will never change again!

if args.get("settings") and args.get("settings").get("api_key") == HIDDEN_VALUE:
args.get("settings")["api_key"] = external_knowledge_api.settings_dict.get("api_key")
Image

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @zhangqinli123 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) ### Steps to reproduce when update the external api , it will call the http://x.x.x.x:x/console/api/datasets/external-knowledge-api/xxxxxxxxxxxxxxxx with api_key [__HIDDEN__] ![Image](https://github.com/user-attachments/assets/335c04b0-1a9a-4d1a-a9a1-e0f96fe2ecf6) In the code ' update_external_knowledge_api ', when api_key equals to HIDDEN_VALUE, it will get the value from settings_dict , which leads to the value will never change again! if args.get("settings") and args.get("settings").get("api_key") == HIDDEN_VALUE: args.get("settings")["api_key"] = external_knowledge_api.settings_dict.get("api_key") ![Image](https://github.com/user-attachments/assets/080d4861-5ac9-460b-b612-7459a4b104a5) ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 19:13:24 -05:00
yindo closed this issue 2026-02-21 19:13:24 -05:00
Author
Owner

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

Hello @zhangqinli123! I'm Dosu, a bot here to help you with bugs, answer your questions, and assist you in becoming a contributor. I'm ready to help while you wait for a human maintainer. How can I assist you today?

The behavior you're observing is due to the way the update_external_knowledge_api function handles the api_key. When the api_key in the settings is set to HIDDEN_VALUE, the function retrieves the existing api_key from settings_dict and uses it instead of updating it with a new value. This is intended to preserve the existing API key when it is not explicitly changed by the user [1].

If you want to update the API key, you need to provide a new value for the api_key in the settings instead of using the HIDDEN_VALUE placeholder. This will ensure that the new API key is saved and the old one is replaced.

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): <!-- Greeting --> Hello @zhangqinli123! I'm [Dosu](https://dosu.dev), a bot here to help you with bugs, answer your questions, and assist you in becoming a contributor. I'm ready to help while you wait for a human maintainer. How can I assist you today? <!-- Answer --> The behavior you're observing is due to the way the `update_external_knowledge_api` function handles the `api_key`. When the `api_key` in the settings is set to `HIDDEN_VALUE`, the function retrieves the existing `api_key` from `settings_dict` and uses it instead of updating it with a new value. This is intended to preserve the existing API key when it is not explicitly changed by the user <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/services/external_knowledge_service.py)</sup>. If you want to update the API key, you need to provide a new value for the `api_key` in the settings instead of using the `HIDDEN_VALUE` placeholder. This will ensure that the new API key is saved and the old one is replaced. <!-- 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/d70da285-f956-47bc-9260-d6ff3115be1c?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/d70da285-f956-47bc-9260-d6ff3115be1c?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/d70da285-f956-47bc-9260-d6ff3115be1c?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/d70da285-f956-47bc-9260-d6ff3115be1c?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/d70da285-f956-47bc-9260-d6ff3115be1c?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/d70da285-f956-47bc-9260-d6ff3115be1c?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/d70da285-f956-47bc-9260-d6ff3115be1c?feedback_type=other)</sup>
Author
Owner

@zhangqinli123 commented on GitHub (May 8, 2025):

@dosu
I am not sure how to provide a new value for the api_key in the settings when modify the api on the front-end page. Could you give me more hints?

And if modifying the api_key on the front end is ineffective, is this prompt ambiguous?

Image

@zhangqinli123 commented on GitHub (May 8, 2025): @dosu I am not sure how to provide a new value for the api_key in the settings when modify the api on the front-end page. Could you give me more hints? And if modifying the api_key on the front end is ineffective, is this prompt ambiguous? ![Image](https://github.com/user-attachments/assets/df1e7e9b-90b3-4e5b-b625-d0ad159ddbb9)
Author
Owner

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

To provide a new value for the api_key in the settings when modifying the API on the front-end page, you can use the Field component to handle the input for the api_key. Here's a code snippet that demonstrates how to update the config.api_key state with the new value using the onChange event handler:

<Field
  label='API Key'
  labelClassName='!text-sm'
  isRequired
  value={config.api_key}
  onChange={handleConfigChange('api_key')}
  placeholder={t(`${I18N_PREFIX}.apiKeyPlaceholder`)!}
/>

This setup allows you to input a new value for the api_key and updates the config object with the new value. Make sure to implement the handleSave function to persist these changes. The handleSave function will ensure that the new api_key is saved correctly [1][2].

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 --> To provide a new value for the `api_key` in the settings when modifying the API on the front-end page, you can use the `Field` component to handle the input for the `api_key`. Here's a code snippet that demonstrates how to update the `config.api_key` state with the new value using the `onChange` event handler: ```tsx <Field label='API Key' labelClassName='!text-sm' isRequired value={config.api_key} onChange={handleConfigChange('api_key')} placeholder={t(`${I18N_PREFIX}.apiKeyPlaceholder`)!} /> ``` This setup allows you to input a new value for the `api_key` and updates the `config` object with the new value. Make sure to implement the `handleSave` function to persist these changes. The `handleSave` function will ensure that the new `api_key` is saved correctly <sup>[[1]](https://github.com/langgenius/dify/blob/main/web/app/components/tools/edit-custom-collection-modal/config-credentials.tsx)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/web/app/components/header/account-setting/data-source-page/data-source-website/config-firecrawl-modal.tsx)</sup>. <!-- 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/20a4ce22-62c3-4c9d-8749-c8818299af88?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/20a4ce22-62c3-4c9d-8749-c8818299af88?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/20a4ce22-62c3-4c9d-8749-c8818299af88?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/20a4ce22-62c3-4c9d-8749-c8818299af88?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/20a4ce22-62c3-4c9d-8749-c8818299af88?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/20a4ce22-62c3-4c9d-8749-c8818299af88?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/20a4ce22-62c3-4c9d-8749-c8818299af88?feedback_type=other)</sup>
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#13691