From 632c6ca65593f2a37e5456932a4a1e990371b287 Mon Sep 17 00:00:00 2001 From: zat366 Date: Mon, 25 May 2026 14:34:45 +0800 Subject: [PATCH] fix(ai-proxy): use HasSuffix instead of Contains in claude.GetApiName to prevent sub-path misidentification (#3839) Signed-off-by: zat366 --- plugins/wasm-go/extensions/ai-proxy/provider/claude.go | 8 ++++---- .../wasm-go/extensions/ai-proxy/provider/claude_test.go | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/plugins/wasm-go/extensions/ai-proxy/provider/claude.go b/plugins/wasm-go/extensions/ai-proxy/provider/claude.go index 97e731b6..402918e9 100644 --- a/plugins/wasm-go/extensions/ai-proxy/provider/claude.go +++ b/plugins/wasm-go/extensions/ai-proxy/provider/claude.go @@ -1060,16 +1060,16 @@ func (c *claudeProvider) insertHttpContextMessage(body []byte, content string, o } func (c *claudeProvider) GetApiName(path string) ApiName { - if strings.Contains(path, PathAnthropicMessages) { + if strings.HasSuffix(path, PathAnthropicMessages) { return ApiNameChatCompletion } - if strings.Contains(path, PathAnthropicComplete) { + if strings.HasSuffix(path, PathAnthropicComplete) { return ApiNameCompletion } - if strings.Contains(path, PathOpenAIModels) { + if strings.HasSuffix(path, PathOpenAIModels) { return ApiNameModels } - if strings.Contains(path, PathOpenAIEmbeddings) { + if strings.HasSuffix(path, PathOpenAIEmbeddings) { return ApiNameEmbeddings } return "" diff --git a/plugins/wasm-go/extensions/ai-proxy/provider/claude_test.go b/plugins/wasm-go/extensions/ai-proxy/provider/claude_test.go index 2133bcdf..d1ec356e 100644 --- a/plugins/wasm-go/extensions/ai-proxy/provider/claude_test.go +++ b/plugins/wasm-go/extensions/ai-proxy/provider/claude_test.go @@ -572,6 +572,12 @@ func TestClaudeProvider_GetApiName(t *testing.T) { t.Run("unknown_path", func(t *testing.T) { assert.Equal(t, ApiName(""), provider.GetApiName("/unknown")) }) + + t.Run("sub_paths_should_not_match", func(t *testing.T) { + assert.Equal(t, ApiName(""), provider.GetApiName("/v1/messages/count_tokens")) + assert.Equal(t, ApiName(""), provider.GetApiName("/v1/messages/batches")) + assert.Equal(t, ApiName(""), provider.GetApiName("/v1/complete/something")) + }) } func TestClaudeProvider_BuildClaudeTextGenRequest_ToolRoleConversion(t *testing.T) {