run-llama/llama_index · error · ValueError
Initial token count exceeds token limit
Error message
Initial token count exceeds token limit
What it means
Error "Initial token count exceeds token limit" thrown in run-llama/llama_index.
Source
Thrown at llama-index-core/llama_index/core/memory/chat_summary_memory_buffer.py:178
# NOTE: The llm will have to be set manually in kwargs
if "llm" in data:
data.pop("llm")
return cls(**data, **kwargs)
def get(
self, input: Optional[str] = None, initial_token_count: int = 0, **kwargs: Any
) -> List[ChatMessage]:
"""Get chat history."""
chat_history = self.get_all()
if len(chat_history) == 0:
return []
# Give the user the choice whether to count the system prompt or not
if self.count_initial_tokens:
if initial_token_count > self.token_limit:
raise ValueError("Initial token count exceeds token limit")
self._token_count = initial_token_count
(
chat_history_full_text,
chat_history_to_be_summarized,
) = self._split_messages_summary_or_full_text(chat_history)
if self.llm is None or len(chat_history_to_be_summarized) == 0:
# Simply remove the message that don't fit the buffer anymore
updated_history = chat_history_full_text
else:
updated_history = [
self._summarize_oldest_chat_history(chat_history_to_be_summarized),
*chat_history_full_text,
]
self.reset()
self._token_count = 0
View on GitHub (pinned to afd0fef371)
Solutions
- Increase token_limit_full_text so it exceeds the token count of the initial messages.
- Shorten or truncate the initial chat history before constructing the ChatSummaryMemoryBuffer.
- Move older messages into a memory block instead of passing them as initial_chat_history.
When it happens
Trigger: Thrown at llama-index-core/llama_index/core/memory/chat_summary_memory_buffer.py:178 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/ee4e36c78f88fffe.
Report an issue: GitHub.