From beff9282f6f8e03307eeaed02aafc0f4b044a676 Mon Sep 17 00:00:00 2001 From: Luis Pater Date: Sat, 26 Jul 2025 15:51:04 +0800 Subject: [PATCH] Fix `alt` parameter handling in URL construction - Ensured `alt` parameter is only appended when non-empty. - Added debug logging for constructed URLs. --- internal/client/client.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/client/client.go b/internal/client/client.go index 041bb24b..3a9e92b1 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -260,7 +260,9 @@ func (c *Client) APIRequest(ctx context.Context, endpoint string, body interface if alt == "" && stream { url = url + "?alt=sse" } else { - url = url + fmt.Sprintf("?$alt=%s", alt) + if alt != "" { + url = url + fmt.Sprintf("?$alt=%s", alt) + } } } else { if endpoint == "countTokens" { @@ -272,7 +274,9 @@ func (c *Client) APIRequest(ctx context.Context, endpoint string, body interface if alt == "" && stream { url = url + "?alt=sse" } else { - url = url + fmt.Sprintf("?$alt=%s", alt) + if alt != "" { + url = url + fmt.Sprintf("?$alt=%s", alt) + } } jsonBody = []byte(gjson.GetBytes(jsonBody, "request").Raw) systemInstructionResult := gjson.GetBytes(jsonBody, "systemInstruction") @@ -285,6 +289,7 @@ func (c *Client) APIRequest(ctx context.Context, endpoint string, body interface } // log.Debug(string(jsonBody)) + // log.Debug(url) reqBody := bytes.NewBuffer(jsonBody) req, err := http.NewRequestWithContext(ctx, "POST", url, reqBody)