Skip to content

feat: run the Gemini engine through OpenRouter - #284

Open
hyperfocus1337 wants to merge 2 commits into
bradautomates:mainfrom
hyperfocus1337:feat/openrouter-provider
Open

hyperfocus1337 wants to merge 2 commits into
bradautomates:mainfrom
hyperfocus1337:feat/openrouter-provider

Conversation

@hyperfocus1337

Copy link
Copy Markdown

Summary

The Gemini engine can now use an OPENROUTER_API_KEY. YouTube URLs then go to Gemini through OpenRouter's chat completions API. The Google path does not change.

 main
   load_gemini_credentials(WATCH_GEMINI_PROVIDER)   # auto: GEMINI_API_KEY first, then OPENROUTER_API_KEY
   resolve_engine
   run_gemini(provider)
+    if provider == openrouter
+      if source is not YouTube
+        fail "Gemini rejected" before anything is sent
+      ask_openrouter(url)          # POST openrouter.ai/api/v1/chat/completions, video_url part
+    else
       youtube → ask(uri)           # Google interactions API, unchanged
       other   → upload_file → ask → delete_file
  • OpenRouter's Google AI Studio route accepts only YouTube video URLs (docs). Local files would need base64 data URLs, which hold the full video in memory, so this PR does not add them.
  • OpenRouter has no clip offsets. --start/--end become a request in the prompt, and the report labels the processing as agentic, focus 00:05–00:15 requested in the prompt.
  • A WATCH_GEMINI_MODEL without a slash gets a google/ prefix, so the default gemini-3.7-flash works for both providers.
  • The report adds OpenRouter cost from the response usage.cost.
  • Separate commit: HTTP 402 (spent prepaid credit) now maps to Gemini quota. Before, it mapped to Gemini rejected with a hint about private or unsupported videos. AI Studio sends 402 for a spent prepayment balance, and OpenRouter sends it for an empty balance.

Evidence

  • Before: with only an OpenRouter key, --engine gemini stops with The gemini engine needs GEMINI_API_KEY. A spent AI Studio key reports Gemini rejected: Gemini refused this request; the video may be private, unsupported, or too long. Detail: HTTP 402: Your prepayment credits are depleted.
    After: a live run with an OpenRouter key:

    $ OPENROUTER_API_KEY=… WATCH_GEMINI_PROVIDER=openrouter watch.py https://www.youtube.com/watch?v=jNQXAC9IVRw --start 0:05 --end 0:15 --question "What happens in this clip?"
    - **Source:** https://www.youtube.com/watch?v=jNQXAC9IVRw (URL sent to OpenRouter and Google)
    - **Engine:** google/gemini-3.7-flash via OpenRouter (agentic, focus 00:05–00:15 requested in the prompt)
    - **Gemini tokens:** 1303
    - **OpenRouter cost:** $0.0044
    ## Answer (from Gemini)
    * 00:05–00:15: A young man stands outdoors facing the camera … two elephants are visible …
    
    $ … watch.py /tmp/clip.mp4
    - **Source:** /tmp/clip.mp4 (not sent)
    - Gemini rejected: OpenRouter accepts only YouTube URLs for Gemini. …
    
  • Tests: 249 passed before, 265 passed after (python -m pytest -q, no network). The new tests cover:

    ask_openrouter sends Bearer auth, no x-goog-api-key, model google/<id>, video_url + processing agentic
    HTTP 401/402/429/5xx, an error object in an HTTP 200 body, empty choices, no route → categorized, key redacted
    --start/--end → focus range in the prompt
    credentials: GEMINI_API_KEY beats OPENROUTER_API_KEY under auto; WATCH_GEMINI_PROVIDER forces one; invalid value rejected
    watch: OpenRouter key + YouTube → ask_openrouter, never ask; non-YouTube → nothing sent, exit 1
    setup: only an OpenRouter key → engine gemini, provider openrouter, setup completes
    Google 402 → "Gemini quota"
    

Merge Danger

Door: two-way

The change adds a key and a setting, and writes no data. A revert restores the old behavior.

Blast Radius: small

  • Users with a GEMINI_API_KEY see no change, because auto prefers it.
  • A user who has OPENROUTER_API_KEY in the environment or in a cwd .env for another tool, and no GEMINI_API_KEY, changes under WATCH_ENGINE=auto: YouTube URLs go from the local engine to Gemini through OpenRouter, which bills that account. WATCH_ENGINE=local or WATCH_GEMINI_PROVIDER=google keeps the old behavior. If you prefer, I can make OpenRouter opt-in only (WATCH_GEMINI_PROVIDER=openrouter).
  • setup.py --json has a new gemini_provider field, and the scaffolded .env has a new OPENROUTER_API_KEY= line. Existing config files are not rewritten.

AI Studio answers a spent prepayment balance with HTTP 402. The adapter mapped every unlisted 4xx to
"rejected", whose hint blames a private, unsupported, or too-long video. 402 now maps to "quota",
which points at the key's plan.
With an OPENROUTER_API_KEY and no GEMINI_API_KEY, or with WATCH_GEMINI_PROVIDER=openrouter, watch
sends YouTube URLs to Gemini through OpenRouter's chat completions API with a video_url part.
OpenRouter's Google AI Studio route accepts only YouTube video URLs, so other sources fail before
anything is sent. OpenRouter has no clip offsets, so --start/--end become a request in the prompt,
and the report says so. WATCH_GEMINI_MODEL IDs get a google/ prefix unless they contain a slash.
The report shows the OpenRouter cost from the response usage.
hyperfocus1337 added a commit to hyperfocus1337/claude-video that referenced this pull request Nov 26, 2026
A distinct marketplace name lets this fork install next to the upstream claude-video marketplace.
Fork-only: not part of upstream PR bradautomates#284.
hyperfocus1337 added a commit to hyperfocus1337/coding-agent-config that referenced this pull request Nov 28, 2026
… fork

The fork adds an OpenRouter provider for the Gemini engine (upstream PR
bradautomates/claude-video#284). The catalog row, the user-level marketplace declaration and the
inventory point to hyperfocus1337/claude-video until that PR is merged.
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.

1 participant