Cannot use wenxinyiyan or Ernie 4 #4911

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

Originally created by @zpyzl on GitHub (Aug 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).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.16

Cloud or Self Hosted

Cloud

Steps to reproduce

Select settings > Model Provider > Wenxinyiyan > setup > enter into key and secret > Save

✔️ Expected Behavior

successfully save WENXINYIYAN model API key and secret

Actual Behavior

dc17749e015d1603a5f32beb249c890

Originally created by @zpyzl on GitHub (Aug 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] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.6.16 ### Cloud or Self Hosted Cloud ### Steps to reproduce Select settings > Model Provider > Wenxinyiyan > setup > enter into key and secret > Save ### ✔️ Expected Behavior successfully save WENXINYIYAN model API key and secret ### ❌ Actual Behavior ![dc17749e015d1603a5f32beb249c890](https://github.com/user-attachments/assets/29e42430-1bda-438b-b1a7-f48f458e1943)
yindo added the 🐞 bug label 2026-02-21 18:08:34 -05:00
yindo closed this issue 2026-02-21 18:08:34 -05:00
Author
Owner

@zpyzl commented on GitHub (Aug 6, 2024):

WENXINYIYAN website has redirect to https://console.bce.baidu.com/qianfan/ais/console/onlineTest
where I applied the API key

@zpyzl commented on GitHub (Aug 6, 2024): WENXINYIYAN website has redirect to https://console.bce.baidu.com/qianfan/ais/console/onlineTest where I applied the API key
Author
Owner

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

Hey @zpyzl! I'm here to help you with any bugs, questions, or contributions while you wait for a human maintainer. Let's tackle this together!

To resolve the "Credentials validation failed: Invalid API key or secret key: unknown client id" error when trying to use the Wenxinyiyan model in Dify version 0.6.16 (Cloud), ensure that you are providing valid API key and secret key credentials. Here is a code snippet that shows how to validate these credentials using environment variables:

import os

import pytest

from core.model_runtime.errors.validate import CredentialsValidateFailedError
from core.model_runtime.model_providers.wenxin.wenxin import WenxinProvider


def test_validate_provider_credentials():
    provider = WenxinProvider()

    with pytest.raises(CredentialsValidateFailedError):
        provider.validate_provider_credentials(
            credentials={
                'api_key': 'hahahaha',
                'secret_key': 'hahahaha'
            }
        )

    provider.validate_provider_credentials(
        credentials={
            'api_key': os.environ.get('WENXIN_API_KEY'),
            'secret_key': os.environ.get('WENXIN_SECRET_KEY')
        }
    )

Make sure that the environment variables WENXIN_API_KEY and WENXIN_SECRET_KEY are set with the correct values. You can set these environment variables in your operating system or in your deployment environment.

For example, in a Unix-based system, you can set these variables in the terminal:

export WENXIN_API_KEY='your_actual_api_key'
export WENXIN_SECRET_KEY='your_actual_secret_key'

In a deployment environment, you would typically set these variables in the configuration settings of your cloud service provider.

Additionally, the validate_provider_credentials method in the WenxinProvider class uses the ernie-bot model to validate the credentials. Ensure that the credentials you are using are valid for the ernie-bot model:

class WenxinProvider(ModelProvider):
    def validate_provider_credentials(self, credentials: dict) -> 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 `ernie-bot` model for validate,
            model_instance.validate_credentials(
                model='ernie-bot',
                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

By ensuring that the API key and secret key are correctly set and valid for the ernie-bot model, you should be able to resolve the credentials validation error [1][2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Aug 6, 2024): <!-- Greeting --> Hey @zpyzl! I'm here to help you with any bugs, questions, or contributions while you wait for a human maintainer. Let's tackle this together! <!-- Answer --> To resolve the "Credentials validation failed: Invalid API key or secret key: unknown client id" error when trying to use the Wenxinyiyan model in Dify version 0.6.16 (Cloud), ensure that you are providing valid API key and secret key credentials. Here is a code snippet that shows how to validate these credentials using environment variables: ```python import os import pytest from core.model_runtime.errors.validate import CredentialsValidateFailedError from core.model_runtime.model_providers.wenxin.wenxin import WenxinProvider def test_validate_provider_credentials(): provider = WenxinProvider() with pytest.raises(CredentialsValidateFailedError): provider.validate_provider_credentials( credentials={ 'api_key': 'hahahaha', 'secret_key': 'hahahaha' } ) provider.validate_provider_credentials( credentials={ 'api_key': os.environ.get('WENXIN_API_KEY'), 'secret_key': os.environ.get('WENXIN_SECRET_KEY') } ) ``` Make sure that the environment variables `WENXIN_API_KEY` and `WENXIN_SECRET_KEY` are set with the correct values. You can set these environment variables in your operating system or in your deployment environment. For example, in a Unix-based system, you can set these variables in the terminal: ```sh export WENXIN_API_KEY='your_actual_api_key' export WENXIN_SECRET_KEY='your_actual_secret_key' ``` In a deployment environment, you would typically set these variables in the configuration settings of your cloud service provider. Additionally, the `validate_provider_credentials` method in the `WenxinProvider` class uses the `ernie-bot` model to validate the credentials. Ensure that the credentials you are using are valid for the `ernie-bot` model: ```python class WenxinProvider(ModelProvider): def validate_provider_credentials(self, credentials: dict) -> 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 `ernie-bot` model for validate, model_instance.validate_credentials( model='ernie-bot', 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 ``` By ensuring that the API key and secret key are correctly set and valid for the `ernie-bot` model, you should be able to resolve the credentials validation error <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/tests/integration_tests/model_runtime/wenxin/test_provider.py)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/wenxin/wenxin.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#4911