Trim API key when submitting requests to LLM providers (#37082)

This prevents the common footgun of copy/pasting an API key
starting/ending with extra newlines, which would lead to a "bad request"
error.

Closes #37038 

Release Notes:

- agent: Support pasting language model API keys that contain newlines.
This commit is contained in:
Antonio Scandurra
2025-08-28 12:00:44 +00:00
committed by GitHub
parent 4981c33bf3
commit 39d86eeb7f
6 changed files with 8 additions and 7 deletions
+1 -1
View File
@@ -424,7 +424,7 @@ pub async fn complete(
.method(Method::POST)
.uri(uri)
.header("Content-Type", "application/json")
.header("Authorization", format!("Bearer {}", api_key))
.header("Authorization", format!("Bearer {}", api_key.trim()))
.header("HTTP-Referer", "https://zed.dev")
.header("X-Title", "Zed Editor");