Session turns keeps resulting in AI_APICallError: Bad Request #1813

Closed
opened 2026-02-16 17:32:45 -05:00 by yindo · 7 comments
Owner

Originally created by @paymog on GitHub (Sep 24, 2025).

Originally assigned to: @rekram1-node on GitHub.

Trying out opencode for the first time. Using grok-fast-1 as the primary model. I'm finding that my session keeps resulting in AI_APICallError: Bad Request

Image

This persists even if I change models, or relaunch opencode and resume the session. I've tried launching with --print-logs but that doesn't show anything helpful

 ❯❯❯ opencode --print-logs
INFO  2025-09-24T17:06:10 +58ms service=default version=0.11.1 args=["--print-logs"] opencode
INFO  2025-09-24T17:06:10 +1ms service=project directory=/Users/paymahn/code/goldsky/graph-tools fromDirectory
INFO  2025-09-24T17:06:11 +77ms service=config path=/Users/paymahn/.config/opencode/config.json loading
INFO  2025-09-24T17:06:11 +0ms service=config path=/Users/paymahn/.config/opencode/opencode.json loading
INFO  2025-09-24T17:06:11 +1ms service=config path=/Users/paymahn/.config/opencode/opencode.jsonc loading
INFO  2025-09-24T17:06:11 +1ms service=plugin path=opencode-copilot-auth@0.0.2 loading plugin
INFO  2025-09-24T17:06:11 +8ms service=plugin path=opencode-anthropic-auth@0.0.2 loading plugin
INFO  2025-09-24T17:06:11 +27ms service=bus type=* subscribing
INFO  2025-09-24T17:06:11 +0ms service=bus type=session.updated subscribing
INFO  2025-09-24T17:06:11 +0ms service=bus type=message.updated subscribing
INFO  2025-09-24T17:06:11 +0ms service=bus type=message.part.updated subscribing
INFO  2025-09-24T17:06:11 +0ms service=format init
INFO  2025-09-24T17:06:11 +0ms service=bus type=file.edited subscribing
INFO  2025-09-24T17:06:11 +1ms service=lsp serverIds=typescript, vue, eslint, gopls, ruby-lsp, pyright, elixir-ls, zls, csharp, rust, clangd, svelte enabled LSP servers
INFO  2025-09-24T17:06:11 +1ms service=models.dev file={} refreshing
INFO  2025-09-24T17:06:11 +2ms service=provider init
INFO  2025-09-24T17:06:11 +1ms service=provider providerID=opencode found
INFO  2025-09-24T17:06:11 +0ms service=provider providerID=anthropic found
INFO  2025-09-24T17:06:11 +6ms service=default cmd=["/Users/paymahn/.cache/opencode/tui/tui-bkrzpvzm."] tui
INFO  2025-09-24T17:06:11 +58ms service=server method=GET path=/agent request
INFO  2025-09-24T17:06:11 +2ms service=server duration=2 response
INFO  2025-09-24T17:06:11 +0ms service=server method=GET path=/project/current request
INFO  2025-09-24T17:06:11 +1ms service=server duration=1 response
INFO  2025-09-24T17:06:11 +0ms service=server method=GET path=/path request
INFO  2025-09-24T17:06:11 +0ms service=server duration=0 response
INFO  2025-09-24T17:06:11 +2ms service=server method=GET path=/config request
INFO  2025-09-24T17:06:11 +0ms service=server duration=0 response
INFO  2025-09-24T17:06:11 +7ms service=server method=GET path=/command request
INFO  2025-09-24T17:06:11 +0ms service=server duration=0 response
INFO  2025-09-24T17:06:11 +1ms service=server method=GET path=/file/status request
INFO  2025-09-24T17:06:11 +1ms service=tui commands={"agent_cycle":{},"agent_cycle_reverse":{},"agent_list":{},"app_exit":{},"app_help":{},"editor_open":{},"input_clear":{},"input_newline":{},"input_paste":{},"input_submit":{},"messages_copy":{},"messages_first":{},"messages_half_page_down":{},"messages_half_page_up":{},"messages_last":{},"messages_page_down":{},"messages_page_up":{},"messages_redo":{},"messages_undo":{},"model_cycle_recent":{},"model_cycle_recent_reverse":{},"model_list":{},"project_init":{},"session_child_cycle":{},"session_child_cycle_reverse":{},"session_compact":{},"session_export":{},"session_interrupt":{},"session_list":{},"session_new":{},"session_share":{},"session_timeline":{},"session_unshare":{},"theme_list":{},"thinking_blocks":{},"tool_details":{}} Loaded commands
                                                                                                                                                                                           INFO  2025-09-24T17:06:11 +0ms service=server method=GET path=/event request
                                                         INFO  2025-09-24T17:06:11 +0ms service=server event connected
                                                                                                                      INFO  2025-09-24T17:06:11 +1ms service=bus type=* subscribing
                                                                                                                                                                                   INFO  2025-09-24T17:06:11 +1ms service=server duration=2 response
                                      INFO  2025-09-24T17:06:11 +1ms service=server method=GET path=/tui/control/next request
                                                                                                                             INFO  2025-09-24T17:06:11 +4ms service=server method=GET path=/config/providers request
      INFO  2025-09-24T17:06:11 +1ms service=server duration=1 response
