This repository was archived by the owner on Dec 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 487
This repository was archived by the owner on Dec 16, 2025. It is now read-only.
No PDF support for files API. #379
Copy link
Copy link
Closed
Labels
component:python sdkIssue/PR related to Python SDKIssue/PR related to Python SDKstatus:awaiting user responseAwaiting a response from the authorAwaiting a response from the authortype:questionSupport-related issuesSupport-related issues
Description
Description of the bug:
I executed the following code with loaded GEMINI_API_KEY environment variable but recieved error "google.api_core.exceptions.InvalidArgument: 400 Unsupported MIME type: application/pdf"
Dependency:
google-generativeai == 0.6.0
Here is the code:
import os
import time
import google.generativeai as genai
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
def upload_to_gemini(path, mime_type=None):
file = genai.upload_file(path, mime_type=mime_type)
print(f"Uploaded file '{file.display_name}' as: {file.uri}")
return file
def wait_for_files_active(files):
print("Waiting for file processing...")
for name in (file.name for file in files):
file = genai.get_file(name)
while file.state.name == "PROCESSING":
print(".", end="", flush=True)
time.sleep(10)
file = genai.get_file(name)
if file.state.name != "ACTIVE":
raise Exception(f"File {file.name} failed to process")
print("...all files ready")
print()
generation_config = {
"temperature": 1,
"top_p": 0.95,
"top_k": 64,
"max_output_tokens": 8192,
"response_mime_type": "text/plain",
}
model = genai.GenerativeModel(
model_name="gemini-1.5-pro",
generation_config=generation_config,
system_instruction="Just summarize the document",
)
files = [
upload_to_gemini("./resources/few-shot/canon-filter/difm-adapter-ef-eosr-im-eng.pdf", mime_type="application/pdf"),
]
wait_for_files_active(files)
chat_session = model.start_chat(
history=[
{
"role": "user",
"parts": [
"Summarize file",
files[0],
],
},
]
)
response = chat_session.send_message("INSERT_INPUT_HERE")
print(response.text)The traceback of error:
Traceback (most recent call last):
File "/init_project/app/services/taskAgent.py", line 223, in <module>
response = chat_session.send_message("INSERT_INPUT_HERE")
File "/python3.10/site-packages/google/generativeai/generative_models.py", line 504, in send_message
response = self.model.generate_content(
File "/python3.10/site-packages/google/generativeai/generative_models.py", line 258, in generate_content
response = self._client.generate_content(
File "/python3.10/site-packages/google/ai/generativelanguage_v1beta/services/generative_service/client.py", line 812, in generate_content
response = rpc(
File "/python3.10/site-packages/google/api_core/gapic_v1/method.py", line 131, in __call__
return wrapped_func(*args, **kwargs)
File "/python3.10/site-packages/google/api_core/retry/retry_unary.py", line 293, in retry_wrapped_func
return retry_target(
File "/python3.10/site-packages/google/api_core/retry/retry_unary.py", line 153, in retry_target
_retry_error_helper(
File "/python3.10/site-packages/google/api_core/retry/retry_base.py", line 212, in _retry_error_helper
raise final_exc from source_exc
File "/python3.10/site-packages/google/api_core/retry/retry_unary.py", line 144, in retry_target
result = target()
File "/python3.10/site-packages/google/api_core/timeout.py", line 120, in func_with_timeout
return func(*args, **kwargs)
File "/python3.10/site-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.InvalidArgument: 400 Unsupported MIME type: application/pdf
Actual vs expected behavior:
The prompt should be executed without error because the code is generated by Google AI studio with a tested working prompt in UI.
Any other information you'd like to share?
I sent the request from Vietnam.
Metadata
Metadata
Assignees
Labels
component:python sdkIssue/PR related to Python SDKIssue/PR related to Python SDKstatus:awaiting user responseAwaiting a response from the authorAwaiting a response from the authortype:questionSupport-related issuesSupport-related issues