Skip to content

Session turns keeps resulting in AI_APICallError: Bad Request #2764

Closed

Description

@paymog

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.

Activity

  1. github-actions commented on Sep 24, 2025

    @github-actions
    Contributor

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

    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.

  2. rekram1-node commented on Sep 24, 2025

    @rekram1-node
    Contributor

    @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

  3. self-assigned this
    on Sep 24, 2025
  4. paymog commented on Sep 24, 2025

    @paymog
    Author

    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.

  5. rekram1-node commented on Sep 24, 2025

    @rekram1-node
    Contributor

    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

  6. paymog commented on Sep 25, 2025

    @paymog
    Author

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

  7. rekram1-node commented on Sep 25, 2025

    @rekram1-node
    Contributor

    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

  8. rekram1-node commented on Sep 30, 2025

    @rekram1-node
    Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions