Cannot add OpenAi key #8893

Closed
opened 2026-02-21 18:28:28 -05:00 by yindo · 2 comments
Owner

Originally created by @gaiyaa on GitHub (Mar 3, 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.0.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

When I added the OpenAi key through the OpenAi plugin, I got an error.

✔️ Expected Behavior

No response

Actual Behavior

http://127.0.0.1/console/api/workspaces/current/model-providers/langgenius/openai/openai

{"code": "invalid_param", "message": "Connection error.", "status": 400}

Traceback (most recent call last):
  File "/app/api/controllers/console/workspace/models.py", line 154, in post
    model_provider_service.save_model_credentials(
  File "/app/api/services/model_provider_service.py", line 237, in save_model_credentials
    provider_configuration.add_or_update_custom_model_credentials(
  File "/app/api/core/entities/provider_configuration.py", line 406, in add_or_update_custom_model_credentials
    provider_model_record, credentials = self.custom_model_credentials_validate(model_type, model, credentials)
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/entities/provider_configuration.py", line 386, in custom_model_credentials_validate
    credentials = model_provider_factory.model_credentials_validate(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/model_runtime/model_providers/model_provider_factory.py", line 190, in model_credentials_validate
    self.plugin_model_manager.validate_model_credentials(
  File "/app/api/core/plugin/manager/model.py", line 137, in validate_model_credentials
    for resp in response:
                ^^^^^^^^
  File "/app/api/core/plugin/manager/base.py", line 189, in _request_with_plugin_daemon_response_stream
    self._handle_plugin_daemon_error(error.error_type, error.message)
  File "/app/api/core/plugin/manager/base.py", line 219, in _handle_plugin_daemon_error
    raise CredentialsValidateFailedError(error_object.get("message"))
core.model_runtime.errors.validate.CredentialsValidateFailedError: Connection error.

Originally created by @gaiyaa on GitHub (Mar 3, 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.0.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce When I added the OpenAi key through the OpenAi plugin, I got an error. ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior > http://127.0.0.1/console/api/workspaces/current/model-providers/langgenius/openai/openai `{"code": "invalid_param", "message": "Connection error.", "status": 400}` ``` Traceback (most recent call last): File "/app/api/controllers/console/workspace/models.py", line 154, in post model_provider_service.save_model_credentials( File "/app/api/services/model_provider_service.py", line 237, in save_model_credentials provider_configuration.add_or_update_custom_model_credentials( File "/app/api/core/entities/provider_configuration.py", line 406, in add_or_update_custom_model_credentials provider_model_record, credentials = self.custom_model_credentials_validate(model_type, model, credentials) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/entities/provider_configuration.py", line 386, in custom_model_credentials_validate credentials = model_provider_factory.model_credentials_validate( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/model_runtime/model_providers/model_provider_factory.py", line 190, in model_credentials_validate self.plugin_model_manager.validate_model_credentials( File "/app/api/core/plugin/manager/model.py", line 137, in validate_model_credentials for resp in response: ^^^^^^^^ File "/app/api/core/plugin/manager/base.py", line 189, in _request_with_plugin_daemon_response_stream self._handle_plugin_daemon_error(error.error_type, error.message) File "/app/api/core/plugin/manager/base.py", line 219, in _handle_plugin_daemon_error raise CredentialsValidateFailedError(error_object.get("message")) core.model_runtime.errors.validate.CredentialsValidateFailedError: Connection error. ```
yindo added the 🐞 bug label 2026-02-21 18:28:28 -05:00
yindo closed this issue 2026-02-21 18:28:28 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 3, 2025):

Hey @gaiyaa! I'm here to help you with any bugs, questions, or contributions for Dify. Let's get this issue sorted out together!

I found a similar issue related to the "Connection error" when adding the OpenAI key in a self-hosted Dify setup using Docker. The solution involves adjusting the configuration to ensure proper network access:

  1. Replace 127.0.0.1 with host.docker.internal in your configuration. The full URL should be http://host.docker.internal:10000/v1/chat/completions. This change is necessary because localhost refers to the container itself, and host.docker.internal allows access to the Docker host [1].

  2. Ensure you provide a valid API key in the credentials.api_key field instead of leaving it empty.

  3. Verify that your system has network connectivity to reach the specified endpoint_url. Make sure the endpoint_url is correct and accessible.

  4. If you have system proxy environment variables set, you may need to unset them using:

    unset HTTP_PROXY
    unset HTTPS_PROXY
    

These steps should help resolve the connection error by ensuring proper configuration and network accessibility.

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 (Mar 3, 2025): <!-- Greeting --> Hey @gaiyaa! I'm here to help you with any bugs, questions, or contributions for Dify. Let's get this issue sorted out together! <!-- Answer --> I found a similar issue related to the "Connection error" when adding the OpenAI key in a self-hosted Dify setup using Docker. The solution involves adjusting the configuration to ensure proper network access: 1. Replace `127.0.0.1` with `host.docker.internal` in your configuration. The full URL should be `http://host.docker.internal:10000/v1/chat/completions`. This change is necessary because `localhost` refers to the container itself, and `host.docker.internal` allows access to the Docker host <sup>[[1]](https://github.com/langgenius/dify/issues/14011)</sup>. 2. Ensure you provide a valid API key in the `credentials.api_key` field instead of leaving it empty. 3. Verify that your system has network connectivity to reach the specified `endpoint_url`. Make sure the `endpoint_url` is correct and accessible. 4. If you have system proxy environment variables set, you may need to unset them using: ```bash unset HTTP_PROXY unset HTTPS_PROXY ``` These steps should help resolve the connection error by ensuring proper configuration and network accessibility. <!-- 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/5e13ffa9-df12-4bed-8413-9748fafc443b?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/5e13ffa9-df12-4bed-8413-9748fafc443b?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/5e13ffa9-df12-4bed-8413-9748fafc443b?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/5e13ffa9-df12-4bed-8413-9748fafc443b?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/5e13ffa9-df12-4bed-8413-9748fafc443b?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/5e13ffa9-df12-4bed-8413-9748fafc443b?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/5e13ffa9-df12-4bed-8413-9748fafc443b?feedback_type=other)</sup>
Author
Owner

@crazywoola commented on GitHub (Mar 3, 2025):

Please ensure you can access this service correctly, and this should use official OpenAI key.

@crazywoola commented on GitHub (Mar 3, 2025): Please ensure you can access this service correctly, and this should use official OpenAI key.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#8893