feat(google): service-account auth for TTS + Imagen (Vertex AI), fix false-availability bugs#132
Open
shubham21155102 wants to merge 1 commit into
Conversation
…e availability
Google's TTS and Imagen tools advertised service-account auth
(GOOGLE_APPLICATION_CREDENTIALS) but only ever authenticated with an API
key string, so users with a service-account JSON could not use either tool.
google_tts.get_status() also over-reported availability when the JSON was
set, then failed at execute() — a silent-availability bug.
Separately, both hand-rolled _load_dotenv parsers kept inline comments as
values, so after `cp .env.example .env` every keyed tool falsely reported
"available" with no real credentials.
Changes:
- Add tools/google_credentials.py: lazy google-auth Bearer-token helper.
- google_tts: authenticate via Cloud TTS Bearer token when only a service
account is configured; make get_status() honest.
- google_imagen: route service-account auth to Vertex AI
({location}-aiplatform.googleapis.com) with project/location resolution,
alongside the existing AI Studio API-key path.
- Fix both _load_dotenv parsers to strip inline comments (quote-aware).
- Add google-auth to requirements; document the new env vars in .env.example.
- .gitignore: never commit GCP service-account key files.
Verified locally with a real service account: TTS produced a valid MP3 and
Imagen produced a valid 1408x768 PNG via Vertex AI. Existing test suite
passes (2 unrelated pre-existing failures only).
Closes calesthio#131
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Google's
google_ttsandgoogle_imagentools advertised service-account auth (GOOGLE_APPLICATION_CREDENTIALS) but only ever authenticated with an API key string, so anyone with a Google service-account JSON (common in GCP shops) could not use either tool. Along the way this surfaced two related false-availability bugs. Fixes #131.Changes
tools/google_credentials.py(new) — lazygoogle-authhelper that mints an OAuth Bearer token from the service-account JSON and resolves the GCP project id.google-authis imported lazily so a missing dep is an actionable runtime error, not an import failure.google_tts— when only a service account is configured, authenticate Cloud Text-to-Speech with a Bearer token instead of?key=.get_status()now reportsavailableonly when a path that actually works is configured (previously it over-reported onGOOGLE_APPLICATION_CREDENTIALSand then failed atexecute()).google_imagen— service-account auth routes to Vertex AI ({location}-aiplatform.googleapis.com), since the AI Studio endpoint is API-key-only. Project resolves fromGOOGLE_CLOUD_PROJECTor the key file; region fromGOOGLE_CLOUD_LOCATION(defaultus-central1). The existing API-key → AI Studio path is unchanged._load_dotenv(bothbase_tool.pyandtool_registry.py) — strip inline comments (quote-aware). PreviouslyGOOGLE_API_KEY= # commentparsed the comment as the value, so aftercp .env.example .envevery keyed tool falsely reportedavailable.requirements.txt— addgoogle-auth..env.example— documentGOOGLE_APPLICATION_CREDENTIALS/GOOGLE_CLOUD_PROJECT/GOOGLE_CLOUD_LOCATION..gitignore— never commit GCP service-account key files.Testing
Verified locally with a real service account (no API key set):
google_ttsgoogle_imagenimagen-4.0-generate-001Availability honesty: blank
.env→ bothunavailable; JSON set →availableand actually generates. Invalid JSON → clean actionable error, no crash.Full suite:
334 passed. The only 2 failures pre-exist on cleanmain(unrelateddoubaoprovider set +character-animationruntime-doc contract) — this PR adds no new failures.Notes for reviewers
.envparser change is global. It's quote-aware and only strips a#at the start of the value or after whitespace, matching thepython-dotenvconvention. Values needing a literal#should be quoted.imagen-4.0-*model ids as the AI Studio path; confirmed working against a live project.