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
View File
@@ -13,6 +13,7 @@ pub async fn stream_generate_content(
api_key: &str,
mut request: GenerateContentRequest,
) -> Result<BoxStream<'static, Result<GenerateContentResponse>>> {
let api_key = api_key.trim();
validate_generate_content_request(&request)?;
// The `model` field is emptied as it is provided as a path parameter.