This is an automated email from the ASF dual-hosted git repository.

ashishtiwari pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 9e34661e7 fix(ai-proxy-multi): panic when instance dont have custom 
endpoint (#12584)
9e34661e7 is described below

commit 9e34661e7edb57fa76a215333b92c6d086e80076
Author: Ashish Tiwari <ashishjaitiwari15112...@gmail.com>
AuthorDate: Thu Sep 4 17:09:58 2025 +0530

    fix(ai-proxy-multi): panic when instance dont have custom endpoint (#12584)
---
 apisix/plugins/ai-proxy-multi.lua | 20 ++++++++---
 t/plugin/ai-proxy-multi3.t        | 74 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+), 5 deletions(-)

diff --git a/apisix/plugins/ai-proxy-multi.lua 
b/apisix/plugins/ai-proxy-multi.lua
index 47e2e00bc..a5682537e 100644
--- a/apisix/plugins/ai-proxy-multi.lua
+++ b/apisix/plugins/ai-proxy-multi.lua
@@ -170,14 +170,24 @@ end
 
 
 local function resolve_endpoint(instance_conf)
+    local scheme, host, port
     local endpoint = core.table.try_read_attr(instance_conf, "override", 
"endpoint")
-    local scheme, host, port, _ = endpoint:match(endpoint_regex)
-    if port == "" then
-        port = (scheme == "https") and "443" or "80"
+    if endpoint then
+        scheme, host, port = endpoint:match(endpoint_regex)
+        if port == "" then
+            port = (scheme == "https") and "443" or "80"
+        end
+        port = tonumber(port)
+    else
+        local ai_driver = require("apisix.plugins.ai-drivers." .. 
instance_conf.provider)
+        -- built-in ai driver always use https
+        scheme = "https"
+        host = ai_driver.host
+        port = ai_driver.port
     end
     local node = {
         host = host,
-        port = tonumber(port),
+        port = port,
         scheme = scheme,
     }
     parse_domain_for_node(node)
@@ -216,7 +226,7 @@ local function fetch_health_instances(conf, checkers)
             if ok then
                 transform_instances(new_instances, ins)
             elseif err then
-                core.log.error("failed to get health check target status, 
addr: ",
+                core.log.warn("failed to get health check target status, addr: 
",
                     node.host, ":", port or node.port, ", host: ", host, ", 
err: ", err)
             end
         else
diff --git a/t/plugin/ai-proxy-multi3.t b/t/plugin/ai-proxy-multi3.t
index 08ec4e10a..dc4601208 100644
--- a/t/plugin/ai-proxy-multi3.t
+++ b/t/plugin/ai-proxy-multi3.t
@@ -835,3 +835,77 @@ passed
 --- timeout: 20
 --- response_body
 passed
+
+
+
+=== TEST 11: configure health check for well-known ai service
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                    "uri": "/ai",
+                    "plugins": {
+                        "ai-proxy-multi": {
+                            "instances": [
+                                {
+                                    "name": "openai-gpt4",
+                                    "provider": "openai",
+                                    "weight": 1,
+                                    "priority": 1,
+                                    "auth": {
+                                        "header": {
+                                            "Authorization": "Bearer token"
+                                        }
+                                    },
+                                    "options": {
+                                        "model": "gpt-4"
+                                    },
+                                    "checks": {
+                                        "active": {
+                                            "timeout": 5,
+                                            "http_path": "/",
+                                            "healthy": {
+                                                "interval": 1,
+                                                "successes": 1
+                                            },
+                                            "unhealthy": {
+                                                "interval": 1,
+                                                "http_failures": 1
+                                            },
+                                            "req_headers": ["User-Agent: 
curl/7.29.0"]
+                                        }
+                                    }
+                                },
+                                
{"name":"openai-gpt3","provider":"openai","weight":1,"priority":1,"auth":{"header":{"Authorization":"Bearer
 token"}},"options":{"model":"gpt-3"}}
+                            ],
+                            "ssl_verify": false
+                        }
+                    }
+                }]]
+            )
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 12: send request to /ai should failed with 401
+--- request
+POST /ai
+{
+  "messages": [
+    {
+      "role": "user",
+      "content": "write a haiku about ai"
+    }
+  ]
+}
+--- error_code: 401

Reply via email to