Credentials validation failed with status code 404 #4474

Closed
opened 2026-02-21 18:06:41 -05:00 by yindo · 1 comment
Owner

Originally created by @leowang9527 on GitHub (Jul 6, 2024).

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).
  • 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.11

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

add a new OpenAI-API-compatible model

and then "Credentials validation failed with status code 404"

why?please help.

image

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @leowang9527 on GitHub (Jul 6, 2024). ### 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] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.6.11 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce add a new OpenAI-API-compatible model and then "Credentials validation failed with status code 404" why?please help. ![image](https://github.com/langgenius/dify/assets/38214421/f8443095-f298-492c-a670-75982cab3a28) ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:06:41 -05:00
yindo closed this issue 2026-02-21 18:06:41 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 6, 2024):

@Noahhhhha Hello there! I'm here to help you with bug reports, answer questions, and assist you with becoming a contributor. While you're awaiting a human maintainer, feel free to ask me anything.

The "Credentials validation failed with status code 404" error indicates that the endpoint URL you are trying to reach is not found. This typically means that the URL is incorrect or the endpoint does not exist.

To resolve this issue, ensure that the endpoint_url provided in the credentials is correct and points to a valid OpenAI API-compatible endpoint. The URL should end with a slash (/), and the specific paths for the endpoints should be correctly appended based on the mode (either chat/completions, completions, or embeddings).

Here is the relevant code snippet that constructs the endpoint URL and sends the request:

headers = {
    'Content-Type': 'application/json'
}

api_key = credentials.get('api_key')
if api_key:
    headers["Authorization"] = f"Bearer {api_key}"

endpoint_url = credentials.get('endpoint_url')
if not endpoint_url.endswith('/'):
    endpoint_url += '/'

completion_type = LLMMode.value_of(credentials['mode'])

if completion_type is LLMMode.CHAT:
    data = {
        'model': model,
        'messages': [
            {
                "role": "user",
                "content": "ping"
            },
        ],
        'max_tokens': 5
    }
    endpoint_url = urljoin(endpoint_url, 'chat/completions')
elif completion_type is LLMMode.COMPLETION:
    data = {
        'model': model,
        'prompt': 'ping',
        'max_tokens': 5
    }
    endpoint_url = urljoin(endpoint_url, 'completions')
elif completion_type is LLMMode.EMBEDDING:
    data = {
        'input': 'ping',
        'model': model
    }
    endpoint_url = urljoin(endpoint_url, 'embeddings')
else:
    raise ValueError("Unsupported completion type for model configuration.")

# send a post request to validate the credentials
response = requests.post(
    endpoint_url,
    headers=headers,
    json=data,
    timeout=(10, 300)
)

if response.status_code != 200:
    raise CredentialsValidateFailedError(
        f'Credentials validation failed with status code {response.status_code}')

Make sure that:

  1. The endpoint_url is correct and accessible.
  2. The endpoint paths (chat/completions, completions, or embeddings) are valid for the given mode.

Additionally, the OpenAIProvider class in Dify's codebase uses the gpt-3.5-turbo model for credential validation regardless of the model type you are trying to add. This means that the validation process is standardized to ensure consistency. Here is the relevant part of the code:

class OpenAIProvider(ModelProvider):

    def validate_provider_credentials(self, credentials: Mapping) -> None:
        """
        Validate provider credentials
        if validate failed, raise exception

        :param credentials: provider credentials, credentials form defined in `provider_credential_schema`.
        """
        try:
            model_instance = self.get_model_instance(ModelType.LLM)

            # Use `gpt-3.5-turbo` model for validate,
            # no matter what model you pass in, text completion model or chat model
            model_instance.validate_credentials(
                model='gpt-3.5-turbo',
                credentials=credentials
            )
        except CredentialsValidateFailedError as ex:
            raise ex
        except Exception as ex:
            logger.exception(f'{self.get_provider_schema().provider} credentials validate failed')
            raise ex

If the URL is correct and you still encounter the issue, verify that the API server is running and the endpoint is correctly configured to handle the requests [1][2][3].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jul 6, 2024): <!-- Greeting --> @Noahhhhha Hello there! I'm here to help you with bug reports, answer questions, and assist you with becoming a contributor. While you're awaiting a human maintainer, feel free to ask me anything. <!-- Answer --> The "Credentials validation failed with status code 404" error indicates that the endpoint URL you are trying to reach is not found. This typically means that the URL is incorrect or the endpoint does not exist. To resolve this issue, ensure that the `endpoint_url` provided in the credentials is correct and points to a valid OpenAI API-compatible endpoint. The URL should end with a slash (`/`), and the specific paths for the endpoints should be correctly appended based on the mode (either `chat/completions`, `completions`, or `embeddings`). Here is the relevant code snippet that constructs the endpoint URL and sends the request: ```python headers = { 'Content-Type': 'application/json' } api_key = credentials.get('api_key') if api_key: headers["Authorization"] = f"Bearer {api_key}" endpoint_url = credentials.get('endpoint_url') if not endpoint_url.endswith('/'): endpoint_url += '/' completion_type = LLMMode.value_of(credentials['mode']) if completion_type is LLMMode.CHAT: data = { 'model': model, 'messages': [ { "role": "user", "content": "ping" }, ], 'max_tokens': 5 } endpoint_url = urljoin(endpoint_url, 'chat/completions') elif completion_type is LLMMode.COMPLETION: data = { 'model': model, 'prompt': 'ping', 'max_tokens': 5 } endpoint_url = urljoin(endpoint_url, 'completions') elif completion_type is LLMMode.EMBEDDING: data = { 'input': 'ping', 'model': model } endpoint_url = urljoin(endpoint_url, 'embeddings') else: raise ValueError("Unsupported completion type for model configuration.") # send a post request to validate the credentials response = requests.post( endpoint_url, headers=headers, json=data, timeout=(10, 300) ) if response.status_code != 200: raise CredentialsValidateFailedError( f'Credentials validation failed with status code {response.status_code}') ``` Make sure that: 1. The `endpoint_url` is correct and accessible. 2. The endpoint paths (`chat/completions`, `completions`, or `embeddings`) are valid for the given mode. Additionally, the `OpenAIProvider` class in Dify's codebase uses the `gpt-3.5-turbo` model for credential validation regardless of the model type you are trying to add. This means that the validation process is standardized to ensure consistency. Here is the relevant part of the code: ```python class OpenAIProvider(ModelProvider): def validate_provider_credentials(self, credentials: Mapping) -> None: """ Validate provider credentials if validate failed, raise exception :param credentials: provider credentials, credentials form defined in `provider_credential_schema`. """ try: model_instance = self.get_model_instance(ModelType.LLM) # Use `gpt-3.5-turbo` model for validate, # no matter what model you pass in, text completion model or chat model model_instance.validate_credentials( model='gpt-3.5-turbo', credentials=credentials ) except CredentialsValidateFailedError as ex: raise ex except Exception as ex: logger.exception(f'{self.get_provider_schema().provider} credentials validate failed') raise ex ``` If the URL is correct and you still encounter the issue, verify that the API server is running and the endpoint is correctly configured to handle the requests <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/openai_api_compatible/text_embedding/text_embedding.py)</sup><sup>[[3]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/openai/openai.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4474