Skip to content

feat(google): service-account auth for TTS + Imagen (Vertex AI), fix false-availability bugs#132

Open
shubham21155102 wants to merge 1 commit into
calesthio:mainfrom
shubham21155102:feat/google-service-account-auth
Open

feat(google): service-account auth for TTS + Imagen (Vertex AI), fix false-availability bugs#132
shubham21155102 wants to merge 1 commit into
calesthio:mainfrom
shubham21155102:feat/google-service-account-auth

Conversation

@shubham21155102

@shubham21155102 shubham21155102 commented Jun 22, 2026

Copy link
Copy Markdown

What & why

Google's google_tts and google_imagen tools 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) — lazy google-auth helper that mints an OAuth Bearer token from the service-account JSON and resolves the GCP project id. google-auth is 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 reports available only when a path that actually works is configured (previously it over-reported on GOOGLE_APPLICATION_CREDENTIALS and then failed at execute()).
  • google_imagen — service-account auth routes to Vertex AI ({location}-aiplatform.googleapis.com), since the AI Studio endpoint is API-key-only. Project resolves from GOOGLE_CLOUD_PROJECT or the key file; region from GOOGLE_CLOUD_LOCATION (default us-central1). The existing API-key → AI Studio path is unchanged.
  • _load_dotenv (both base_tool.py and tool_registry.py) — strip inline comments (quote-aware). Previously GOOGLE_API_KEY= # comment parsed the comment as the value, so after cp .env.example .env every keyed tool falsely reported available.
  • requirements.txt — add google-auth.
  • .env.example — document GOOGLE_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):

Tool Auth path Result
google_tts service account → Cloud TTS Bearer valid MP3 (24 kHz mono)
google_imagen service account → Vertex AI Bearer valid 1408×768 PNG, model imagen-4.0-generate-001

Availability honesty: blank .env → both unavailable; JSON set → available and actually generates. Invalid JSON → clean actionable error, no crash.

Full suite: 334 passed. The only 2 failures pre-exist on clean main (unrelated doubao provider set + character-animation runtime-doc contract) — this PR adds no new failures.

Notes for reviewers

  • The .env parser change is global. It's quote-aware and only strips a # at the start of the value or after whitespace, matching the python-dotenv convention. Values needing a literal # should be quoted.
  • Imagen on Vertex uses the same imagen-4.0-* model ids as the AI Studio path; confirmed working against a live project.

…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>
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.

Google service-account auth is advertised but non-functional (TTS + Imagen) + false-availability bugs

1 participant