AI_APICallError: tool_use ids were found without tool_result blocks immediately after #1139

Open
opened 2026-02-16 17:29:36 -05:00 by yindo · 11 comments
Owner

Originally created by @ShamanicArts on GitHub (Aug 6, 2025).

Originally assigned to: @rekram1-node on GitHub.

On claude pro - sonnet 4

AI_APICallError: messages.13:
`tool_use` ids were found without
`tool_result` blocks immediately
after:
toolu_01CfJCsh21fK1pAXsXWYJYBA,
toolu_01NoqnwsaxoK3AYM2FyrxmjN.
Each `tool_use` block must have a
corresponding `tool_result` block
in the next message.

happpens regularly . conversation cannot be continued without switching to a different model

https://opencode.ai/s/gkaS8vZY

ubuntu via WSL

Originally created by @ShamanicArts on GitHub (Aug 6, 2025). Originally assigned to: @rekram1-node on GitHub. On claude pro - sonnet 4 ``` AI_APICallError: messages.13: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01CfJCsh21fK1pAXsXWYJYBA, toolu_01NoqnwsaxoK3AYM2FyrxmjN. Each `tool_use` block must have a corresponding `tool_result` block in the next message. ``` happpens regularly . conversation cannot be continued without switching to a different model https://opencode.ai/s/gkaS8vZY ubuntu via WSL
Author
Owner

@AnsgarH1 commented on GitHub (Aug 18, 2025):

I also got the error on MacOS with OpenCode v0.5.5

@AnsgarH1 commented on GitHub (Aug 18, 2025): I also got the error on MacOS with OpenCode v0.5.5
Author
Owner

@rekram1-node commented on GitHub (Aug 18, 2025):

did this happen after an abort or something? Like you aborted a request then tried to continue convo?

@rekram1-node commented on GitHub (Aug 18, 2025): did this happen after an abort or something? Like you aborted a request then tried to continue convo?
Author
Owner

@ShamanicArts commented on GitHub (Aug 18, 2025):

did this happen after an abort or something? Like you aborted a request then tried to continue convo?

this commonly seems to be a trigger, but is not the sole trigger. it can occur randomly. it can be mitigated by undoing to the message before the message which triggers this error

@ShamanicArts commented on GitHub (Aug 18, 2025): > did this happen after an abort or something? Like you aborted a request then tried to continue convo? this commonly seems to be a trigger, but is not the sole trigger. it can occur randomly. it can be mitigated by undoing to the message before the message which triggers this error
Author
Owner

@esafak commented on GitHub (Aug 29, 2025):

I am getting this error on 0.5.28 with opus 4.1 as the planning agent. I exited and restarted opencode and the problem persisted after resuming the session.

I suspect there is 'corruption' in the history as I can also trigger this error by running /compact after it occurs.

@esafak commented on GitHub (Aug 29, 2025): I am getting this error on 0.5.28 with opus 4.1 as the planning agent. I exited and restarted opencode and the problem persisted after resuming the session. I suspect there is 'corruption' in the history as I can also trigger this error by running `/compact` after it occurs.
Author
Owner

@namchuai commented on GitHub (Nov 21, 2025):

I'm also faced this issue

messages.453: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01BmQLHErsVFKDSd51CUnUXg. Each `tool_use` block must have a corresponding `tool_result` block in the next message.

Edit 1:
Switching other model (to Claude Opus 4.1) does not help.

@namchuai commented on GitHub (Nov 21, 2025): I'm also faced this issue ``` messages.453: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01BmQLHErsVFKDSd51CUnUXg. Each `tool_use` block must have a corresponding `tool_result` block in the next message. ``` Edit 1: Switching other model (to Claude Opus 4.1) does not help.
Author
Owner

@rekram1-node commented on GitHub (Nov 21, 2025):

Yeah this is a bug with the anthropic api itself it sends back duplicate content or something and messes up the state of the client.

We can fix it on our end its just a little messy reordering things all the time

