A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 9, 03:45 UTC
fix: only include Authorization header when OPENAI_API_KEY is set (#33488)
Signed-off-by: zack041 <zackyu041@gmail.com>
Zack Yu committed
Jan 31, 2026 at 23:35 UTC
754a8ca9426080a652377b556d466cadb5c3468f
1 file changed
+17
-26
vllm/benchmarks/lib/endpoint_request_func.py
+17
-26
@@ -138,6 +138,16 @@ def _update_headers_common(
138
headers["x-request-id"] = request_func_input.request_id
139
140
141
+def _get_headers(content_type: str | None = None) -> dict[str, str]:
142
+ headers = {}
143
+ if content_type:
144
+ headers["Content-Type"] = content_type
145
+ api_key = os.environ.get("OPENAI_API_KEY")
146
+ if api_key:
147
+ headers["Authorization"] = f"Bearer {api_key}"
148
+ return headers
149
+
150
+
151
async def async_request_openai_completions(
152
request_func_input: RequestFuncInput,
153
session: aiohttp.ClientSession,
@@ -170,9 +180,7 @@ async def async_request_openai_completions(
180
}
181
_update_payload_common(payload, request_func_input)
182
173
- headers = {
174
- "Authorization": f"Bearer {os.environ.get('OPENAI_API_KEY')}",
175
- }
183
+ headers = _get_headers()
184
_update_headers_common(headers, request_func_input)
185
186
output = RequestFuncOutput()
@@ -301,10 +309,7 @@ async def async_request_openai_chat_completions(
309
}
310
_update_payload_common(payload, request_func_input)
311
304
- headers = {
305
- "Content-Type": "application/json",
306
- "Authorization": f"Bearer {os.environ.get('OPENAI_API_KEY')}",
307
- }
312
+ headers = _get_headers("application/json")
313
_update_headers_common(headers, request_func_input)
314
315
output = RequestFuncOutput()
@@ -396,9 +401,7 @@ async def async_request_openai_audio(
401
}
402
_update_payload_common(payload, request_func_input)
403
399
- headers = {
400
- "Authorization": f"Bearer {os.environ.get('OPENAI_API_KEY')}",
401
- }
404
+ headers = _get_headers()
405
_update_headers_common(headers, request_func_input)
406
407
# Send audio file
@@ -537,10 +540,7 @@ async def async_request_openai_embeddings(
540
}
541
_update_payload_common(payload, request_func_input)
542
540
- headers = {
541
- "Content-Type": "application/json",
542
- "Authorization": f"Bearer {os.environ.get('OPENAI_API_KEY')}",
543
- }
543
+ headers = _get_headers("application/json")
544
_update_headers_common(headers, request_func_input)
545
546
return await _run_pooling_request(
@@ -576,10 +576,7 @@ async def async_request_vllm_rerank(
576
"truncate_prompt_tokens": -1,
577
}
578
579
- headers = {
580
- "Content-Type": "application/json",
581
- "Authorization": f"Bearer {os.environ.get('OPENAI_API_KEY')}",
582
- }
579
+ headers = _get_headers("application/json")
580
_update_headers_common(headers, request_func_input)
581
582
return await _run_pooling_request(
@@ -615,10 +612,7 @@ async def async_request_openai_embeddings_chat(
612
}
613
_update_payload_common(payload, request_func_input)
614
618
- headers = {
619
- "Content-Type": "application/json",
620
- "Authorization": f"Bearer {os.environ.get('OPENAI_API_KEY')}",
621
- }
615
+ headers = _get_headers("application/json")
616
_update_headers_common(headers, request_func_input)
617
618
return await _run_pooling_request(
@@ -721,10 +715,7 @@ async def async_request_infinity_embeddings(
715
716
_update_payload_common(payload, request_func_input)
717
724
- headers = {
725
- "Content-Type": "application/json",
726
- "Authorization": f"Bearer {os.environ.get('OPENAI_API_KEY')}",
727
- }
718
+ headers = _get_headers("application/json")
719
_update_headers_common(headers, request_func_input)
720
721
return await _run_pooling_request(