INFO  2025-09-24T17:08:17 +101836ms service=bus type=* unsubscribing
INFO  2025-09-24T17:08:17 +0ms service=server event disconnected

One thing that looks suspicious is that it seems opencode is trying to send my tsbuild.info file to the LLM. I don't quite know how to scroll in the TUI or how else to verify, but I see output like this which is suspicious

Image

Note that this AI_APICallError: Bad Request happened earlier and I don't know how I got it unstuck but now it's stuck again.

Originally created by @paymog on GitHub (Sep 24, 2025). Originally assigned to: @rekram1-node on GitHub. Trying out opencode for the first time. Using grok-fast-1 as the primary model. I'm finding that my session keeps resulting in `AI_APICallError: Bad Request` <img width="500" height="334" alt="Image" src="https://github.com/user-attachments/assets/f39c489a-8d5f-4edc-9056-e1088556bb41" /> This persists even if I change models, or relaunch opencode and resume the session. I've tried launching with `--print-logs` but that doesn't show anything helpful ``` ❯❯❯ opencode --print-logs INFO 2025-09-24T17:06:10 +58ms service=default version=0.11.1 args=["--print-logs"] opencode INFO 2025-09-24T17:06:10 +1ms service=project directory=/Users/paymahn/code/goldsky/graph-tools fromDirectory INFO 2025-09-24T17:06:11 +77ms service=config path=/Users/paymahn/.config/opencode/config.json loading INFO 2025-09-24T17:06:11 +0ms service=config path=/Users/paymahn/.config/opencode/opencode.json loading INFO 2025-09-24T17:06:11 +1ms service=config path=/Users/paymahn/.config/opencode/opencode.jsonc loading INFO 2025-09-24T17:06:11 +1ms service=plugin path=opencode-copilot-auth@0.0.2 loading plugin INFO 2025-09-24T17:06:11 +8ms service=plugin path=opencode-anthropic-auth@0.0.2 loading plugin INFO 2025-09-24T17:06:11 +27ms service=bus type=* subscribing INFO 2025-09-24T17:06:11 +0ms service=bus type=session.updated subscribing INFO 2025-09-24T17:06:11 +0ms service=bus type=message.updated subscribing INFO 2025-09-24T17:06:11 +0ms service=bus type=message.part.updated subscribing INFO 2025-09-24T17:06:11 +0ms service=format init INFO 2025-09-24T17:06:11 +0ms service=bus type=file.edited subscribing INFO 2025-09-24T17:06:11 +1ms service=lsp serverIds=typescript, vue, eslint, gopls, ruby-lsp, pyright, elixir-ls, zls, csharp, rust, clangd, svelte enabled LSP servers INFO 2025-09-24T17:06:11 +1ms service=models.dev file={} refreshing INFO 2025-09-24T17:06:11 +2ms service=provider init INFO 2025-09-24T17:06:11 +1ms service=provider providerID=opencode found INFO 2025-09-24T17:06:11 +0ms service=provider providerID=anthropic found INFO 2025-09-24T17:06:11 +6ms service=default cmd=["/Users/paymahn/.cache/opencode/tui/tui-bkrzpvzm."] tui INFO 2025-09-24T17:06:11 +58ms service=server method=GET path=/agent request INFO 2025-09-24T17:06:11 +2ms service=server duration=2 response INFO 2025-09-24T17:06:11 +0ms service=server method=GET path=/project/current request INFO 2025-09-24T17:06:11 +1ms service=server duration=1 response INFO 2025-09-24T17:06:11 +0ms service=server method=GET path=/path request INFO 2025-09-24T17:06:11 +0ms service=server duration=0 response INFO 2025-09-24T17:06:11 +2ms service=server method=GET path=/config request INFO 2025-09-24T17:06:11 +0ms service=server duration=0 response INFO 2025-09-24T17:06:11 +7ms service=server method=GET path=/command request INFO 2025-09-24T17:06:11 +0ms service=server duration=0 response INFO 2025-09-24T17:06:11 +1ms service=server method=GET path=/file/status request INFO 2025-09-24T17:06:11 +1ms service=tui commands={"agent_cycle":{},"agent_cycle_reverse":{},"agent_list":{},"app_exit":{},"app_help":{},"editor_open":{},"input_clear":{},"input_newline":{},"input_paste":{},"input_submit":{},"messages_copy":{},"messages_first":{},"messages_half_page_down":{},"messages_half_page_up":{},"messages_last":{},"messages_page_down":{},"messages_page_up":{},"messages_redo":{},"messages_undo":{},"model_cycle_recent":{},"model_cycle_recent_reverse":{},"model_list":{},"project_init":{},"session_child_cycle":{},"session_child_cycle_reverse":{},"session_compact":{},"session_export":{},"session_interrupt":{},"session_list":{},"session_new":{},"session_share":{},"session_timeline":{},"session_unshare":{},"theme_list":{},"thinking_blocks":{},"tool_details":{}} Loaded commands INFO 2025-09-24T17:06:11 +0ms service=server method=GET path=/event request INFO 2025-09-24T17:06:11 +0ms service=server event connected INFO 2025-09-24T17:06:11 +1ms service=bus type=* subscribing INFO 2025-09-24T17:06:11 +1ms service=server duration=2 response INFO 2025-09-24T17:06:11 +1ms service=server method=GET path=/tui/control/next request INFO 2025-09-24T17:06:11 +4ms service=server method=GET path=/config/providers request INFO 2025-09-24T17:06:11 +1ms service=server duration=1 response INFO 2025-09-24T17:08:17 +101836ms service=bus type=* unsubscribing INFO 2025-09-24T17:08:17 +0ms service=server event disconnected ``` One thing that looks suspicious is that it seems opencode is trying to send my tsbuild.info file to the LLM. I don't quite know how to scroll in the TUI or how else to verify, but I see output like this which is suspicious <img width="2943" height="1165" alt="Image" src="https://github.com/user-attachments/assets/07131b3d-8b90-4c88-ad40-58587e3bbd8a" /> Note that this `AI_APICallError: Bad Request` happened earlier and I don't know how I got it unstuck but now it's stuck again.
yindo closed this issue 2026-02-16 17:32:45 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Sep 24, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #494: AI_APICallError: Bad Request with Open Router - Similar error pattern with Bad Request failures during session
  • #678: All requests fail with "AI_APICallError: Bad Request" - Identical error message and behavior with GitHub Copilot provider
  • #1282: Copilot models respond with AI_APICallError: Bad Request after a quick chat - Same error occurs after some chat interaction, affects multiple models including grok variants
  • #537: 400 Bad Request when busy - Related Bad Request errors during active sessions

