Skip to content
Source
Sign inSign up
TanStack/schemas

Send the Gemini API key as a header, not a query param #351

Mergedtombeckenhammerged 2 commits intomain fromfix/350-gemini-key-headermerged by tombeckenham View on GitHub

tombeckenhamcommented

Closes #350

What

The Gemini models poll put GEMINI_API_KEY in the request URL as ?key=. fetchJson quotes the URL in its error message, so the 400 at 2026-10-18T15:00:30Z put the live key into a PostHog ingest_failed event.

listModels now sends the key in the x-goog-api-key header, which the Gemini API accepts. The URL, and every error message that quotes it, no longer carries the secret. The error itself still throws as before; nothing is swallowed.

Test

src/server/providers/gemini-list.test.ts stubs a 400 from the listing. It checks that the thrown message still names the status, contains no key, and that the key went in the header. It fails on main.

Not in this PR

  • The exposed key should be rotated, and the PostHog event holding it deleted. That has to happen outside the repo.
  • connect.securitySchemes (the auth hint served to agents) still says in: query. That is valid for clients and out of scope here.

Review notes (non-critical, not fixed here)

Four parallel reviews (correctness, silent failures, test quality, comment accuracy) found nothing critical. They noted:

  • pricingPromise and wirePromise start before the listing loop in listModels. If the listing throws and one of those loads later rejects, nothing ever handles the rejection. This was already on main; it is worth a small follow-up.
  • body.models ?? [] reads a page with no models field as empty. Also already on main.
  • The test leaves non-listing fetches pending, so a future change that awaits docs before the listing would make it hang instead of fail. It covers only the first page; later pages go through the same code.
  • I took the comment wording fix (name fetchJson) in c4b7435.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PHzf3V4TcvL3zzFSmp9i8Y

    1. cloudflare-workers-and-pages[bot](GitHub profile, opens in a new tab)commented

      Deploying with  Cloudflare Workers  Cloudflare Workers

      The latest updates on your project. Learn more about integrating Git with Workers.

      StatusNameLatest CommitPreview URLUpdated (UTC)
      ✅ Deployment successful!
      View logs
      modelschemasc4b74354Commit Preview URL

      Branch Preview URL
      Oct 18 2026, 03:49 PM
    2. QuestionAnswer
      What it solvesA failed Gemini models fetch put the live GEMINI_API_KEY into ingest_failed telemetry, because the key was in the URL that fetchJson quotes in its error.
      Does it matterYes. It is a secret leak to a third party (PostHog), and it repeats on every failed Gemini listing fetch.
      Added complexityLittle: 4 lines of code changed, plus one 46-line test.
      Fallbacks that should be errorsNone added. The error still throws with its status.
      Public type/API changesNone. The served connect.securitySchemes is unchanged.
      Users helped/hurtHelps the operator: no secret in telemetry. No catalog output changes.
      Standards complianceFollows CLAUDE.md. The test is under src/server/providers, uses no any, and touches no generated artifacts. Lint, typecheck, format and the full test suite (2055 tests) pass locally.
      VerdictApprove. It removes the cause of the leak with the smallest correct diff. The key still has to be rotated outside the repo.

      Generated by Claude Code

    3. tombeckenham merged thisc7544d9

    4. tombeckenham closed this

Sign in to join this conversation.