fix: anthropic tool sanitation (#9310)

This commit is contained in:
Ari Webb
2026-02-05 16:31:12 -08:00
committed by Caren Thomas
parent 6f746c5225
commit 85ee7ed7b4
3 changed files with 33 additions and 4 deletions

View File

@@ -524,7 +524,17 @@ def openai_chat_completions_request(
log_event(name="llm_request_sent", attributes=data)
chat_completion = client.chat.completions.create(**data)
log_event(name="llm_response_received", attributes=chat_completion.model_dump())
return ChatCompletionResponse(**chat_completion.model_dump())
response = ChatCompletionResponse(**chat_completion.model_dump())
# Override tool_call IDs to ensure cross-provider compatibility (matches streaming path behavior)
# Some models (e.g. Kimi via OpenRouter) generate IDs like 'Read:93' which violate Anthropic's pattern
for choice in response.choices:
if choice.message.tool_calls:
for tool_call in choice.message.tool_calls:
if tool_call.id is not None:
tool_call.id = get_tool_call_id()
return response
def prepare_openai_payload(chat_completion_request: ChatCompletionRequest):