The OPENAI configuration is incorrect #4060

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

Originally created by @liuyuf on GitHub (Jun 12, 2024).

Originally assigned to: @laipz8200 on GitHub.

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).
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.10

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

curl 'http://localhost/console/api/workspaces/current/model-providers/openai'
-H 'Accept: /'
-H 'Accept-Language: zh-CN,zh;q=0.9'
-H 'Connection: keep-alive'
-H 'Cookie: locale=zh-Hans'
-H 'Origin: http://localhost'
-H 'Referer: http://localhost/apps'
-H 'Sec-Fetch-Dest: empty'
-H 'Sec-Fetch-Mode: cors'
-H 'Sec-Fetch-Site: same-origin'
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
-H 'authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYzRjZTFmMmUtOTMxYi00N2JhLTg0Y2ItNjQ2MTEzYjI4NjNhIiwiZXhwIjoxNzIwODQxMDY2LCJpc3MiOiJTRUxGX0hPU1RFRCIsInN1YiI6IkNvbnNvbGUgQVBJIFBhc3Nwb3J0In0.gtYAzHMV1O3fg-lGRigxpU9cJdtGSGQaQP0hwwdo5gY'
-H 'content-type: application/json'
-H 'sec-ch-ua: "Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"'
-H 'sec-ch-ua-mobile: ?0'
-H 'sec-ch-ua-platform: "macOS"'
--data-raw '{"config_from":"predefined-model","credentials":{"openai_api_key":"sk-3AhfADoAZj3MrnNwhGDIS9IiodFFE24***********","openai_api_base":"https://api.fe8.****"},"load_balancing":{"enabled":false,"configs":[]}}'

The openai_api_key and openai_api_base shown here are encrypted, and the actual openai_api_key and openai_api_base are available in the actual project

✔️ Expected Behavior

No response

Actual Behavior

api return:
{
"code": "invalid_param",
"message": "Error code: 404 - {'message': ''}",
"status": 400
}

Originally created by @liuyuf on GitHub (Jun 12, 2024). Originally assigned to: @laipz8200 on GitHub. ### 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] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.6.10 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce curl 'http://localhost/console/api/workspaces/current/model-providers/openai' \ -H 'Accept: */*' \ -H 'Accept-Language: zh-CN,zh;q=0.9' \ -H 'Connection: keep-alive' \ -H 'Cookie: locale=zh-Hans' \ -H 'Origin: http://localhost' \ -H 'Referer: http://localhost/apps' \ -H 'Sec-Fetch-Dest: empty' \ -H 'Sec-Fetch-Mode: cors' \ -H 'Sec-Fetch-Site: same-origin' \ -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' \ -H 'authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYzRjZTFmMmUtOTMxYi00N2JhLTg0Y2ItNjQ2MTEzYjI4NjNhIiwiZXhwIjoxNzIwODQxMDY2LCJpc3MiOiJTRUxGX0hPU1RFRCIsInN1YiI6IkNvbnNvbGUgQVBJIFBhc3Nwb3J0In0.gtYAzHMV1O3fg-lGRigxpU9cJdtGSGQaQP0hwwdo5gY' \ -H 'content-type: application/json' \ -H 'sec-ch-ua: "Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"' \ -H 'sec-ch-ua-mobile: ?0' \ -H 'sec-ch-ua-platform: "macOS"' \ --data-raw '{"config_from":"predefined-model","credentials":{"openai_api_key":"sk-3AhfADoAZj3MrnNwhGDIS9IiodFFE24***********","openai_api_base":"https://api.fe8.****"},"load_balancing":{"enabled":false,"configs":[]}}' The openai_api_key and openai_api_base shown here are encrypted, and the actual openai_api_key and openai_api_base are available in the actual project ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior api return: { "code": "invalid_param", "message": "Error code: 404 - {'message': ''}", "status": 400 }
yindo added the 🐞 bug label 2026-02-21 18:04:35 -05:00
yindo closed this issue 2026-02-21 18:04:36 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 13, 2024):

