AlinsRan opened a new pull request, #13583:
URL: https://github.com/apache/apisix/pull/13583

   ### Description
   
   Two bugs in the Anthropic-to-OpenAI converter 
(`apisix/plugins/ai-protocols/converters/anthropic-messages-to-openai-chat.lua`):
   
   1. **`tool_choice` forwarded without `tools` → upstream 400.** `tool_choice` 
(and `parallel_tool_calls`) were sent to the OpenAI-compatible upstream even 
when **no tools** ended up in the request — either the client provided none, or 
all were dropped as Anthropic built-ins (e.g. `web_search`) / invalid. 
OpenAI-compatible upstreams reject `tool_choice` without `tools`. They are now 
dropped when the tools array is empty.
   
   2. **Streaming client hang.** When a stream emitted `message_start` but the 
upstream sent `[DONE]` before any content block opened and without a 
`finish_reason` chunk, `convert_sse_events` returned `nil` and never emitted 
`message_stop`, leaving the client hanging until timeout. `message_delta` + 
`message_stop` are now emitted whenever the message was already started.
   
   ### Tests
   
   Added two unit tests to `t/plugin/ai-proxy-anthropic.t`:
   - `tool_choice`/`parallel_tool_calls` dropped when no tools are forwarded 
(no-tools and all-built-in cases); preserved when a real tool remains.
   - `[DONE]` after `message_start` without a content block still emits 
`message_stop`.
   
   ### Checklist
   
   - [x] I have explained the need for this PR and the problem it solves
   - [x] I have explained the changes or the new features added to this PR
   - [x] I have added tests corresponding to this change
   - [x] I have updated the documentation to reflect this change (N/A — bugfix, 
no config/behavior doc change)
   - [x] I have verified that this change is backward compatible


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to