Did My Vertex AI Input Caching Fail?

I ask this because it seems that it didn’t work, and it may cost me a lot of money.

Caching disambiguation says input caching is enable by default.

I am sure that I have enable default input caching, but when I check response.usage_metadata, it seems that it didn’t work

Here is the code:

from google import genai
from google.genai import types


gemini_client = genai.Client(
    vertexai=True,
    project='gen-lang-client-0021737048',
    location='us-central1',
    http_options=types.HttpOptions(api_version='v1')
)

chat_session=gemini_client.chats.create(model="gemini-2.0-flash-001", history=[])

resp1=chat_session.send_message(message="hi, I am john")
print(resp1.usage_metadata.total_token_count) # 21

resp2= chat_session.send_message(message="Do u know my name?")
print(resp2.usage_metadata.cached_content_token_count) # it should be 21, but it is None

Thank you!

1 Like

@Long_Peng, minimum length to enable Context caching is 4096 tokens . please refer to documentation for any further details

1 Like

Thank you. Can default caching be used for caching conversation like OpenAI/Claude/DeepSeek? How to cache conversation like OpenAI/Claude/DeepSeek?