generative-ai-python
generative-ai-python copied to clipboard
Test to ensure that api_key or credentials is set in configure
Description of the feature request:
I would like to suggest a change to configure
Currently both api_key and credentials can be set to None.
api_key: str | None = None,
credentials: ga_credentials.Credentials | dict | None = None,
If they are both set to None then the API returns with an error which arguably doesn't lead the developer to understand what the issue is. "ACCESS_TOKEN_SCOPE_INSUFFICIENT" It would be better if the library tested to ensure that either api_key is set or credentials are set. Ideally that api_key is not set to "" as well. as this appears to happen when an empty env var is loaded. Which is again hard to debug.
What problem are you trying to solve with this feature?
I am trying to make it easer to avoid the "ACCESS_TOKEN_SCOPE_INSUFFICIENT" error. By informing the developer that they must set either credentials or api key
Any other information you'd like to share?
This is an issue i have seen a number of times on SO and one that i have also personally had sevral times. Google generativeai 403 Request had insufficient authentication scopes. [reason: "ACCESS_TOKEN_SCOPE_INSUFFICIENT"]
If accepted i would be willing to make the change myself.