fix(ai-proxy): forward client method and query string for passthrough#13546
Open
AlinsRan wants to merge 1 commit into
Open
fix(ai-proxy): forward client method and query string for passthrough#13546AlinsRan wants to merge 1 commit into
AlinsRan wants to merge 1 commit into
Conversation
The passthrough protocol is a catch-all that proxies the original client request to the provider, but the upstream request builder hardcoded the method to POST and built the query string only from auth.query and the override.endpoint URL — the client's own query string (ctx.var.args) was dropped. This breaks providers that carry required parameters in the query on POST requests, e.g. Azure OpenAI's ?api-version=. For the passthrough protocol, forward the client's HTTP method and merge its query string into the upstream request. Signed-off-by: AlinsRan <alinsran@apache.org>
f5a6ae7 to
f4e3899
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
The ai-proxy passthrough protocol dropped the client's query string and forced the method to POST, breaking providers that need query params on POST — e.g. Azure OpenAI's
?api-version=....Cause
In
apisix/plugins/ai-providers/base.lua, the upstream request builder hardcodesmethod = "POST"and merges onlyauth.query+ theoverride.endpointURL query — the client's own query string (ctx.var.args) is never added.Fix
For the passthrough protocol (
ctx.ai_target_protocol == "passthrough"), forward the client's HTTP method (core.request.get_method()) and merge the client's query string (ctx.var.args) into the upstream request. Other protocols are unchanged (still POST with provider-specific query args).Test
t/plugin/ai-proxy-passthrough.t: a passthrough request with?name=fooasserts the arg reaches the upstream; aPUTpassthrough request asserts the upstream seesPUT.Checklist