Skip to content

Commit ac5e790

Browse files
committed
fix(github_copilot): main.py header block honors resolved api_key
The openai-compatible completion branch in main.py builds the Copilot default headers with a fresh Authenticator().get_api_key() regardless of the api_key already resolved for the call, so a clientside per-user key raised GetAPIKeyError (mapped to AuthenticationError) whenever the file-backed authenticator was unseeded. Use the resolved api_key and only fall back to the authenticator when none is present. Found in end-to-end verification of per-user Copilot credentials.
1 parent ff36aeb commit ac5e790

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

litellm/main.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,8 +2381,13 @@ def _complete_custom_openai(
23812381
get_copilot_default_headers,
23822382
)
23832383

2384-
copilot_auth = Authenticator()
2385-
copilot_api_key = copilot_auth.get_api_key()
2384+
# a caller-supplied (clientside / per-user) key was already resolved
2385+
# into api_key above; only fall back to the global file-backed
2386+
# authenticator when no key is present
2387+
copilot_api_key = api_key
2388+
if copilot_api_key is None:
2389+
copilot_auth = Authenticator()
2390+
copilot_api_key = copilot_auth.get_api_key()
23862391
copilot_headers = get_copilot_default_headers(copilot_api_key)
23872392
if extra_headers:
23882393
copilot_headers.update(extra_headers)

0 commit comments

Comments
 (0)