Skip to content

fix: Use orElseGet to defer loading of default credentials#124

Merged
jaycee-li merged 1 commit intogoogleapis:mainfrom
mrdziuban:fix-default-credentials
Apr 3, 2025
Merged

fix: Use orElseGet to defer loading of default credentials#124
jaycee-li merged 1 commit intogoogleapis:mainfrom
mrdziuban:fix-default-credentials

Conversation

@mrdziuban
Copy link
Contributor

@mrdziuban mrdziuban commented Mar 24, 2025

When constructing a Client with explicitly provided credentials, the ApiClient constructor still throws an error about failing to get application default credentials. For example:

Client client = Client.builder()
  .credentials(...)
  .project("...")
  .location("...")
  .vertexAI(true)
  .build();
/*
java.lang.IllegalArgumentException: Failed to get application default credentials, please explicitly provide credentials.
	at com.google.genai.ApiClient.<init>(ApiClient.java:109)
	at com.google.genai.HttpApiClient.<init>(HttpApiClient.java:43)
	at com.google.genai.Client.<init>(Client.java:203)
	at com.google.genai.Client.<init>(Client.java:27)
	at com.google.genai.Client$Builder.build(Client.java:55)
	...
*/

As a fix, this defers loading of the application default credentials by calling orElseGet instead of orElse on the given credentials.

@mrdziuban mrdziuban force-pushed the fix-default-credentials branch 2 times, most recently from 8da7c0c to 5294488 Compare March 27, 2025 13:28
@mrdziuban mrdziuban force-pushed the fix-default-credentials branch from 5294488 to 978c946 Compare April 3, 2025 14:18
@mrdziuban
Copy link
Contributor Author

@jaycee-li could you take a look at this? Or if not, could you tag someone who can? Thank you!

Copy link
Collaborator

@jaycee-li jaycee-li left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@jaycee-li jaycee-li merged commit 6adac0e into googleapis:main Apr 3, 2025
2 checks passed
@mrdziuban mrdziuban deleted the fix-default-credentials branch April 3, 2025 16:37
copybara-service bot pushed a commit that referenced this pull request Apr 3, 2025
--
978c946 by Matt Dziuban <mrdziuban@gmail.com>:

fix: Use `orElseGet` to defer loading of default credentials.
COPYBARA_INTEGRATE_REVIEW=#124 from mrdziuban:fix-default-credentials 978c946
PiperOrigin-RevId: 743689191
This was referenced Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants