You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "huanghuang0913 (via GitHub)" <gi...@apache.org> on 2025/11/25 01:46:32 UTC

[I] help request: Malformed encoding found in chunked-encoding returned [apisix]

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

   ### Description
   
   I created a route for our deepseek r1:        
   curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \
     -H "X-API-KEY: ${admin_key}" \
     -d '{
       "id": "ai-proxy-route-DeepSeek-R1",
       "name": "DeepSeek-R1",
       "uri": "/deepseek-r1/chat/completions",
       "methods": ["POST"],
       "plugins": {
         "ai-proxy": {
           "provider": "openai-compatible",
           "auth": {
             "header": {
               "Authorization": "Bearer '"$DEEPSEEK_API_KEY"'"
             }
           },
           "override": {
             "endpoint": "http://<our ip>:<our port>/v1/chat/completions"
           }
         },
         "prometheus": {}
       }
     }'
   
   But when I send the request via apisix:
   [root@tmpl logs]# curl "http://10.103.43.14:9080/deepseek-r1/chat/completions" -X POST \
   > -H "Content-Type: application/json" \
   > -d '{
   >   "model": "DeepSeek-R1",
   >   "messages": [
   >     { "role": "system", "content": "You are a mathematician" },
   >     { "role": "user", "content": "What is 1+1?" }
   >   ],
   >   "stream": true
   > }'
   Here is the response:
   data: {"id":"endpoint_common_673","object":"chat.completion.chunk","created":1763984277,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":"{think"}],"logprobs":null,"finish_reason":null}]}
   
   data: {"id":"endpoint_common_673","object":"chat.completion.chunk","created":1763984277,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":"\\n"}],"logprobs":null,"finish_reason":null}]}
   
   data: {"id":"endpoint_common_673","object":"chat.completion.chunk","created":1763984277,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":"First"}],"logprobs":null,"finish_reason":null}]}
   
   data: {"id":"endpoint_common_673","object":"chat.completion.chunk","created":1763984278,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":","}],"logprobs":null,"finish_reason":null}]}
   
   data: {"id":"endpoint_common_673","object":"chat.completion.chunk","created":1763984278,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":" the"}],"logprobs":null,"finish_reason":null}]}
   
   data: {"id":"endpoint_common_673","object":"chat.completion.chunk","created":1763984278,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":" user"}],"logprobs":null,"finish_reason":null}]}
   
   data: {"id":"endpoint_common_673","object":"chat.completion.chunk","created":1763984278,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":"1"}],"logprobs":null,"finish_reason":null}]}
   
   d8
   
   da
   curl: (56) Malformed encoding found in chunked-encoding
   data: {"id":"endpoint_common_673","object":"chat.completion.chunk","created":1763984278,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":"\""}],"logprobs":null,"finish_reason":nu[root@tmpl logs]#
   
   If I send the same request to our ai model directly, the response is fine.
   
   ### Environment
   
   APISIX version (run apisix version): 3.14
   Operating system (run uname -a): x86_64 GNU/Linux
   OpenResty / Nginx version (run openresty -V or nginx -V):1.21.4.1
   etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info):bitnami/etcd:3.5.11
   APISIX Dashboard version, if relevant:apache/apisix-dashboard:latest
   Plugin runner version, for issues related to plugin runners:prom/prometheus:v2.25.0
   LuaRocks version, for installation issues (run luarocks --version): 3.12.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: notifications-unsubscribe@apisix.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: Malformed encoding found in chunked-encoding returned [apisix]

Posted by "huanghuang0913 (via GitHub)" <gi...@apache.org>.
huanghuang0913 commented on issue #12776:
URL: https://github.com/apache/apisix/issues/12776#issuecomment-3580500050

   By the way, since deepseek model doesn't work, but Qwen3-32B works fine using ai-proxy plugin.


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: Malformed encoding found in chunked-encoding returned [apisix]

Posted by "huanghuang0913 (via GitHub)" <gi...@apache.org>.
huanghuang0913 commented on issue #12776:
URL: https://github.com/apache/apisix/issues/12776#issuecomment-3584250911

   I cann't since you can not access our internal model.


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: Malformed encoding found in chunked-encoding returned [apisix]

Posted by "huanghuang0913 (via GitHub)" <gi...@apache.org>.
huanghuang0913 commented on issue #12776:
URL: https://github.com/apache/apisix/issues/12776#issuecomment-3578799459

   Here are the response from our direct request:
   * Trying 10.109.45.72:1005...
   * Connected to 10.109.45.72 (10.109.45.72) port 1005 (#0)
   > POST /v1/chat/completions HTTP/1.1
   > Host: 10.109.45.72:1005
   > User-Agent: curl/7.71.1
   > Accept: */*
   > Content-Type: application/json
   > Content-Length: 115
   >
   * upload completely sent off: 115 out of 115 bytes
   * Mark bundle as not supporting multiuse
   < HTTP/1.1 200 OK
   < Keep-Alive: timeout=180, max=2147483647
   < Transfer-Encoding: chunked
   < Content-Type: text/event-stream
   < RequestUUID: 1cf7e4ca4d8ddcde8d46731a16daeaac
   <
   
   data: {"id":"endpoint_common_6","object":"chat.completion.chunk","created":1764125956,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":"(think)"}, "logprobs":null,"finish_reason":null}]}


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: Malformed encoding found in chunked-encoding returned [apisix]

Posted by "Baoyuantop (via GitHub)" <gi...@apache.org>.
Baoyuantop commented on issue #12776:
URL: https://github.com/apache/apisix/issues/12776#issuecomment-3574821732

   Does your AI service response contain a valid Transfer-Encoding header?


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: Malformed encoding found in chunked-encoding returned [apisix]

Posted by "huanghuang0913 (via GitHub)" <gi...@apache.org>.
huanghuang0913 commented on issue #12776:
URL: https://github.com/apache/apisix/issues/12776#issuecomment-3578278149

   I can not use proxy-rewrite, since prometheus plugin only shows apisix_llm_completion_tokens from ai-proxy plugin? I want to count token usage via APISIX Prometheus metrics, but the metric apisix_llm_completion_tokens does not appear in the metrics information when I use proxy-rewrite instead of ai_proxy.
   
   curl "http://127.0.0.1:9180/apisix/admin/routes/ai-proxy-route-DeepSeek-R1" -X PUT \
     -H "X-API-KEY: ${admin_key}" \
     -d '{
       "id": "ai-proxy-route-DeepSeek-R1",
       "name": "DeepSeek-R1", 
       "uri": "/deepseek-r1/chat/completions",
       "methods": ["POST"],
       "plugins": {
         "proxy-rewrite": {
           "uri": "/v1/chat/completions",
           "host": "10.103.43.62:1025",
           "headers": {
             "Authorization": "Bearer '"$DEEPSEEK_API_KEY"'",
             "Content-Type": "application/json"
           }
         },
         "prometheus": {}
       },
       "upstream": {
         "nodes": {
           "<our ip>:<our port>": 1
         },
         "type": "roundrobin",
         "timeout": {
           "connect": 60,
           "send": 60, 
           "read": 300
         }
       }
     }'


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: Malformed encoding found in chunked-encoding returned [apisix]

Posted by "Baoyuantop (via GitHub)" <gi...@apache.org>.
Baoyuantop commented on issue #12776:
URL: https://github.com/apache/apisix/issues/12776#issuecomment-3573556103

   Hi @huanghuang0913, could you try replacing the provider with deepseek in the plugin configuration and then try again?


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: Malformed encoding found in chunked-encoding returned [apisix]

Posted by "huanghuang0913 (via GitHub)" <gi...@apache.org>.
huanghuang0913 commented on issue #12776:
URL: https://github.com/apache/apisix/issues/12776#issuecomment-3578267291

   curl -v:
   < HTTP/1.1 200 OK
   < Content-Type: text/event-stream
   < Transfer-Encoding: chunked  ← valid chunked transfer encoding header
   < Connection: keep-alive
   < Server: APISIX/3.14.1
   
   APISIX's ai-proxy plugin incorrectly generates or modifies the chunk boundaries when forwarding chunked-encoded streaming responses.
   If I use proxy-rewrite plugin, the response is okay, so I suspect it is the bug of ai-proxy plugin.


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: Malformed encoding found in chunked-encoding returned [apisix]

Posted by "Baoyuantop (via GitHub)" <gi...@apache.org>.
Baoyuantop commented on issue #12776:
URL: https://github.com/apache/apisix/issues/12776#issuecomment-3894995873

   This function is invoked each time a chunk is read when an AI agent returns a response in a streaming (SSE) manner. It allows downstream plugins—such as logging, content auditing, or response rewriting plugins—to inspect or modify the response body incrementally, chunk by chunk, rather than waiting until the entire response is complete before processing.


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: Malformed encoding found in chunked-encoding returned [apisix]

Posted by "Baoyuantop (via GitHub)" <gi...@apache.org>.
Baoyuantop closed issue #12776: help request: Malformed encoding found in chunked-encoding returned
URL: https://github.com/apache/apisix/issues/12776


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: Malformed encoding found in chunked-encoding returned [apisix]

Posted by "huanghuang0913 (via GitHub)" <gi...@apache.org>.
huanghuang0913 commented on issue #12776:
URL: https://github.com/apache/apisix/issues/12776#issuecomment-3626056299

   @Baoyuantop I noticed there is new line in /home/huangy/apisix-master-3.14/apisix/plugins/ai-drivers/openai-base.lua:
   plugin.lua_response_filter(ctx, res.headers, original_chunk), if I commented it, the response is normal. And it doesn't existed in apisix-3.13.


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: Malformed encoding found in chunked-encoding returned [apisix]

Posted by "Baoyuantop (via GitHub)" <gi...@apache.org>.
Baoyuantop commented on issue #12776:
URL: https://github.com/apache/apisix/issues/12776#issuecomment-3578498999

   > curl -v: < HTTP/1.1 200 OK < Content-Type: text/event-stream < Transfer-Encoding: chunked ← valid chunked transfer encoding header < Connection: keep-alive < Server: APISIX/3.14.1
   > 
   > APISIX's ai-proxy plugin incorrectly generates or modifies the chunk boundaries when forwarding chunked-encoded streaming responses. If I use proxy-rewrite plugin, the response is okay, so I suspect it is the bug of ai-proxy plugin.
   
   This looks like an APISIX response. Could you provide an example of requesting your AI service directly without going through a proxy?


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: Malformed encoding found in chunked-encoding returned [apisix]

Posted by "huanghuang0913 (via GitHub)" <gi...@apache.org>.
huanghuang0913 commented on issue #12776:
URL: https://github.com/apache/apisix/issues/12776#issuecomment-3574460055

   hi, Baoyuan @Baoyuantop. I tired, but it doesn't work, the ai model we use is not the offical api, but the deployment by ourselves. so according to the doc:
   LLM service provider. When set to openai, the Plugin will proxy the request to https://api.openai.com/chat/completions. When set to deepseek, the Plugin will proxy the request to https://api.deepseek.com/chat/completions. When set to aimlapi, the Plugin uses the OpenAI-compatible driver and proxies the request to https://api.aimlapi.com/v1/chat/completions by default. **When set to openai-compatible, the Plugin will proxy the request to the custom endpoint configured in override.**


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: Malformed encoding found in chunked-encoding returned [apisix]

Posted by "Baoyuantop (via GitHub)" <gi...@apache.org>.
Baoyuantop commented on issue #12776:
URL: https://github.com/apache/apisix/issues/12776#issuecomment-3584090684

   If you can provide a reproducible environment, we can continue investigating this issue.


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org