@rekram1-node commented on GitHub (Nov 21, 2025): Yeah this is a bug with the anthropic api itself it sends back duplicate content or something and messes up the state of the client. We can fix it on our end its just a little messy reordering things all the time
Author
Owner

@sawy3r commented on GitHub (Dec 15, 2025):

I'm also facing this one, it's happening across at least Sonnet 4, Sonnet 4.5 and Opus 4.5. I'm seeing it when the agent reads a pdf file (in the same project). Once this happens it corrupts the conversation, I need to undo the prompt that caused it, and can then continue, but to no avail to read the PDF and get past that point. Switching to a non-Anthropic model of course enables it to proceed (as the error is being returned from the Anthropic API). I can then switch back to the Anthropic model and continue, so there is a workaround albeit not ideal!

Running opencode binary version 1.0.157 on MacOS

@sawy3r commented on GitHub (Dec 15, 2025): I'm also facing this one, it's happening across at least Sonnet 4, Sonnet 4.5 and Opus 4.5. I'm seeing it when the agent reads a pdf file (in the same project). Once this happens it corrupts the conversation, I need to undo the prompt that caused it, and can then continue, but to no avail to read the PDF and get past that point. Switching to a non-Anthropic model of course enables it to proceed (as the error is being returned from the Anthropic API). I can then switch back to the Anthropic model and continue, so there is a workaround albeit not ideal! Running opencode binary version 1.0.157 on MacOS
Author
Owner

@rekram1-node commented on GitHub (Dec 16, 2025):

@sawy3r now that's interesting would u be able to share your session reproducing that?

opencode export > session.json

@rekram1-node commented on GitHub (Dec 16, 2025): @sawy3r now that's interesting would u be able to share your session reproducing that? `opencode export > session.json`
Author
Owner

@sawy3r commented on GitHub (Dec 17, 2025):

@sawy3r now that's interesting would u be able to share your session reproducing that?

opencode export > session.json

Sure can!

See attached, I've redacted it slightly and truncated the PDF base64 data that was included (I've also attached the PDF for your reference as well. It happens with any I try at the moment).
I set this session up to attempt to replicate it, and it happened right away at the first prompt, where I asked the agent to read a PDF.

sessionNew-redacted.json
AI_APICallError_ tool_use ids were found without tool_result blocks immediately after · Issue #1662 · sst_opencode.pdf

@sawy3r commented on GitHub (Dec 17, 2025): > [@sawy3r](https://github.com/sawy3r) now that's interesting would u be able to share your session reproducing that? > > `opencode export > session.json` Sure can! See attached, I've redacted it slightly and truncated the PDF base64 data that was included (I've also attached the PDF for your reference as well. It happens with any I try at the moment). I set this session up to attempt to replicate it, and it happened right away at the first prompt, where I asked the agent to read a PDF. [sessionNew-redacted.json](https://github.com/user-attachments/files/24223762/sessionNew-redacted.json) [AI_APICallError_ `tool_use` ids were found without `tool_result` blocks immediately after · Issue #1662 · sst_opencode.pdf](https://github.com/user-attachments/files/24223761/AI_APICallError_.tool_use.ids.were.found.without.tool_result.blocks.immediately.after.Issue.1662.sst_opencode.pdf)
Author
Owner

@tagpro commented on GitHub (Dec 20, 2025):

ctrl+x u will undo the previous message. Undo until the error message disappears from the chat. This can happen when a message response was interrupted and the result from the message wasn't created. So, undo until chat history is at a good stage and then continue again.

@tagpro commented on GitHub (Dec 20, 2025): `ctrl+x u` will undo the previous message. Undo until the error message disappears from the chat. This can happen when a message response was interrupted and the result from the message wasn't created. So, undo until chat history is at a good stage and then continue again.
Author
Owner

@soapergem commented on GitHub (Feb 6, 2026):

I'm also getting this same error quite a lot lately, on Claude Sonnet 4.5

@soapergem commented on GitHub (Feb 6, 2026): I'm also getting this same error quite a lot lately, on Claude Sonnet 4.5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1139