Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

400 Request contains an invalid argument #664

Open
meganano202 opened this issue Jan 8, 2025 · 3 comments
Open

400 Request contains an invalid argument #664

meganano202 opened this issue Jan 8, 2025 · 3 comments
Labels
component:python sdk Issue/PR related to Python SDK status:triaged Issue/PR triaged to the corresponding sub-team type:bug Something isn't working

Comments

@meganano202
Copy link

Description of the bug:

For some reason I got this error.

This is my traceback when trying to process a video:

Traceback (most recent call last):
  File "f:\Users\meganano202\Desktop\Python\test.py", line 25, in <module>
    result = model.generate_content(
  File "C:\Users\meganano202\AppData\Local\Programs\Python\Python310\lib\site-packages\google\generativeai\generative_models.py", line 331, in generate_content
    response = self._client.generate_content(
  File "C:\Users\meganano202\AppData\Local\Programs\Python\Python310\lib\site-packages\google\ai\generativelanguage_v1beta\services\generative_service\client.py", line 830, in generate_content
    response = rpc(
  File "C:\Users\meganano202\AppData\Local\Programs\Python\Python310\lib\site-packages\google\api_core\gapic_v1\method.py", line 131, in __call__
    return wrapped_func(*args, **kwargs)
  File "C:\Users\meganano202\AppData\Local\Programs\Python\Python310\lib\site-packages\google\api_core\retry\retry_unary.py", line 293, in retry_wrapped_func
    return retry_target(
  File "C:\Users\meganano202\AppData\Local\Programs\Python\Python310\lib\site-packages\google\api_core\retry\retry_unary.py", line 153, in retry_target
    _retry_error_helper(
  File "C:\Users\meganano202\AppData\Local\Programs\Python\Python310\lib\site-packages\google\api_core\retry\retry_base.py", line 212, in _retry_error_helper
    raise final_exc from source_exc
  File "C:\Users\meganano202\AppData\Local\Programs\Python\Python310\lib\site-packages\google\api_core\retry\retry_unary.py", line 144, in retry_target
    result = target()
  File "C:\Users\meganano202\AppData\Local\Programs\Python\Python310\lib\site-packages\google\api_core\timeout.py", line 120, in func_with_timeout
    return func(*args, **kwargs)
  File "C:\Users\meganano202\AppData\Local\Programs\Python\Python310\lib\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 Request contains an invalid argument.

I tested it proccessing a image and without upload anything and it worked. I searched in google but nobody knows anything about this error

I suppose that the error its here:

result = model.generate_content(
        contents=[myfile, query],  # The query is passed as text
        safety_settings={
            HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE,
            HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE,
            HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE,
            HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE
        },
    )

But it dont really know because it worked fine yesterday

Actual vs expected behavior:

It gives me an error 400 when generating the response but yesterday it did it all right everything

Any other information you'd like to share?

No response

@TS-development
Copy link

We just started seeing a 400 today as well, unsure if related but this is what we are getting:

{"timestamp": "2025-01-08T19:55:35.279861", "logger": "api.main", "level": "ERROR", "message": "(CLOUD) true, 2025-01-08T19:55:35.279869, Uncaught Error in Ecomm Chat!!!: 400 Developer instruction is not enabled for models/gemini-1.5-flash-latest. Traceback: Traceback (most recent call last):\n  File \"/app/api/main.py\", line 196, in ecommerce_ws\n    chat_success = await _ecomm_chat_ws(\n  File \"/app/api/main.py\", line 174, in _ecomm_chat_ws\n    success, error_msg = await ecomm_chat.handle_chat_interaction()\n  File \"/app/api/chatting/ecommerce/ecommerce_chat.py\", line 303, in handle_chat_interaction\n    ai_resp = await self.second_stage_conversation(\n  File \"/app/api/chatting/ecommerce/ecommerce_chat.py\", line 217, in second_stage_conversation\n    ai_resp = await self.send_llm_text_response()\n  File \"/app/api/chatting/base_chat_interface.py\", line 125, in send_llm_text_response\n    async for token in self.get_llm_resp_ws():\n  File \"/app/api/chatting/base_chat_interface.py\", line 72, in get_llm_resp_ws\n    async for text in model_func(\n  File \"/app/api/llm_clients/_gemini.py\", line 100, in chat_stream\n    async for token in await model.generate_content_async(\n  File \"/usr/local/lib/python3.10/site-packages/google/generativeai/generative_models.py\", line 379, in generate_content_async\n    iterator = await self._async_client.stream_generate_content(\n  File \"/usr/local/lib/python3.10/site-packages/google/api_core/retry/retry_unary_async.py\", line 230, in retry_wrapped_func\n    return await retry_target(\n  File \"/usr/local/lib/python3.10/site-packages/google/api_core/retry/retry_unary_async.py\", line 160, in retry_target\n    _retry_error_helper(\n  File \"/usr/local/lib/python3.10/site-packages/google/api_core/retry/retry_base.py\", line 212, in _retry_error_helper\n    raise final_exc from source_exc\n  File \"/usr/local/lib/python3.10/site-packages/google/api_core/retry/retry_unary_async.py\", line 155, in retry_target\n    return await target()\n  File \"/usr/local/lib/python3.10/site-packages/google/api_core/grpc_helpers_async.py\", line 178, in error_remapped_callable\n    await call.wait_for_connection()\n  File \"/usr/local/lib/python3.10/site-packages/google/api_core/grpc_helpers_async.py\", line 79, in wait_for_connection\n    raise exceptions.from_grpc_error(rpc_error) from rpc_error\ngoogle.api_core.exceptions.InvalidArgument: 400 Developer instruction is not enabled for models/gemini-1.5-flash-latest\n", "labels": {"request_id": "1de404ef-9b67-4f8c-a557-4a505b1c5e1b", "tenant": "default", "project": "device-heaven"}}

@meganano202
Copy link
Author

meganano202 commented Jan 8, 2025

We just started seeing a 400 today as well, unsure if related but this is what we are getting:

{"timestamp": "2025-01-08T19:55:35.279861", "logger": "api.main", "level": "ERROR", "message": "(CLOUD) true, 2025-01-08T19:55:35.279869, Uncaught Error in Ecomm Chat!!!: 400 Developer instruction is not enabled for models/gemini-1.5-flash-latest. Traceback: Traceback (most recent call last):\n  File \"/app/api/main.py\", line 196, in ecommerce_ws\n    chat_success = await _ecomm_chat_ws(\n  File \"/app/api/main.py\", line 174, in _ecomm_chat_ws\n    success, error_msg = await ecomm_chat.handle_chat_interaction()\n  File \"/app/api/chatting/ecommerce/ecommerce_chat.py\", line 303, in handle_chat_interaction\n    ai_resp = await self.second_stage_conversation(\n  File \"/app/api/chatting/ecommerce/ecommerce_chat.py\", line 217, in second_stage_conversation\n    ai_resp = await self.send_llm_text_response()\n  File \"/app/api/chatting/base_chat_interface.py\", line 125, in send_llm_text_response\n    async for token in self.get_llm_resp_ws():\n  File \"/app/api/chatting/base_chat_interface.py\", line 72, in get_llm_resp_ws\n    async for text in model_func(\n  File \"/app/api/llm_clients/_gemini.py\", line 100, in chat_stream\n    async for token in await model.generate_content_async(\n  File \"/usr/local/lib/python3.10/site-packages/google/generativeai/generative_models.py\", line 379, in generate_content_async\n    iterator = await self._async_client.stream_generate_content(\n  File \"/usr/local/lib/python3.10/site-packages/google/api_core/retry/retry_unary_async.py\", line 230, in retry_wrapped_func\n    return await retry_target(\n  File \"/usr/local/lib/python3.10/site-packages/google/api_core/retry/retry_unary_async.py\", line 160, in retry_target\n    _retry_error_helper(\n  File \"/usr/local/lib/python3.10/site-packages/google/api_core/retry/retry_base.py\", line 212, in _retry_error_helper\n    raise final_exc from source_exc\n  File \"/usr/local/lib/python3.10/site-packages/google/api_core/retry/retry_unary_async.py\", line 155, in retry_target\n    return await target()\n  File \"/usr/local/lib/python3.10/site-packages/google/api_core/grpc_helpers_async.py\", line 178, in error_remapped_callable\n    await call.wait_for_connection()\n  File \"/usr/local/lib/python3.10/site-packages/google/api_core/grpc_helpers_async.py\", line 79, in wait_for_connection\n    raise exceptions.from_grpc_error(rpc_error) from rpc_error\ngoogle.api_core.exceptions.InvalidArgument: 400 Developer instruction is not enabled for models/gemini-1.5-flash-latest\n", "labels": {"request_id": "1de404ef-9b67-4f8c-a557-4a505b1c5e1b", "tenant": "default", "project": "device-heaven"}}

I tried to search in my logs but didnt find anything. Am I searching in the right website?

Edit:

I finally found the logs:

{"protoPayload":{"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":5,"message":"Cannot find metric(s) that match type = \"generativelanguage.googleapis.com/quota/predict_requests_per_model/usage\" label = limit_name. If a metric was created recently, it could take up to 10 minutes to become available. Please try again soon."},"requestMetadata":{"callerSuppliedUserAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36,gzip(gfe),gzip(gfe)"},"serviceName":"monitoring.googleapis.com","methodName":"google.monitoring.v3.MetricService.ListTimeSeries","authorizationInfo":[{"permission":"monitoring.timeSeries.list","granted":true}],"request":{"interval":{"startTime":"2025-01-09T06:57:44.900934Z","endTime":"2025-01-09T07:07:44.900934Z"},"@type":"type.googleapis.com/google.monitoring.v3.ListTimeSeriesRequest","filter":"resource.type=\"generativelanguage.googleapis.com/Location\" AND metric.type=\"generativelanguage.googleapis.com/quota/predict_requests_per_model/usage\" AND metric.label.limit_name=\"PredictRequestsPerMinutePerProjectPerModel\""}},"resource":{"type":"audited_resource","labels":{"method":"google.monitoring.v3.MetricService.ListTimeSeries","service":"monitoring.googleapis.com"}},"timestamp":"2025-01-09T07:07:44.912385502Z","severity":"ERROR"}

The error message is "Cannot find metric(s) that match type = \"generativelanguage.googleapis.com/quota/predict_requests_per_model/usage\" label = limit_name. If a metric was created recently, it could take up to 10 minutes to become available. Please try again soon."

Edit 2:

If you need more information, I'm using the model gemini-1.5-flash in Python 3.10.6 and google-generativeai version is 0.8.3

@gmKeshari gmKeshari added type:bug Something isn't working status:triaged Issue/PR triaged to the corresponding sub-team component:python sdk Issue/PR related to Python SDK labels Jan 9, 2025
@popov-ig
Copy link

I faced the same error, although for text requests.

Behavior:

  1. Created a cache,
  2. Instantiated a model,
  3. Call of model with generate_content method caused error
InvalidArgument: 400 CachedContent can not be used with GenerateContent request setting system_instruction, tools or tool_config. Proposed fix: move those values to CachedContent from GenerateContent request.

I have checked all the possible reason:
✅ Does app's code have recent changes? Yes, BUT I rolled back those changes and still have the same error.
✅ Does client package have recent changes? Nope, the last one was made in Oct 2024, see here
✅ Does app's data same? Yes, I have tried with different test payloads, and can easily reproduce error.

🤔 So, it smells like a bug on a server-side (Gemini API).

✍️ I also submitted a comment in corresponding Dev's forum branch.

❗Waiting for developer's response, because this error reproduce for 100% requests, so, it actually blocks our app 🛑.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:python sdk Issue/PR related to Python SDK status:triaged Issue/PR triaged to the corresponding sub-team type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants