Skip to content

Invalid tool_use.id format during session resume causes API 400 error #856

@naidanLuo

Description

@naidanLuo

claude-agent-sdk version 0.1.61


Bug: SDK generates invalid tool_use.id during session resume

Problem

The Claude Agent SDK generates tool_use.id values in the format functions.{ToolName}:{N}
(e.g., functions.AskUserQuestion:1), which contain . and : characters that violate the API's
validation pattern ^[a-zA-Z0-9_-]+$. On session resume, these historical messages are
replayed verbatim, causing a 400 error.

Evidence

API error:
messages.7.content.1.tool_use.id: String should match pattern '^[a-zA-Z0-9_-]+$'

Invalid IDs found in request body (captured via LLM proxy):
functions.AskUserQuestion:1 — contains '.' and ':'
functions.AskUserQuestion:2 — contains '.' and ':'
functions.AskUserQuestion:4 — contains '.' and ':'
functions.AskUserQuestion:5 — contains '.' and ':'

Valid IDs from the same session (different code path):
call_360410d3f1444f978a42a482 — valid
call_5d86f36491e247039a0aec00 — valid

Failing message (messages[7]):
{
"role": "assistant",
"content": [
{"type": "text", "text": "..."},
{"type": "tool_use", "id": "functions.AskUserQuestion:1", "name": "AskUserQuestion",
"input": {...}}
]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions