sagrawal1993 opened a new issue, #14220:
URL: https://github.com/apache/apisix/issues/14220

   ### Current Behavior
   
   Since 3.18, when ai-proxy (or ai-proxy-multi) changes the request body 
before sending it upstream — options.model, stream_options for a streamed 
OpenAI request, removing model for Azure/Bedrock, a protocol conversion — the 
body is encoded by ai-transport/http.lua with core.json.canonical_encode, which 
sorts the keys of every object.
   
   For most fields key order does not matter, but for structured output it 
does: providers generate the answer in the order of the JSON Schema's 
properties, so a schema written as reasoning, answer is answered as answer, 
reasoning. Tool parameters schemas are reordered the same way.
   
   Only a body nothing touched keeps the client's bytes (the passthrough added 
in #13699), so most real requests are affected.
   
   ### Expected Behavior
   
   The upstream request keeps the client's key order. Keys APISIX adds (e.g. 
stream_options) can follow, in a deterministic order, so the same request still 
produces the same bytes.
   
   ### Error Logs
   
   None — the request succeeds; only the order differs.
   
   
   ### Steps to Reproduce
   
   1. Route with ai-proxy, provider: openai, options: {"model": "gpt-4o"}, 
override.endpoint pointing at a server that records the request body.
   2. Send:
   ```
   {"model":"client-model","messages":[{"role":"user","content":"hi"}],
    
"response_format":{"type":"json_schema","json_schema":{"name":"probe","schema":
      
{"type":"object","properties":{"zeta":{"type":"string"},"alpha":{"type":"string"},"mid":{"type":"integer"}},
       "required":["zeta","alpha","mid"]}}}}
   ```
   The upstream receives (3.18.0 – 3.20.0 and master d817af6f):
   ```
   
{"messages":[{"content":"hi","role":"user"}],"model":"gpt-4o","response_format":{"json_schema":{"name":"probe",
    
"schema":{"properties":{"alpha":{"type":"string"},"mid":{"type":"integer"},"zeta":{"type":"string"}},
    "required":["zeta","alpha","mid"],"type":"object"}},"type":"json_schema"}}
   ```
   properties is now alpha, mid, zeta.
   A streamed request is sorted too: 
`{"stream":true,"model":"m","messages":[...]} arrives as 
{"messages":[...],"model":"gpt-4o","stream":true,"stream_options":{"include_usage":true}}`.
   
   ### Environment
   
   
   - APISIX version: 3.18.0, 3.19.0, 3.20.0, master (d817af6f)
   - Operating system: Linux (official apache/apisix:*-ubuntu images)
   - OpenResty / Nginx version: 1.31.8.1 (3.20.0)


-- 
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]

  • [I] bug: ai-proxy sends the re... sagrawal1993 (via GitHub) via notifications

Reply via email to