Replies: 11 comments
-
|
The default key is not used in load balancing because load balancing requires multiple API keys to distribute the requests. The default key is the credential added when initially configuring the model provider. Load balancing will take effect and the current will be limited when at least one additional model credential is added to the configuration [1]. For more details, you might find this similar discussion helpful: What will happen to the API when load balancing is enabled and rate limiting is enabled? [2]. |
Beta Was this translation helpful? Give feedback.
-
|
@StudyingLover @dosu |
Beta Was this translation helpful? Give feedback.
-
|
To ensure that load balancing works correctly with multiple API keys, follow these steps:
Dify uses the Round-robin strategy by default for load balancing, which means it should distribute requests evenly across all configured keys [1]. If you still see only one key being used, double-check that all keys are correctly added and saved in the configuration. If the issue persists, there might be a problem with how the keys are being recognized or saved. In that case, reviewing the configuration steps or checking for any known issues in the documentation might help. |
Beta Was this translation helpful? Give feedback.
-
|
@StudyingLover @dosu |
Beta Was this translation helpful? Give feedback.
-
|
The first key is always used instead of load balancing across multiple keys because at least one additional model credential must be added to save and enable load balancing. If only the default API key is configured without adding additional keys, load balancing will not be activated, and the system will continue to use the first key. Additionally, it is important to note that model load balancing is a paid feature and requires a subscription to a SaaS paid service or the purchase of an enterprise version to enable this functionality [1]. If you have already added additional keys and saved the configuration successfully, but still see only the first key being used, it might be worth checking the following:
If everything seems correct and the issue persists, there might be a deeper problem with how the keys are being recognized or saved. |
Beta Was this translation helpful? Give feedback.
-
|
@StudyingLover @dosu |
Beta Was this translation helpful? Give feedback.
-
|
The part of the load balancing code responsible for using the key saved by the load balancing to make requests is: provider_model_credentials_cache = ProviderCredentialsCache(
tenant_id=load_balancing_model_config.tenant_id,
identity_id=load_balancing_model_config.id,
cache_type=ProviderCredentialsCacheType.LOAD_BALANCING_MODEL,
)
# Get cached provider model credentials
cached_provider_model_credentials = provider_model_credentials_cache.get()This code snippet retrieves the cached provider model credentials using the key saved by the load balancing configuration. The |
Beta Was this translation helpful? Give feedback.
-
|
@StudyingLover @dosu |
Beta Was this translation helpful? Give feedback.
-
|
Yes, if you don’t have the load balancing configuration in Redis, there will be a situation where only one key is used. This is because the Here is the relevant code snippet: def _round_robin_invoke(self, function: Callable, *args, **kwargs):
"""
Round-robin invoke
:param function: function to invoke
:param args: function args
:param kwargs: function kwargs
:return:
"""
if not self.load_balancing_manager:
return function(*args, **kwargs)If |
Beta Was this translation helpful? Give feedback.
-
|
@StudyingLover @dosu The saved load balancing configuration is now in the table load_balancing_model_configs, but the load balancing fails and the default key is always used. What may be the reason? |
Beta Was this translation helpful? Give feedback.
-
|
The load balancing fails and the default key is always used because at least one additional model credential must be added to save and enable load balancing. If no additional credentials are added, the system will default to using the initial API key. Additionally, the system checks for the existence of an "inherit" configuration, which represents the provider or model custom credentials. If this "inherit" configuration does not exist, it initializes one. This ensures that the load balancing configuration is properly set up. Moreover, if the |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Self Checks
Dify version
0.8.3
Cloud or Self Hosted
Cloud
Steps to reproduce
After load balancing is enabled, the key used is always the latest one added. Why is the default key not used? Shouldn't it be used one by one? I want to know when the default key will be used, when load balancing will take effect, and when the current is limited.
✔️ Expected Behavior
After load balancing is enabled, the key used is always the latest one added. Why is the default key not used? Shouldn't it be used one by one? I want to know when the default key will be used, when load balancing will take effect, and when the current is limited.
❌ Actual Behavior
After load balancing is enabled, the key used is always the latest one added. Why is the default key not used? Shouldn't it be used one by one? I want to know when the default key will be used, when load balancing will take effect, and when the current is limited.
Beta Was this translation helpful? Give feedback.
All reactions