# Issues with token's limit

**URL:** <https://community.crewai.com/t/issues-with-tokens-limit/4957>\
**Category:** General\
**Created:** [March 24, 2025, 7:34pm UTC](https://community.crewai.com/t/issues-with-tokens-limit/4957 "2025-03-24T19:34:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roberto\_Ronderos](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/roberto_ronderos/32/3187_2.png) [@Roberto\_Ronderos](https://community.crewai.com/u/Roberto_Ronderos)\
**Post date:** [March 24, 2025, 7:34pm UTC](https://community.crewai.com/t/issues-with-tokens-limit/4957/1 "2025-03-24T19:34:36Z")

</div>

Hi there, I’m running a crew with 4 agents and sometimes I get this error:

> Error code: 429 - {‘error’: {‘message’: ‘Request too large for gpt-4o-mini in organization org-cYJxGgQQaN0Q42pQUmO3ksQr on tokens per min (TPM): Limit 4000000, Requested 8814213. The input or output tokens must be reduced in order to run successfully. Visit [https://platform.openai.com/account/rate-limits](https://platform.openai.com/account/rate-limits) to learn more.’, ‘type’: ‘tokens’, ‘param’: None, ‘code’: ‘rate\_limit\_exceeded’}}

here’s the full stack trace:

> LiteLLM.Info: If you need to debug this error, use `litellm.\_turn\_on\_debug()'.
> 
> ERROR:root:LiteLLM call failed: litellm.RateLimitError: RateLimitError: OpenAIException - Error code: 429 - {‘error’: {‘message’: ‘Request too large for gpt-4o-mini in organization org-cYJxGgQQaN0Q42pQUmO3ksQr on tokens per min (TPM): Limit 4000000, Requested 8814213. The input or output tokens must be reduced in order to run successfully. Visit [https://platform.openai.com/account/rate-limits](https://platform.openai.com/account/rate-limits) to learn more.’, ‘type’: ‘tokens’, ‘param’: None, ‘code’: ‘rate\_limit\_exceeded’}}
> 
> ERROR:agent\_rose:Error in property feasibility analysis  
> Traceback (most recent call last):  
> File “…/litellm/llms/openai/openai.py”, line 711, in completion  
> raise e  
> File “…/litellm/llms/openai/openai.py”, line 638, in completion  
> self.make\_sync\_openai\_chat\_completion\_request(  
> File “…/litellm/litellm\_core\_utils/logging\_utils.py”, line 145, in sync\_wrapper  
> result = func(\*args, \*\*kwargs)  
> File “…/litellm/llms/openai/openai.py”, line 457, in make\_sync\_openai\_chat\_completion\_request  
> raise e  
> File “…/litellm/llms/openai/openai.py”, line 439, in make\_sync\_openai\_chat\_completion\_request  
> raw\_response = openai\_client.chat.completions.with\_raw\_response.create(  
> File “…/openai/\_legacy\_response.py”, line 364, in wrapped  
> return cast(LegacyAPIResponse[R], func(\*args, \*\*kwargs))  
> File “…/openai/\_utils/\_utils.py”, line 279, in wrapper  
> return func(\*args, \*\*kwargs)  
> File “…/openai/resources/chat/completions/completions.py”, line 879, in create  
> return self.\_post(  
> File “…/openai/\_base\_client.py”, line 1296, in post  
> return cast(ResponseT, self.request(…))  
> File “…/openai/\_base\_client.py”, line 973, in request  
> return self.\_request(  
> File “…/openai/\_base\_client.py”, line 1062, in \_request  
> return self.\_retry\_request(  
> File “…/openai/\_base\_client.py”, line 1111, in \_retry\_request  
> return self.\_request(  
> File “…/openai/\_base\_client.py”, line 1077, in \_request  
> raise self.\_make\_status\_error\_from\_response(err.response) from None  
> openai.RateLimitError: Error code: 429 - {‘error’: {‘message’: ‘Request too large for gpt-4o-mini… (TPM): Limit 4000000, Requested 8814213.’}}
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):  
> File “…/litellm/main.py”, line 1692, in completion  
> raise e  
> File “…/litellm/main.py”, line 1665, in completion  
> response = openai\_chat\_completions.completion(  
> File “…/litellm/llms/openai/openai.py”, line 721, in completion  
> raise OpenAIError(  
> litellm.llms.openai.common\_utils.OpenAIError: Error code: 429 - {‘error’: {‘message’: ‘Request too large for gpt-4o-mini…’}}
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):  
> File “…/property\_analyzer.py”, line 164, in analyze\_properties  
> analyzed\_properties = crew.analyze\_properties(properties, …)  
> File “…/crew.py”, line 293, in analyze\_properties  
> analyzed\_property = self.analyze\_property(property\_data)  
> File “…/crew.py”, line 199, in analyze\_property  
> crew\_output = self.crew().kickoff(inputs=inputs)  
> File “…/crew.py”, line 576, in kickoff  
> result = self.\_run\_sequential\_process()  
> File “…/crew.py”, line 683, in \_run\_sequential\_process  
> return self.\_execute\_tasks(self.tasks)  
> File “…/crew.py”, line 781, in \_execute\_tasks  
> task\_output = task.execute\_sync(…)  
> File “…/task.py”, line 302, in execute\_sync  
> return self.\_execute\_core(…)  
> File “…/task.py”, line 366, in \_execute\_core  
> result = agent.execute\_task(…)  
> File “…/agent.py”, line 254, in execute\_task  
> raise e  
> File “…/agent.py”, line 243, in execute\_task  
> result = self.agent\_executor.invoke(…)  
> File “…/crew\_agent\_executor.py”, line 112, in invoke  
> raise e  
> File “…/crew\_agent\_executor.py”, line 102, in invoke  
> formatted\_answer = self.\_invoke\_loop()  
> File “…/crew\_agent\_executor.py”, line 160, in \_invoke\_loop  
> raise e  
> File “…/crew\_agent\_executor.py”, line 140, in \_invoke\_loop  
> answer = self.\_get\_llm\_response()  
> File “…/crew\_agent\_executor.py”, line 210, in \_get\_llm\_response  
> raise e  
> File “…/crew\_agent\_executor.py”, line 201, in \_get\_llm\_response  
> answer = self.llm.call(…)  
> File “…/llm.py”, line 291, in call  
> response = litellm.completion(\*\*params)  
> File “…/utils.py”, line 1154, in wrapper  
> raise e  
> File “…/utils.py”, line 1032, in wrapper  
> result = original\_function(\*args, \*\*kwargs)  
> File “…/main.py”, line 3068, in completion  
> raise exception\_type(  
> File “…/exception\_mapping\_utils.py”, line 2201, in exception\_type  
> raise e  
> File “…/exception\_mapping\_utils.py”, line 345, in exception\_type  
> raise RateLimitError(  
> litellm.exceptions.RateLimitError: litellm.RateLimitError: RateLimitError: OpenAIException - Error code: 429 - {‘error’: {‘message’: ‘Request too large for gpt-4o-mini…’}}
> 
> ValueError: Error in property feasibility analysis: litellm.RateLimitError: RateLimitError: OpenAIException - Error code: 429 - {‘error’: {‘message’: ‘Request too large for gpt-4o-mini…’}}

I thought CrewAI handled this things by default, am I incorrect? I’ve also seen errors similar to this one when I enable memory.

---

<div class="post-metadata">

**Author:** ![derekmizak](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/derekmizak/32/3230_2.png) [@derekmizak](https://community.crewai.com/u/derekmizak)\
**Post date:** [March 31, 2025, 8:14pm UTC](https://community.crewai.com/t/issues-with-tokens-limit/4957/2 "2025-03-31T20:14:25Z")

</div>

I have exactly the same issue. All what I can find that CrewAI does limit retry rate through max\_rpm parameter in task but there is nothing about token per minute limiting. I can adjust max\_token but it leads to reduce quality. max\_token\_per\_minute option would be good.

---

<div class="post-metadata">

**Author:** ![T4n17](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/t4n17/32/4213_2.png) [@T4n17](https://community.crewai.com/u/T4n17)\
**Post date:** [July 31, 2025, 7:40am UTC](https://community.crewai.com/t/issues-with-tokens-limit/4957/3 "2025-07-31T07:40:13Z")

</div>

These types of errors don’t get handled by CrewAI. When there is an error, the task just fails because the exception is not handled. The only solution I found is to modify the Task class so that the exception is not raised, and the task is rerun after a fixed amount of time. This way, it doesn’t end up in error when it gets a rate limit error or a throttling error

```python
def _execute_core(
        self,
        agent: Optional[BaseAgent],
        context: Optional[str],
        tools: Optional[List[Any]],
        max_retries: Optional[int] = 5,
        delay: Optional[int] = 5,
    ) -> TaskOutput:
...
...
...
except Exception as e:
            self.end_time = datetime.datetime.now()
            crewai_event_bus.emit(self, TaskFailedEvent(error=str(e), task=self))
            if max_retries > 0:
                # Retry task execution
                time.sleep(delay)
                max_retries -= 1
                return self._execute_core(agent, context, tools, max_retries, delay)
            else:
                crewai_event_bus.emit(self, TaskCompletedEvent(output=TaskOutput(description="Task failed", agent=self.agent.role), task=self))
                #raise e # Re-raise the exception after emitting the event

```

Look [Here](https://github.com/T4n17/CrewAI-Retry-After-Failure-Patch)

---

<div class="post-metadata">

**Author:** ![Tony\_Wood](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/tony_wood/32/1876_2.png) [@Tony\_Wood](https://community.crewai.com/u/Tony_Wood)\
**Post date:** [July 31, 2025, 4:27pm UTC](https://community.crewai.com/t/issues-with-tokens-limit/4957/4 "2025-07-31T16:27:52Z")

</div>

@tonykipkemboi Is this worth a feature request as I have seen a few of these and felt it myself.  
Request to add `max_token_per_minute` to params