The pattern of persistent Bad Request errors even after model changes and session restarts matches these existing reports. The mention of tsbuild.info file being sent to the LLM might also be related to context/file handling issues reported in similar cases.

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Sep 24, 2025): This issue might be a duplicate of existing issues. Please check: - #494: AI_APICallError: Bad Request with Open Router - Similar error pattern with Bad Request failures during session - #678: All requests fail with "AI_APICallError: Bad Request" - Identical error message and behavior with GitHub Copilot provider - #1282: Copilot models respond with AI_APICallError: Bad Request after a quick chat - Same error occurs after some chat interaction, affects multiple models including grok variants - #537: 400 Bad Request when busy - Related Bad Request errors during active sessions The pattern of persistent Bad Request errors even after model changes and session restarts matches these existing reports. The mention of tsbuild.info file being sent to the LLM might also be related to context/file handling issues reported in similar cases. Feel free to ignore if none of these address your specific case.
Author
Owner

@rekram1-node commented on GitHub (Sep 24, 2025):

@paymog yeah it looks like you probably have a message in context that is too big. Once that happens the only way currently to fix is to use /undo to revert until you have reverted problematic message and then continue

You could also ofc start a fresh session, can you maybe share the session causing issue?

Is the agent reading tsbuild.info or are you @ referencing it into context? Maybe consider putting in AGENTS.md telling llm to not read it

