Hey guys,
I got a error using File API from google-genai. I use that to list and delete files in the generative language API file storage. After using it for some time, I received this generic error and since then I have not been able to list anything, all requests fail.
Function: client.files.list()
Error: ServerError: 500 INTERNAL. {‘error’: {‘code’: 500, ‘message’: ‘Failed to convert server response to JSON’, ‘status’: ‘INTERNAL’}}
Stack:
---------------------------------------------------------------------------
ServerError Traceback (most recent call last)
Cell In[8], line 2
1 print('My files:')
----> 2 for f in client.files.list():
3 client.files.delete(name=f.name)
File ~/xxx/google/genai/files.py:714, in Files.list(self, config)
708 def list(
709 self, *, config: Optional[types.ListFilesConfigOrDict] = None
710 ) -> Pager[types.File]:
711 return Pager(
712 'files',
713 self._list,
--> 714 self._list(config=config),
715 config,
716 )
File ~/xxx/google/genai/files.py:385, in Files._list(self, config)
382 request_dict = _common.convert_to_dict(request_dict)
383 request_dict = _common.encode_unserializable_types(request_dict)
--> 385 response_dict = self._api_client.request(
386 'get', path, request_dict, http_options
387 )
389 if not self._api_client.vertexai:
390 response_dict = _ListFilesResponse_from_mldev(
391 self._api_client, response_dict
392 )
File ~/xxx/google/genai/_api_client.py:732, in BaseApiClient.request(self, http_method, path, request_dict, http_options)
722 def request(
723 self,
724 http_method: str,
(...)
727 http_options: Optional[HttpOptionsOrDict] = None,
728 ) -> Union[BaseResponse, Any]:
729 http_request = self._build_request(
730 http_method, path, request_dict, http_options
731 )
--> 732 response = self._request(http_request, stream=False)
733 json_response = response.json
734 if not json_response:
File ~/xxx/google/genai/_api_client.py:661, in BaseApiClient._request(self, http_request, stream)
658 print(data)
660 print(response.content)
--> 661 errors.APIError.raise_for_response(response)
662 return HttpResponse(
663 response.headers, response if stream else [response.text]
664 )
File ~/xxx/google/genai/errors.py:103, in APIError.raise_for_response(cls, response)
101 raise ClientError(status_code, response_json, response)
102 elif 500 <= status_code < 600:
--> 103 raise ServerError(status_code, response_json, response)
104 else:
105 raise cls(status_code, response_json, response)
ServerError: 500 INTERNAL. {'error': {'code': 500, 'message': 'Failed to convert server response to JSON', 'status': 'INTERNAL'}}
I can also replicate it by making a GET call directly using the following cURL:
curl --location ‘https://generativelanguage.googleapis.com/v1beta/files’ \ --header 'x-goog-api-key: <my_api_key>
Since I can’t list and delete, my storage has filled up to the maximum. When the quota resets, the storage is cleared and this error disappears, but it comes back after calling the file API to list and delete a few dozen/hundreds of times.
Anyone felt the pain?
Tnks,