Payload exceeds maximum permitted token count.
Why this happens
The contents provided exceed the configured context limits for the selected Gemini model.
Answer 1: Chunk content into manageable sections
from google import genai
client = genai.Client()
token_count = client.models.count_tokens(
model="gemini-2.5-flash",
contents=long_text
)
