mirror of
https://github.com/langgenius/dify-official-plugins.git
synced 2026-07-22 10:05:23 -04:00
Align Gemini validate_credentials to use LLM generation API instead of count_tokens
#958
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @WH-2099 on GitHub (Jan 28, 2026).
Originally assigned to: @WH-2099 on GitHub.
Self Checks
1. Is this request related to a challenge you're experiencing? Tell me about your story.
The current Gemini plugin uses
genai_client.models.count_tokens()API for credential validation, while other model providers (OpenAI, Anthropic, etc.) use the actual LLM generation API. This inconsistency may lead to situations where credentials pass validation but fail during actual usage.2. Additional context or comments
No response
3. Can you help us with this feature?
@dosubot[bot] commented on GitHub (Jan 28, 2026):
To align Gemini's credential validation with other providers, update the validate_credentials method in models/gemini/models/llm/llm.py to use the LLM generation API instead of count_tokens. Currently, it calls genai_client.models.count_tokens(model=model, contents="ping") for validation, which can let invalid credentials pass if they only fail during actual LLM usage (source).
You should replace the count_tokens call with a minimal LLM generation call, such as genai_client.models.generate_content(model=model, contents=["ping"]), similar to how OpenAI and Anthropic providers do it (OpenAI example, Anthropic example). Make sure to handle exceptions by raising CredentialsValidateFailedError if validation fails, and log other exceptions as in the current pattern.
After making this change, test with both valid and invalid credentials to ensure the new validation logic correctly reflects real-world LLM API usage. This will prevent credentials that only work for token counting but fail for actual generation from being accepted. Update any related comments or documentation to clarify the new approach.
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other