Skip to content

feat: Add Nano Banana 2 support with three-tier quality presets#57

Merged
shinpr merged 14 commits intomainfrom
feat/nano-banana2-with-pro-model-option
Feb 27, 2026
Merged

feat: Add Nano Banana 2 support with three-tier quality presets#57
shinpr merged 14 commits intomainfrom
feat/nano-banana2-with-pro-model-option

Conversation

@shinpr
Copy link
Owner

@shinpr shinpr commented Feb 27, 2026

Summary

  • Add Nano Banana 2 (gemini-3.1-flash-image-preview) as the default image generation model, replacing the previous Pro-only setup
  • Introduce a three-tier quality preset system (IMAGE_QUALITY env var) allowing users to choose between speed and fidelity:
    • fast (default): Nano Banana 2 — fastest generation for drafts and iteration
    • balanced: Nano Banana 2 with thinking enabled — better detail and coherence
    • quality: Nano Banana Pro (gemini-3-pro-image-preview) — highest fidelity for final deliverables
  • Per-request quality override via the quality tool parameter, designed to only activate when the user explicitly requests it (server default is respected otherwise)
  • Add 4 new aspect ratios (1:4, 1:8, 4:1, 8:1) supported by Nano Banana 2
  • Update imageSize options to 1K, 2K, 4K (removed 512px which is Flash-only and incompatible with Pro model)
  • Optimize tool parameter descriptions for LLM consumers — precision-first approach ensuring correct parameter usage
  • Comprehensive test coverage: 161 tests across 13 test files, all passing

Test plan

  • Unit tests: All 161 tests pass (npm test)
  • Build verification: npm run build succeeds
  • Manual testing: Verified all three quality presets generate images correctly with expected models
  • LLM behavior: Confirmed LLM does not override IMAGE_QUALITY env var when quality is not explicitly requested

🤖 Generated with Claude Code

shinpr and others added 14 commits February 27, 2026 12:46
Define ImageQuality = 'fast' | 'balanced' | 'quality' preset type for
the new quality tier system. Extend AspectRatio with 4 new ratios
(1:4, 1:8, 4:1, 8:1) and ImageSize with 2 new sizes (512px, 1K)
supported by Nano Banana 2. Add optional quality field to
GenerateImageParams.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add imageQuality field to Config interface, read from IMAGE_QUALITY
env var (default: 'fast'), and validate against allowed values
(fast, balanced, quality). Update existing config tests to include
the new required field.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add 5 test cases covering imageQuality config: valid values accepted,
invalid values rejected with helpful error, default 'fast' when env
var unset, env var reading, and invalid env var rejection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace hardcoded model name with dynamic selection based on quality
preset: fast/balanced use gemini-3.1-flash-image-preview (Nano Banana 2),
quality uses gemini-3-pro-image-preview (Nano Banana Pro). Add
thinkingConfig with thinkingLevel 'high' for balanced preset.
Constructor accepts defaultQuality from config with per-request override.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add quality parameter validation against supported values (fast,
balanced, quality). Extend SUPPORTED_ASPECT_RATIOS with 4 new ratios
(1:4, 1:8, 4:1, 8:1) supported by Nano Banana 2.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update geminiClient tests: change expected model to
gemini-3.1-flash-image-preview, add 5 tests for quality presets
(fast/balanced/quality model selection, thinking_config, per-request
override, constructor default). Update inputValidator tests: fix 4:1
ratio test (now valid), add new aspect ratio tests, add quality
validation tests. Total: 155 tests passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add quality preset parameter (fast/balanced/quality) to generate_image
tool schema with descriptive text for AI agents. Update aspectRatio
enum with 4 new ratios (1:4, 1:8, 4:1, 8:1) and imageSize enum with
2 new sizes (512px, 1K). Pass quality through to geminiClient.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update GeminiAPIError suggestion text to mention both
gemini-3.1-flash-image-preview and gemini-3-pro-image-preview
instead of only the Pro model. Add error suggestion tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update all test fixtures and mocks from gemini-3-pro-image-preview to
gemini-3.1-flash-image-preview. Add tests for quality parameter schema,
imageSize enum (4 values), and verify aspectRatio enum (14 values).
Total: 161 tests passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- #1: Extract model names to GEMINI_MODELS constants in types/mcp.ts
- #2: Unify quality values list to IMAGE_QUALITY_VALUES constant
- #3: Fix unsafe as ImageQuality cast order in getConfig()
- #4,#8: Remove contextMethod/features from mock (not in interface)
- #5: Use !== undefined for quality passthrough consistency
- #6: Add tools to GeminiClientInstance interface
- #7: Sort aspect ratio enum consistently across files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
512px is only supported by Nano Banana 2 (Flash) and would cause
API errors when used with the Pro model quality preset. Keep 1K
which is supported by both models.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- quality: Replace internal model names with user-facing decision
  criteria (speed/fidelity tradeoff and use cases)
- purpose: Clarify effect on output (lighting, composition, detail)
- fileName: Remove implementation detail (IMAGE_OUTPUT_DIR)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Bump version 0.7.0 -> 0.8.0 in package.json, package-lock.json, server.json
- Remove 512px from README imageSize parameter (removed from implementation)
- Improve quality parameter description to prevent LLM from overriding server default
- Add user-friendly per-request quality override instructions in README

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…nano-banana-2 tag

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@shinpr shinpr self-assigned this Feb 27, 2026
@shinpr shinpr merged commit df31a04 into main Feb 27, 2026
1 check passed
@shinpr shinpr deleted the feat/nano-banana2-with-pro-model-option branch February 27, 2026 06:12
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