Wierd Error when calling api

hey guys, for some reason every now and then it just says
Traceback (most recent call last):
File “/usr/local/lib/python3.10/dist-packages/flask/app.py”, line 1473, in wsgi_app
response = self.full_dispatch_request()
File “/usr/local/lib/python3.10/dist-packages/flask/app.py”, line 882, in full_dispatch_request
rv = self.handle_user_exception(e)
File “/usr/local/lib/python3.10/dist-packages/flask/app.py”, line 880, in full_dispatch_request
rv = self.dispatch_request()
File “/usr/local/lib/python3.10/dist-packages/flask/app.py”, line 865, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
File “/root/AdaptiveAI API/Server.py”, line 78, in Retail_query
_response = _ai_lib.chatQuery(Query,UserID)
File “/root/AdaptiveAI API/app/Logging.py”, line 24, in wrapper
result = func(*args, **kwargs)
File “/root/AdaptiveAI API/app/AI_Lib.py”, line 107, in chatQuery
response = _chat_session.send_message(query)
File “/usr/local/lib/python3.10/dist-packages/google/generativeai/generative_models.py”, line 578, in send_message
response = self.model.generate_content(
File “/usr/local/lib/python3.10/dist-packages/google/generativeai/generative_models.py”, line 331, in generate_content
response = self._client.generate_content(
File “/usr/local/lib/python3.10/dist-packages/google/ai/generativelanguage_v1beta/services/generative_service/client.py”, line 830, in generate_content
response = rpc(
File “/usr/local/lib/python3.10/dist-packages/google/api_core/gapic_v1/method.py”, line 131, in call
return wrapped_func(*args, **kwargs)
File “/usr/local/lib/python3.10/dist-packages/google/api_core/retry/retry_unary.py”, line 293, in retry_wrapped_func
return retry_target(
File “/usr/local/lib/python3.10/dist-packages/google/api_core/retry/retry_unary.py”, line 153, in retry_target
_retry_error_helper(
File “/usr/local/lib/python3.10/dist-packages/google/api_core/retry/retry_base.py”, line 212, in _retry_error_helper
raise final_exc from source_exc
File “/usr/local/lib/python3.10/dist-packages/google/api_core/retry/retry_unary.py”, line 144, in retry_target
result = target()
File “/usr/local/lib/python3.10/dist-packages/google/api_core/timeout.py”, line 120, in func_with_timeout
return func(*args, **kwargs)
File “/usr/local/lib/python3.10/dist-packages/google/api_core/grpc_helpers.py”, line 78, in error_remapped_callable
raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.InternalServerError: 500 An internal error has occurred. Please retry or report in Guia de solução de problemas  |  Gemini API  |  Google AI for Developers

if i retry its perfectly fine its wierd

Error 500 is not uncommon, tho certainly more common than it should be. If you’re retrying the same thing and it works as expected, then there isn’t much you can do.

How frequently does this happen?

every like 10m or so, its quite annoying and i keep thinking that im sending info wrong or something but it will work for like 2hrs straight no issues then suddenly err 500

I recommend using retry with exponential back off for both http status codes, 429 and 500. That doesn’t stop the internal error from happening, but it does effectively stop the 500’s from interfering with your development and/or application.

Hope that helps.

1 Like