ITADN
Kong/kong/Issues

ai-proxy upstream returns error json

#14903OpenArjen10 创建于 2026-06-09
A
Arjen10commented
### Is there an existing issue for this? - [x] I have searched the existing issues ### Kong version (`$ kong version`) kong 3.10 ### Current Behavior when the `ai-proxy` plugin is configured with `route_type = preserve`, if the upstream returns an invalid json res, the request is closed unexpectedly and the client receives an empty response ### Expected Behavior kong gateway is proxy gateway, don't return error to client, so return original json to client ### Steps To Reproduce _No response_ ### Anything else? ### 1. configure a fake upstream API fake upstream returns an incomplete json response ```nginx location /fake { content_by_lua_block { ngx.status = 200 ngx.header["Content-Type"] = "application/json" ngx.print("{") } } ``` fake upstream URL: ```text http://172.0.18.100:6443/fake ``` ### 2. Configure the `ai-proxy` plugin ```json { "name": "ai-proxy", "config": { "route_type": "preserve", "llm_format": "openai", "model": { "provider": "openai", "options": { "upstream_url": "http://172.0.18.100:6443/fake" } }, "auth": { "header_name": "Authorization", "header_value": "Bearer dummy" }, "logging": { "log_statistics": true } } } ``` ### 3. Send a request through Kong gateway ```bash curl --location 'http://172.18.0.21:8100/fake' \ --header 'Content-Type: application/json' \ --data '{ "model": "gpt-4", "messages": [ { "role": "user", "content": "hello" } ] }' ``` ### 4. actual behavior client receives an empty response: ```text curl: (52) Empty reply from server ``` kong logs the following error: ```text failed to run body_filter_by_lua*: .../kong/llm/plugin/shared-filters/serialize-analytics.lua:53: Expected object key string but found T_END at character 2 ``` full error log: ```text 2026/06/09 21:18:15 [error] 2631#0: *5185 failed to run body_filter_by_lua*: ...1/kong/llm/plugin/shared-filters/serialize-analytics.lua:53: Expected object key string but found T_END at character 2 stack traceback: [C]: in function 'decode' ...1/kong/llm/plugin/shared-filters/serialize-analytics.lua:53: in function 'run' /usr/local/share/lua/5.1/kong/llm/plugin/base.lua:63: in function 'run_stage' /usr/local/share/lua/5.1/kong/llm/plugin/base.lua:135: in function </usr/local/share/lua/5.1/kong/llm/plugin/base.lua:122> /usr/local/share/lua/5.1/kong/init.lua:509: in function 'execute_collected_plugins_iterator' /usr/local/share/lua/5.1/kong/init.lua:1997: in function 'body_filter' body_filter_by_lua(nginx-kong.conf:142):2: in main chunk while sending to client, client: 172.18.0.21, server: kong, request: "POST /fake HTTP/1.1", host: "172.18.0.21:8100", request_id: "d82f3e71d7ca4846e0636e33d09b3f1a" ```
1 条评论