@rekram1-node commented on GitHub (Sep 24, 2025): @paymog yeah it looks like you probably have a message in context that is too big. Once that happens the only way currently to fix is to use /undo to revert until you have reverted problematic message and then continue You could also ofc start a fresh session, can you maybe share the session causing issue? Is the agent reading `tsbuild.info` or are you @ referencing it into context? Maybe consider putting in AGENTS.md telling llm to not read it
Author
Owner

@paymog commented on GitHub (Sep 24, 2025):

Ah gotcha. Ok i'll try reverting and/or starting a new session. I don't think I can share teh session publicly becuase i'm using opencode with a private repo.

I didn't reference tsbuild.info myself, I suspect it added to the context when opencode used grep or something similar.

@paymog commented on GitHub (Sep 24, 2025): Ah gotcha. Ok i'll try reverting and/or starting a new session. I don't think I can share teh session publicly becuase i'm using opencode with a private repo. I didn't reference tsbuild.info myself, I suspect it added to the context when opencode used grep or something similar.
Author
Owner

@rekram1-node commented on GitHub (Sep 24, 2025):

Yeah we try to limit output of read tool but I think we don't properly handle the case if all the content is on 1 line in the file

but we should fix that

@rekram1-node commented on GitHub (Sep 24, 2025): Yeah we try to limit output of read tool but I think we don't properly handle the case if all the content is on 1 line in the file but we should fix that
Author
Owner

@paymog commented on GitHub (Sep 24, 2025):

would be neat if opencode could also by default ignore gitignored files or something like that

@paymog commented on GitHub (Sep 24, 2025): would be neat if opencode could also by default ignore gitignored files or something like that
Author
Owner

@rekram1-node commented on GitHub (Sep 24, 2025):

it does do that but the llm can still discover rhem using bash commands and just trying reads on random paths

the list and grep both use ripgrep under hood which respects gitigore

@rekram1-node commented on GitHub (Sep 24, 2025): it does do that but the llm can still discover rhem using bash commands and just trying reads on random paths the list and grep both use ripgrep under hood which respects gitigore
Author
Owner

@rekram1-node commented on GitHub (Sep 30, 2025):

going to close since this just seems like too much context was injected

@rekram1-node commented on GitHub (Sep 30, 2025): going to close since this just seems like too much context was injected
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1813