[BUG] /model fails for Gemini models: context caching requires 1024+ tokens

Resolved 💬 2 comments Opened Mar 3, 2026 by furkangr Closed Mar 31, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Describe the bug

When attempting to switch to a Gemini model using /model gemini-3-pro-preview in a conversation with less than 1024 tokens of context, the command fails with a 400 error related to context caching minimum token requirements.

Error Message

API error: 400 {"error":{"message":"litellm.BadRequestError: Vertex_aiException BadRequestError - {\n  \"error\": {\n    \"code\": 400,\n    \"message\": \"The cached content is of 56 tokens. The minimum token count to start caching is 1024.\",\n    \"status\": \"INVALID_ARGUMENT\"\n  }\n}\n. Received Model Group=gemini-3-pro-preview\nAvailable Model Group Fallbacks=None","type":null,"param":null,"code":"400"}}

Steps to Reproduce

  1. Start a new Claude Code conversation (or have a short conversation with < 1024 tokens)
  2. Run /model gemini-3-pro-preview
  3. Observe the 400 error

Expected Behavior

The model switch should either:

  • Work without requiring context caching for small conversations
  • Display a user-friendly error message explaining the minimum token requirement
  • Automatically disable context caching when below the threshold

Root Cause

Gemini API's context caching feature requires a minimum of 1,024 tokens (for Gemini 2.5 Flash) or 2,048 tokens (for Gemini 2.5/3.x Pro). When LiteLLM attempts to cache the conversation context during model switching, it fails if the context is too small.

Workaround

Continue the conversation to build up more context (1000+ tokens) before switching models, or start a fresh conversation with more initial context.

Related Issues

Environment

  • Claude Code CLI
  • Model attempted: gemini-3-pro-preview
  • Context size at time of error: 56 tokens
  • Date: 2026-03-03

Suggested Fix

Add validation in the /model command to either:

  1. Skip context caching when switching to Gemini models if context < minimum threshold
  2. Display a helpful error message to the user explaining the limitation
  3. Auto-detect and handle this scenario gracefully

References

What Should Happen?

The model switch should either:

  • Work without requiring context caching for small conversations
  • Display a user-friendly error message explaining the minimum token requirement
  • Automatically disable context caching when below the threshold

Error Messages/Logs

API error: 400 {"error":{"message":"litellm.BadRequestError: Vertex_aiException BadRequestError - {\n  \"error\": {\n    \"code\": 400,\n    \"message\": \"The cached content is of 56 tokens. The minimum token count to start caching is 1024.\",\n    \"status\": \"INVALID_ARGUMENT\"\n  }\n}\n. Received Model Group=gemini-3-pro-preview\nAvailable Model Group Fallbacks=None","type":null,"param":null,"code":"400"}}

Steps to Reproduce

  1. Start a new Claude Code conversation (or have a short conversation with < 1024 tokens)
  2. Run /model gemini-3-pro-preview
  3. Observe the 400 error

Claude Model

None

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.63

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Warp

Additional Information

_No response_

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