Skip to content

fix: support OAuth for Gemini media understanding#17813

Closed
irchelper wants to merge 2 commits into
openclaw:mainfrom
irchelper:fix/gemini-media-oauth
Closed

fix: support OAuth for Gemini media understanding#17813
irchelper wants to merge 2 commits into
openclaw:mainfrom
irchelper:fix/gemini-media-oauth

Conversation

@irchelper

@irchelper irchelper commented Feb 16, 2026

Copy link
Copy Markdown

Summary

Extract parseGeminiAuth() to shared infra module (src/infra/gemini-auth.ts) and use it in both:

  • src/memory/embeddings-gemini.ts
  • src/media-understanding/providers/google/inline-data.ts

Problem

inline-data.ts directly set x-goog-api-key header without handling OAuth JSON format:

if (!headers.has('x-goog-api-key')) {
  headers.set('x-goog-api-key', params.apiKey);
}

This broke media understanding when using OAuth authentication (e.g., {"token": "...", "projectId": "..."}).

Solution

  • Created src/infra/gemini-auth.ts with shared parseGeminiAuth() function
  • Both files now import and use this shared function
  • Properly supports both traditional API keys and OAuth tokens

Testing

  • pnpm check passes (format, types, lint)

Greptile Summary

Extracts the parseGeminiAuth() function from src/memory/embeddings-gemini.ts (added in the prior commit ac0613cf) into a shared src/infra/gemini-auth.ts module, and applies it to src/media-understanding/providers/google/inline-data.ts to fix OAuth authentication for Gemini media understanding (video/image description).

  • New shared module: src/infra/gemini-auth.ts — detects OAuth JSON format ({"token": "...", "projectId": "..."}) and returns Authorization: Bearer headers, falling back to x-goog-api-key for traditional API keys.
  • inline-data.ts: Replaces hardcoded x-goog-api-key + content-type header logic with parseGeminiAuth(), fixing the bug where OAuth JSON was set as a raw API key value.
  • embeddings-gemini.ts: Swaps the local parseGeminiAuth implementation for the shared import (no behavioral change).
  • Header override semantics are preserved in both call sites — caller-provided headers still take precedence.

Confidence Score: 5/5

  • This PR is safe to merge — it's a straightforward extract-and-reuse refactor that fixes a real OAuth authentication bug with no behavioral regressions.
  • The changes are minimal and well-scoped: a function is extracted verbatim from one file into a shared module and applied to a second call site. The extracted function is identical to the original. Header override semantics are preserved in both consumers. Existing tests (embeddings + video) validate the traditional API key path, and the OAuth path follows the same pattern already proven in the embeddings module. No new attack surface or risky logic introduced.
  • No files require special attention.

Last reviewed commit: 962d59b

(5/5) You can turn off certain types of comments like style here!

康熙 added 2 commits February 16, 2026 14:02
Add parseGeminiAuth() to detect OAuth JSON format ({"token": "...", "projectId": "..."})
and use Bearer token authentication instead of x-goog-api-key header.

This allows OAuth users (using gemini-cli-auth extension) to use memory_search
with Gemini embedding API.
Extract parseGeminiAuth() to shared infra module and use it in both
embeddings-gemini.ts and inline-data.ts.

Previously, inline-data.ts directly set x-goog-api-key header without
handling OAuth JSON format. Now it properly supports both traditional
API keys and OAuth tokens.
@irchelper

Copy link
Copy Markdown
Author

Merged into #17800

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant