#Unexpected Error from Claude with Tool Use

6 messages · Page 1 of 1 (latest)

edgy turtle
#

I'm getting the following error message bubbling through to OpenRouter when I try to send a request to Claude that contains a function call output. I've created a simple script to replicate the issue as well. What am I doing wrong here?

Error:

message: Provider returned error
error: {
  "code": 400,
  "message": "Provider returned error",
  "metadata": {
    "raw": "{\"message\":\"messages.0.content.1: unexpected `tool_use_id` found in `tool_result` blocks: toolu_synthetic_repro_001. Each `tool_result` block must have a corresponding `tool_use` block in the previous message.\"}",
    "provider_name": "Amazon Bedrock",
    "is_byok": false
  }
}

I've attached the script to reproduce the issue. Just run npx tsx repro-openrouter.ts in a TS environment to see it.

eager egret
#

I'm seeing the same thing, and have a simpler reproduction with curl:

curl https://openrouter.ai/api/v1/responses \
  -H "Authorization: Bearer $OPENROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary "@request.json"

request.json:

{
  "input": [
    {
      "type": "message",
      "role": "user",
      "content": "Write a program to print 1 to 10 in Python and then execute it in the sandbox"
    },
    {
      "type": "function_call",
      "arguments": "{\"command\": \"python3 - <<'EOF'\\nfor i in range(1, 11):\\n    print(i)\\nEOF\"}",
      "call_id": "toolu_019HqPQBp1GgTY9LGvygk999",
      "name": "exec_bash",
      "id": "fc_tmp_1oxhsr20bz",
      "status": "completed"
    },
    {
      "type": "function_call_output",
      "call_id": "toolu_019HqPQBp1GgTY9LGvygk999",
      "output": "some result here",
      "id": "fc_tmp_1oxhsr20bz",
      "status": "completed"
    }
  ],
  "model": "anthropic/claude-4.6-sonnet",
  "tools": [
    {
      "type": "function",
      "name": "exec_bash",
      "parameters": {
        "additionalProperties": false,
        "properties": {
          "command": {
            "type": "string"
          }
        },
        "required": [
          "command"
        ],
        "type": "object"
      },
      "strict": true,
      "description": "Run a bash command in a persistent sandbox."
    }
  ]
}

This was working fine a few weeks ago.

#

<@&1384697330254610442>

strange portal
#

hey thanks for reporting this! I've found the root cause and will have the fix out soon

edgy turtle
#

@eager egret in the meantime, I've found that injecting an assistant message with an empty string for the content BEFORE the function_call message works. Certianly not an ideal solution, but it works if you need this before @strange portal has a fix out.

strange portal