gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

Code 400

Open JuhanV opened this issue 1 year ago • 15 comments

What happened?

✕ [API Error: [{ "error": { "code": 400, "message": "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn.", "errors": [ { "message": "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn.", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" } } ]]

What did you expect to happen?

make a plan

Client information

  • CLI Version: 0.1.9
  • Git Commit: N/A
  • Operating System: win32 v22.16.0
  • Sandbox Environment: no sandbox
  • Model Version: gemini-2.5-pro
  • Memory Usage: 144.3 MB

Login information

No response

Anything else we need to know?

No response

JuhanV avatar Jul 03 '25 14:07 JuhanV

Hmmm that's unfortunate a few questions:

  1. Are you able to reproduce regularly by chance?
  2. Do you recall what happened prior to you getting this error?
  3. What's the output of your /about in Gemini CLI?

NTaylorMullen avatar Jul 03 '25 14:07 NTaylorMullen

Hmmm that's unfortunate a few questions:

1. Are you able to reproduce regularly by chance? 

2. Do you recall what happened prior to you getting this error?

3. What's the output of your `/about` in Gemini CLI?It began after I cancelled an action.  
  1. It happens quite often. Most likely I can yes.
  2. It was requesting to create to create some directories and move some files. I told it no. I asked it to explain the reasoning behind what it was doing. At that time is when the Code 400 loop began. I then cancelled the loop.
  3. The about shows 2.5-flash, but it started happening under 2.5-pro, during the loop it switched over to flash. About Gemini CLI │ │ │ │ CLI Version 0.1.7 │ │ Git Commit 55cc809 │ │ Model gemini-2.5-flash │ │ Sandbox no sandbox │ │ OS win32 │ │ Auth Method OAuth

shawnhale avatar Jul 03 '25 15:07 shawnhale

Looks like there is also a ton of info on this one here: https://github.com/google-gemini/gemini-cli/issues/1690

jackwotherspoon avatar Jul 03 '25 15:07 jackwotherspoon

Hey there! It seems to happen to me only after I try to interact with Google CLI in any way. I can give it a whole .md plan and it spends 7 minutes making the app, but when I try to chat and say something after like, "Now fix this error that's happening" the " function response parts is equal to the number of function call parts of the function call turn" happens. I've tried out making three apps so far and that's been the pattern each time. Good luck!

dhstrom avatar Jul 03 '25 16:07 dhstrom

Yo, Google person that asked for us to post here in this thread, here's the error that's happening. I can develop an entire application, then when I ask it to fix something, the error always happens:

fix this error that's happening now:

Traceback (most recent call last):

PS C:\Personal Projects...> python run_curator.py

File "C:\Personal Projects...\run_curator.py", line 6, in

from ..core.database import EventData # Assuming EventData is accessible

from core.ai_processor import process_pending_posts

ImportError: attempted relative import beyond top-level package

File "C:\Personal Projects...\core\ai_processor.py", line 64, in

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

✦ I will now run the curator.

ℹ ⚡ Slow response times detected. Automatically switching from gemini-2.5-pro to gemini-2.5-flash for faster responses for the remainder of this session. ⚡ To avoid this you can either upgrade to Standard tier. See: https://goo.gle/set-up-gemini-code-assist ⚡ Or you can utilize a Gemini API Key. See: https://goo.gle/gemini-cli-docs-auth#gemini-api-key ⚡ You can switch authentication methods by typing /auth ✦ My apologies. It seems there was an issue with the last command. The traceback indicates an error. I will try to correct the command. It seems I was using the git config command incorrectly. I will now try to add the directory to the safe list using
the correct syntax.

I will now add the current directory to the git safe directories. This will prevent potential git-related errors. ✦ It seems you've pointed out an issue with the relative import in core/ai_processor.py.
You are correct. The import from ..core.database import EventData is incorrect for the
file structure. It should be from .database import EventData.

I will correct this now. First, I'll read the file. ✦ I see the ImportError. This is happening because of an incorrect relative import in one
of the core modules. The error attempted relative import beyond top-level package points
to an issue with how modules inside a package are importing each other when the main
script is run from outside the package.

The problematic import is from ..core.database import EventData inside core/ai_processor.py. It should be from .database import EventData to correctly reference the database module within the same core package.

I will correct this now. First, I'll read the file to ensure I'm editing the correct content. ✦ Please provide the error message you are encountering. I need to know what the error is
to help you fix it. ╭───────────────────────────────────────────────────────────────────────────────────────╮
│ ✔ Shell git config --global safe.directory "C:/Personal Projects/… │
╰───────────────────────────────────────────────────────────────────────────────────────╯

╭───────────────────────────────────╮ │ ✔ ReadFile core\ai_processor.py │ ╰───────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────╮
│ ✔ ReadFile run_curator.py │
│ │
│ (truncated) │
╰─────────────────────────────────────────────────────────────────────────────╯
╭───────────────────────────────────╮
│ ✔ ReadFile core\ai_processor.py │
╰───────────────────────────────────╯
╭─────────────────────────────────────────────────────────────────────────────╮ │ ✔ ReadFile run_curator.py │ │ │ │ (truncated) │ ╰─────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────╮ │ ✔ ReadFile run_curator.py │ ╰─────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────╮
│ ✔ Shell git config --global safe.directory "C:/Personal Projects/… │
╰───────────────────────────────────────────────────────────────────────────────────────╯
✦ It seems the issue is with how the run_curator.py script is being executed. When you have a package structure (like your core directory), you should run the main script as a module.

I understand. The error ImportError: attempted relative import beyond top-level package when running run_curator.py is due to the way Python handles imports when a script is executed directly.

Specifically, the line from ..core.database import EventData in core/ai_processor.py is causing the problem. When run_curator.py is executed, core is treated as a top-level package. The .. in the import statement tries to go "above" the core package, which is not allowed in this context.

The correct way to import EventData within core/ai_processor.py is to use an absolute import from the core package, like from core.database import EventData.

It appears there was an error in the core/ai_processor.py file that I created. The
error message indicates a problem with a relative import. I will correct the import
╭───────────────────────────────────╮ │ ✔ ReadFile core\ai_processor.py │ ╰───────────────────────────────────╯ ✦ statement. ╭───────────────────────────────────╮ │ ✔ ReadFile core\ai_processor.py │ ╰───────────────────────────────────╯ ✕ [API Error: [{ "error": { "code": 400, "message": "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn.", "errors": [ { "message": "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn.", "domain": "global", "reason": "badRequest"
}
], "status": "INVALID_ARGUMENT" } } ]]

✕ [API Error: [{ "error": { "code": 400, "message": "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn.", "errors": [ { "message": "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn.", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" } } ]]

✦ The ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pointing to from core.ai_processor import process_pending_posts in run_curator.py suggests that the issue is not with run_curator.py itself, but rather with the core/ai_processor.py module that it's trying to import. This often happens when there's a syntax error or an unhandled exception within the imported module that prevents it from being loaded successfully.

I will re-read the core/ai_processor.py file to inspect its contents and identify any potential issues. ╭───────────────────────────────────╮ │ ✔ ReadFile core\ai_processor.py │ ╰───────────────────────────────────╯ ✕ [API Error: [{ "error": { "code": 400, "message": "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn.", "errors": [ { "message": "Please ensure that the number of function response parts is equal
to the number of function call parts of the function call turn.", "domain": "global",
"reason": "badRequest"
}
], "status": "INVALID_ARGUMENT" } } ]]

dhstrom avatar Jul 04 '25 19:07 dhstrom

This happened for me after chatting just a little bit back and forth, it wanted to do some changes, i declined 3 changes in a row it wanted to do. Came back to computer an hour later to resume the chat, and now even just "hi" produces this error over and over.

nsanden avatar Jul 05 '25 15:07 nsanden

@dhstrom that's massively helpful thank you! It sounds like you're able to reproduce a bit. Would it be possible to do /chat save bug and then provide your ~/.gemini/tmp/<some big number, find the one with latest modified timestamp>/checkpoint-bug.json.

Note this will have all interaction information so make sure there's nothing unintentionally sensitive.

This should help me understand where/why things are falling over a bit more

NTaylorMullen avatar Jul 05 '25 18:07 NTaylorMullen

I was able to reproduce this. Repro steps:

Image

Working on a fix

NTaylorMullen avatar Jul 05 '25 19:07 NTaylorMullen

Here is another way to reproduce the same error.

  1. auth using API option. Send some messages and save the chat.
  2. Change auth to Google login
  3. resume the saved chat and send any message to get the error

ilkerhk avatar Jul 14 '25 13:07 ilkerhk

Here is another way to reproduce the same error.

  1. auth using API option. Send some messages and save the chat.
  2. Change auth to Google login
  3. resume the saved chat and send any message to get the error

Hmm I just tried this a few ways but can't reproduce. Would you mind sharing specific propts / experiences?

NTaylorMullen avatar Jul 14 '25 17:07 NTaylorMullen

Hmm I just tried this a few ways but can't reproduce. Would you mind sharing specific propts / experiences?

Below are the screenshots. First using API auth and saving chat (first screenshot), Then switching to Google login auth, resuming the saved chat, and it gives error (second screenshot)

Image Image

ilkerhk avatar Jul 14 '25 20:07 ilkerhk

(after saving etc.)

Image

Honestly quite confused....

NTaylorMullen avatar Jul 15 '25 05:07 NTaylorMullen

same (*。>Д<)o゜

Image

Wenbobobo avatar Jul 26 '25 02:07 Wenbobobo

@scidomino this may still be an issue ^

NTaylorMullen avatar Jul 27 '25 04:07 NTaylorMullen

Is this a single saved chat that's causing this or are you seeing this in new sessions?

scidomino avatar Jul 30 '25 21:07 scidomino