API key error occurs when setting model load balancing with Google model #7781

Closed
opened 2026-02-21 18:22:21 -05:00 by yindo · 3 comments
Owner

Originally created by @fujita-h on GitHub (Jan 19, 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

0.15.1

Cloud or Self Hosted

Cloud, Self Hosted (Source)

Steps to reproduce

  1. Setup Google Gemini Model
  2. Add Load Balancing Setting to a model, for example "Gemini 1.5 Flash"
  3. Create simple flow uses "Gemini 1.5 Flash"
  4. Run the flow several times

✔️ Expected Behavior

It is load balanced and the flow succeeds every time.

Actual Behavior

An error occurs at the timing of the key that is additionally set for load balancing.

Image

Originally created by @fujita-h on GitHub (Jan 19, 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 0.15.1 ### Cloud or Self Hosted Cloud, Self Hosted (Source) ### Steps to reproduce 1. Setup Google Gemini Model 2. Add Load Balancing Setting to a model, for example "Gemini 1.5 Flash" 3. Create simple flow uses "Gemini 1.5 Flash" 4. Run the flow several times ### ✔️ Expected Behavior It is load balanced and the flow succeeds every time. ### ❌ Actual Behavior An error occurs at the timing of the key that is additionally set for load balancing. ![Image](https://github.com/user-attachments/assets/42234513-6ddb-4141-a960-24c92b4db3e3)
yindo added the 🐞 bug label 2026-02-21 18:22:21 -05:00
yindo closed this issue 2026-02-21 18:22:21 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jan 19, 2025):

I found a similar unsolved discussion regarding model load balancing usage issues, which might be relevant to your situation. You can check it out here [1].

Regarding the API key error you're encountering, Dify returns a specific error message and code when an API key is invalid or misconfigured. The error code is 1001, and the message is "Invalid Authorization header format. Expected 'Bearer ' format." This might be related to the 400 Bad Request error you're seeing [2][3].

Additionally, Dify validates API keys for Google models during the load balancing process using the validateLoadBalancingCredentials function. This function checks the credentials by sending a POST request to a specific URL endpoint. If the validation fails, it returns an error status and message [4][5].

Ensure that your API key is correctly formatted and that the credentials are valid. If the issue persists, you might want to review the load balancing configuration and ensure that all settings are correctly applied.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot[bot] commented on GitHub (Jan 19, 2025): <!-- Answer --> I found a similar unsolved discussion regarding model load balancing usage issues, which might be relevant to your situation. You can check it out [here](https://github.com/langgenius/dify/discussions/8729) <sup>[[1]](https://github.com/langgenius/dify/discussions/8729)</sup>. Regarding the API key error you're encountering, Dify returns a specific error message and code when an API key is invalid or misconfigured. The error code is 1001, and the message is "Invalid Authorization header format. Expected 'Bearer <api-key>' format." This might be related to the 400 Bad Request error you're seeing <sup>[[2]](https://github.com/langgenius/dify-docs/blob/main/jp/.gitbook/assets/Dify-test.openapi.jp.json)</sup><sup>[[3]](https://github.com/langgenius/dify-docs/blob/main/en/.gitbook/assets/Dify-test.openapi.json)</sup>. Additionally, Dify validates API keys for Google models during the load balancing process using the `validateLoadBalancingCredentials` function. This function checks the credentials by sending a POST request to a specific URL endpoint. If the validation fails, it returns an error status and message <sup>[[4]](https://github.com/langgenius/dify/blob/main/web/app/components/header/account-setting/model-provider-page/utils.ts)</sup><sup>[[5]](https://github.com/langgenius/dify/blob/main/api/services/model_load_balancing_service.py)</sup>. Ensure that your API key is correctly formatted and that the credentials are valid. If the issue persists, you might want to review the load balancing configuration and ensure that all settings are correctly applied. <!-- 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/0e73a85d-1533-4e13-aeca-ed52fd7f884c?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/0e73a85d-1533-4e13-aeca-ed52fd7f884c?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/0e73a85d-1533-4e13-aeca-ed52fd7f884c?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/0e73a85d-1533-4e13-aeca-ed52fd7f884c?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/0e73a85d-1533-4e13-aeca-ed52fd7f884c?feedback_type=hallucination) | [Other](https://app.dosu.dev/response-feedback/0e73a85d-1533-4e13-aeca-ed52fd7f884c?feedback_type=other)</sup>
Author
Owner

@kurokobo commented on GitHub (Jan 19, 2025):

@fujita-h
Hi, thanks for the report and PR.

In my understanding, this issue can occur not only with Google but also with any provider that does not have model_credential_schema.

The model_credential_schema is a schema designed to support Customizable Models for the provider, which means that providers that only support predefined-model typically do not have model_credential_schema. Therefore, the same issue can arise in providers that do not support Customizable Models (e.g., Anthropic and many others) as well.

As a potential fix, adding model_credential_schema to Google is one option, but adopting that proposal would mean making model_credential_schema mandatory for all providers that do not use Customizable Models.

In the first place, the Add Config for LB screen shows the form based on credential_form_schemas from provider_credential_schema or model_credential_schema depending on the configuration method (predefined or customizable).

https://github.com/langgenius/dify/blob/bc3a570dda37cbb8539d9a5c1494e3a4317fc090/web/app/components/header/account-setting/model-provider-page/model-modal/model-load-balancing-entry-modal.tsx#L94-L96

Therefore, to determine variables to be decrypted, it seems more natural to reference provider_credential_schema or model_credential_schema depending on the configuration method as well, rather than strictly referring to model_credential_schema.

@kurokobo commented on GitHub (Jan 19, 2025): @fujita-h Hi, thanks for the report and PR. In my understanding, this issue can occur not only with Google but also with any provider that does not have `model_credential_schema`. The `model_credential_schema` is a schema designed to support Customizable Models for the provider, which means that providers that only support `predefined-model` typically do not have `model_credential_schema`. Therefore, the same issue can arise in providers that do not support Customizable Models (e.g., Anthropic and many others) as well. As a potential fix, adding `model_credential_schema` to Google is one option, but adopting that proposal would mean making `model_credential_schema` mandatory for all providers that do not use Customizable Models. In the first place, the `Add Config` for LB screen shows the form based on `credential_form_schemas` from `provider_credential_schema` or `model_credential_schema` depending on the configuration method (predefined or customizable). https://github.com/langgenius/dify/blob/bc3a570dda37cbb8539d9a5c1494e3a4317fc090/web/app/components/header/account-setting/model-provider-page/model-modal/model-load-balancing-entry-modal.tsx#L94-L96 Therefore, to determine variables to be decrypted, it seems more natural to reference `provider_credential_schema` or `model_credential_schema` depending on the configuration method as well, rather than strictly referring to `model_credential_schema`.
Author
Owner

@fujita-h commented on GitHub (Jan 19, 2025):

@kurokobo
Thank you for checking.

I also created a PR that makes the way provider_credential_schema and model_credential_schema are referenced consistent with the web.

@fujita-h commented on GitHub (Jan 19, 2025): @kurokobo Thank you for checking. I also created a PR that makes the way `provider_credential_schema` and `model_credential_schema` are referenced consistent with the web.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#7781