File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -641,8 +641,20 @@ def _prepare_proxy_and_headers(
641641 request_id = request .headers .get ("x-request-id" , str (uuid .uuid4 ()))
642642 api_key = DUMMY_KEY
643643
644+ # get x-api-key
645+ x_api_key = request .headers .get ("x-api-key" )
646+
644647 if SERVER_STATE .is_mock_mode :
645648 api_key = _MOCK_ENV_API_KEY or "mock-key"
649+
650+ # [Modification]: If x-api-key exists, override authorization header
651+ elif x_api_key :
652+ api_key = x_api_key
653+ logger .debug (
654+ f"Request { request_id } : Using x-api-key for authorization override."
655+ )
656+
657+ # Only check Authorization Header if x-api-key is not present
646658 elif authorization :
647659 if not authorization .startswith ("Bearer " ):
648660 logger .warning (
@@ -660,12 +672,14 @@ def _prepare_proxy_and_headers(
660672 "host" ,
661673 "content-length" ,
662674 "content-type" ,
663- "authorization" ,
675+ "authorization" , # Authorization has been regenerated by AsyncOpenAI client through api_key parameter, so it is filtered out here
664676 "connection" ,
665677 "upgrade" ,
666678 "accept-encoding" ,
667679 "transfer-encoding" ,
668680 }
681+
682+ # x-api-key 不在 unsafe_headers 中,因此会被保留在 forward_headers 中发送给上游
669683 forward_headers = {
670684 k : v for k , v in request .headers .items () if k .lower () not in unsafe_headers
671685 }
You can’t perform that action at this time.
0 commit comments