Skip to content

Gemma / Nano Banana compat: skip tools, hint on billing-required quotas - #12

Merged
aciderix merged 1 commit into
mainfrom
claude/gemma-compat
Apr 22, 2026
Merged

aciderix merged 1 commit into
mainfrom
claude/gemma-compat

Conversation

@aciderix

@aciderix aciderix commented Apr 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes two annoyances surfaced in recent testing:

1. Gemma / Nano Banana reject tools + systemInstruction

Those models return 400 when the request body carries either field ("Function Calling is not Enabled for gemma*", and the same for Imagen-ish models). The app now strips both when the selected model doesn't support them.

  • New modelSupportsFunctionCalling() heuristic: false for startsWith("gemma"), startsWith("imagen"), or name containing -image (Nano Banana). Sits next to the existing modelEmitsImages() so image-only models get the right request shape automatically.
  • buildRequestBody() skips tools and systemInstruction for those models. Gemini 2.5 / 2.0 / 1.5 chat models keep the full request shape and function calling.

2. Image-model quota errors look like a rate-limit, but they're billing

The free tier has limit: 0 for Imagen + -image models — the API returns a "quota exceeded" message that's easy to misread as "try again later". We now detect the limit: 0 + image-model pattern in tryExtractError() and append:

Enable billing on the Google Cloud project linked to your API key: https://console.cloud.google.com/billing — then retry.

Test plan

  • Pick a Gemma model in the top-bar picker, send a chat turn, get a real answer instead of a 400.
  • Pick gemini-2.5-flash-image-preview without billing, send, see the new billing hint in the error bubble.
  • Pick gemini-2.5-flash, send "create a hello.py", confirm function calling still works and write_file runs.

https://claude.ai/code/session_015dVKN2jG34HKP9SeBpSvS5

Summary by Sourcery

Adjust Gemini request construction and error handling for better compatibility with Gemma/image models and clearer quota messaging.

Enhancements:

  • Gate inclusion of system instructions and tools in request bodies behind a modelSupportsFunctionCalling() check to avoid 400 errors from Gemma and image-only models.
  • Extend error extraction to detect image-model free-tier quota (limit 0) responses and append a billing enablement hint for users.
  • Introduce modelSupportsFunctionCalling() helper alongside modelEmitsImages() to distinguish models that accept tools/systemInstruction from image-only or Gemma models.

- buildRequestBody now strips 'systemInstruction' and 'tools' for models
  that don't accept them (Gemma, Imagen, *-image). Gemini text models are
  unchanged, so function calling keeps working where supported.
- modelSupportsFunctionCalling() encapsulates the heuristic (name-based)
  next to modelEmitsImages() so newly added image-only models inherit
  the right request shape automatically.
- When the API returns a quota-exceeded error for an image model on the
  free tier, append a pointer to enable billing at
  console.cloud.google.com/billing — the default message is misleading
  (says 'quota exceeded' even though the real cause is billing-required).
@sourcery-ai

sourcery-ai Bot commented Apr 22, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Adjusts request construction and error handling for Gemini-related models so that Gemma and image-only models avoid unsupported tools/systemInstruction fields, and image-model quota errors surface a clearer billing-related hint.

Class diagram for updated RestGeminiCore request/error handling

classDiagram
    class RestGeminiCore {
        +buildRequestBody() String
        +tryExtractError(body String) String?
        -looksLikeImageFreeTierQuota(message String) Boolean
    }

    class RestGeminiCoreCompanion {
        +modelEmitsImages(modelName String) Boolean
        +modelSupportsFunctionCalling(modelName String) Boolean
    }

    RestGeminiCoreCompanion <|-- RestGeminiCore : companion
Loading

File-Level Changes

Change Details Files
Gate inclusion of tools and systemInstruction in request bodies based on model capabilities and image emission behavior.
  • Refactored buildRequestBody() to always include contents but conditionally add systemInstruction and tools only when modelSupportsFunctionCalling(model) is true.
  • Introduced local emitsImages and supportsTools flags in buildRequestBody() to separate concerns of image-generation behavior vs. tool support.
  • Kept image-specific generationConfig attachment behavior based solely on modelEmitsImages(model) so image-capable models still get correct request shape.
core-bridge/src/main/kotlin/com/gemini/bridge/RestGeminiCore.kt
Clarify error messages for image-model quota failures related to free-tier billing limits.
  • Enhanced tryExtractError() to first extract the raw error message and then, when it matches an image free-tier quota pattern, append a billing enablement hint with a direct Cloud Console billing URL.
  • Added looksLikeImageFreeTierQuota(message: String) helper to detect quota errors by checking for case-insensitive presence of "quota", "limit: 0", and either "-image" or "imagen" in the message.
core-bridge/src/main/kotlin/com/gemini/bridge/RestGeminiCore.kt
Introduce a heuristic to determine whether a model supports function calling (tools + systemInstruction).
  • Added modelSupportsFunctionCalling(modelName: String) companion function that lowercases the model name and returns false for prefixes "gemma" and "imagen" and for any name containing "-image".
  • Documented modelSupportsFunctionCalling() to clarify that Gemma and image-only models currently reject tools/systemInstruction while Gemini text/multimodal models accept them.
  • Placed modelSupportsFunctionCalling() alongside existing modelEmitsImages() to keep model capability heuristics co-located.
core-bridge/src/main/kotlin/com/gemini/bridge/RestGeminiCore.kt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In modelSupportsFunctionCalling, you duplicate the -image detection logic that already exists in modelEmitsImages; consider delegating to modelEmitsImages or centralizing model-capability detection so the heuristics don’t drift over time.
  • The looksLikeImageFreeTierQuota check relies on brittle string fragments like "limit: 0" and "quota"; if possible, consider inspecting structured fields on the error response (e.g., code, status, or metadata) so the billing hint isn’t tied to exact message wording.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `modelSupportsFunctionCalling`, you duplicate the `-image` detection logic that already exists in `modelEmitsImages`; consider delegating to `modelEmitsImages` or centralizing model-capability detection so the heuristics don’t drift over time.
- The `looksLikeImageFreeTierQuota` check relies on brittle string fragments like `"limit: 0"` and `"quota"`; if possible, consider inspecting structured fields on the error response (e.g., code, status, or metadata) so the billing hint isn’t tied to exact message wording.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@aciderix
aciderix merged commit 2c4d9bb into main Apr 22, 2026
3 checks passed
@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@aciderix has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 36 minutes and 7 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 36 minutes and 7 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ceb93b49-a238-4a41-b38f-0c474eb0f8e0

📥 Commits

Reviewing files that changed from the base of the PR and between 188ba36 and b0dc377.

📒 Files selected for processing (1)
  • core-bridge/src/main/kotlin/com/gemini/bridge/RestGeminiCore.kt
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/gemma-compat

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

2 participants