@liuyuf 🌟 Hello there! I'm here to help you with any bugs, questions, or contributions you might have for the project. Let me know how I can assist you!

To resolve the 404 error when configuring the OpenAI model provider in your self-hosted Dify version 0.6.10 setup using Docker, ensure that the openai_api_base URL is correctly set and does not end with a trailing slash. The _to_credential_kwargs method in the provided code snippet trims any trailing slash from the openai_api_base and appends /v1 to it.

Here is the relevant part of the code:

if credentials.get('openai_api_base'):
    credentials['openai_api_base'] = credentials['openai_api_base'].rstrip('/')
    credentials_kwargs['base_url'] = credentials['openai_api_base'] + '/v1'

Make sure your openai_api_base is correctly configured without a trailing slash. For example, if your base URL is https://api.openai.com, it should be set exactly as https://api.openai.com and not https://api.openai.com/.

Additionally, verify that the endpoint /v1 is correct and accessible. According to the openai.yaml configuration file, the openai_api_base should be set to the base URL, e.g., https://api.openai.com.

Here is the relevant part of the openai.yaml configuration:

- variable: openai_api_base
  label:
    zh_Hans: API Base
    en_US: API Base
  type: text-input
  required: false
  placeholder:
    zh_Hans: 在此输入您的 API Base, 如:https://api.openai.com
    en_US: Enter your API Base, e.g. https://api.openai.com

Ensure that the openai_api_base is correctly set to https://api.openai.com or the appropriate base URL for your setup.

For further details on configuring model providers in Dify, refer to the Model Configuration documentation [1][2][3][4].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jun 13, 2024): <!-- Greeting --> @liuyuf 🌟 Hello there! I'm here to help you with any bugs, questions, or contributions you might have for the project. Let me know how I can assist you! <!-- Answer --> To resolve the 404 error when configuring the OpenAI model provider in your self-hosted Dify version 0.6.10 setup using Docker, ensure that the `openai_api_base` URL is correctly set and does not end with a trailing slash. The `_to_credential_kwargs` method in the provided code snippet trims any trailing slash from the `openai_api_base` and appends `/v1` to it. Here is the relevant part of the code: ```python if credentials.get('openai_api_base'): credentials['openai_api_base'] = credentials['openai_api_base'].rstrip('/') credentials_kwargs['base_url'] = credentials['openai_api_base'] + '/v1' ``` Make sure your `openai_api_base` is correctly configured without a trailing slash. For example, if your base URL is `https://api.openai.com`, it should be set exactly as `https://api.openai.com` and not `https://api.openai.com/`. Additionally, verify that the endpoint `/v1` is correct and accessible. According to the `openai.yaml` configuration file, the `openai_api_base` should be set to the base URL, e.g., `https://api.openai.com`. Here is the relevant part of the `openai.yaml` configuration: ```yaml - variable: openai_api_base label: zh_Hans: API Base en_US: API Base type: text-input required: false placeholder: zh_Hans: 在此输入您的 API Base, 如:https://api.openai.com en_US: Enter your API Base, e.g. https://api.openai.com ``` Ensure that the `openai_api_base` is correctly set to `https://api.openai.com` or the appropriate base URL for your setup. For further details on configuring model providers in Dify, refer to the [Model Configuration documentation](https://docs.dify.ai/tutorials/model-configuration/README.md) <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/openai/_common.py)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/openai_api_compatible/openai_api_compatible.yaml)</sup><sup>[[3]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/openai/openai.yaml)</sup><sup>[[4]](https://github.com/langgenius/dify-docs/blob/main/en/tutorials/model-configuration/README.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@laipz8200 commented on GitHub (Jun 24, 2024):

It looks like you're directly using our backend API. We haven't found any bugs related to setting the OpenAI API Key, so I'm going to close this issue. If you still have problems, you can provide more details and reopen it.

@laipz8200 commented on GitHub (Jun 24, 2024): It looks like you're directly using our backend API. We haven't found any bugs related to setting the OpenAI API Key, so I'm going to close this issue. If you still have problems, you can provide more details and reopen it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4060