Input payload exceeds context window limits.
Why this happens
Oversized requests must be segmented to fit within supported token bounds.
Answer 1: Split content into smaller chunks
from google import genai
client = genai.Client()
token_count = client.models.count_tokens(
model="gemini-2.5-flash",
contents=long_text
)
chunks = [long_text[i:i+500000] for i in range(0, len(long_text),
500000)]
