Skip to content

fix(github_copilot): honor caller credentials for messages - #11

Merged
tanmaykm merged 1 commit into
v1.110.1_with_jh_fixesfrom
litellm_github_copilot_messages_caller_key
Nov 20, 2026
Merged

tanmaykm merged 1 commit into
v1.110.1_with_jh_fixesfrom
litellm_github_copilot_messages_caller_key

Conversation

@lamdor

@lamdor lamdor commented Nov 20, 2026

Copy link
Copy Markdown
Member

Fixes caller-key authentication for Copilot Messages.


Handwritten 1-3 sentence description

Copilot /v1/messages now uses the caller's per-user key when there is no user session, the same way chat, embeddings and Responses already do after #9. Without a caller key the stored login path is unchanged. Live proof with a real per-user Copilot key is still outstanding

Details

TLDR

Problem this solves:

  • Messages ignores caller keys when no user session exists.
  • Noninteractive callers without a stored login receive authentication errors.

How it solves it:

  • Keep user sessions first, then caller keys, then stored credentials.
  • Caller keys use the caller's base or the default host.
  • Stored credentials keep their own endpoint, ignoring caller bases.

User Flow

Before, a caller cannot use Messages without a stored login. The example hostname below represents the caller's proxy.

  1. They send POST https://proxy.example/v1/messages with their per-user key, using noninteractive mode and no stored login.
  2. They receive HTTP 401 with "No GitHub Copilot access token available".
  3. They cannot receive a message or stream using their own key.

After, the same request uses the caller's key. The automated proof below mocks the provider response.

  1. They send POST https://proxy.example/v1/messages with their per-user key, using noninteractive mode and no stored login.
  2. They receive the provider's message or stream through their chosen endpoint, or the default endpoint when none is supplied.
  3. They do not need a stored login to use their own key.

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes all required CI/CD checks
  • My PR's scope is as isolated as possible
  • Every automated review on my PR's latest commit has finished

Screenshots / Proof of Fix

Tested commit 4b4f9c46772ce7a40de76773291eee717cf8945a with mocked HTTP only. No live proxy or real provider calls were run. This authentication change does not qualify for the mechanical-change E2E exception. Live before/after proof remains outstanding before maintainer review.

The regression check loaded the original transformation module from base commit d8f3861655178f099e1629e4f528cf4987019ed4 into a separate Python process, then ran the new caller-key and public-request tests. It did not modify the working tree.

7 failed, 24 deselected, 1 warning in 3.41s
Original implementation pytest exit: 1

All new and existing Copilot unit tests were run at the tested commit with this command from the checkout.

LITELLM_LOCAL_MODEL_COST_MAP=true PYTHONPATH="$PWD" \
  /home/ubuntu/work/venv-upgrade/bin/python -m pytest \
  tests/unit/llms/github_copilot -q
304 passed, 48 warnings in 10.84s

The tests cover caller keys with explicit and default bases, no stored endpoint discovery for caller keys, blank-key fallback, missing credentials, and user-session precedence. Public request tests cover plain and streaming responses through litellm.anthropic_messages and litellm.anthropic.messages.acreate with bearer-header and URL assertions.

/home/ubuntu/work/venv-upgrade/bin/ruff check \
  litellm/llms/github_copilot/messages/transformation.py \
  tests/unit/llms/github_copilot/messages/test_github_copilot_messages_transformation.py
/home/ubuntu/work/venv-upgrade/bin/ruff format --check \
  litellm/llms/github_copilot/messages/transformation.py \
  tests/unit/llms/github_copilot/messages/test_github_copilot_messages_transformation.py
git diff --check
All checks passed!
2 files already formatted

Type

Bug Fix

Caveats (if any)

Medium

  • Live proxy and real-provider proof still needs to run.

Low

  • This fork has no litellm.aanthropic_messages export.
  • Both tested public entry points are asynchronous.
  • Existing synchronous native Messages requests remain unsupported.

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@tanmaykm tanmaykm left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. The change is right, and I've tested it live with a real per-user Copilot key.

Code: the order is right. The user session wins; otherwise a non-blank caller key is used, with the caller's base or the default host and never the stored login's endpoint. Without a caller key, behaviour is unchanged, and the caller's base is still ignored when the stored token is used. get_complete_url follows the same rule.

Unit tests: I ran the fork's whole tests/unit/llms/github_copilot suite on a v1.110.1 install, without and with this commit. All 7 new tests fail on the base and pass with the change, and 296 tests pass in total. 7 other failures and 1 error appear identically with and without the change. They come from my environment: the image sets GITHUB_COPILOT_NON_INTERACTIVE, and the local_beta_headers_config fixture wasn't available. Note that only the PR-title check ran on the fork, because its unit-test workflows don't trigger for PRs into *_with_jh_fixes.

Live check: I copied this commit's messages/transformation.py onto JuliaHub's litellmsrvr image (JuliaComputing/JuliaHub#25720, v1.110.1). The test user had a connected Copilot account, so the JuliaHub plugin got a per-user key from GitHub and set api_key/api_base on each request. The container had no stored login.

/v1/messages call Before (base) With this PR
claude-sonnet-5, plain 401 "No GitHub Copilot access token" ✓ 200, spend row under the user
claude-sonnet-5, streaming 401 ✓ 200 SSE, spend row under the user
claude-sonnet-5, tool use 401 ✓ 200 tool_use, spend row under the user
No user headers (no caller key) 401 401 (unchanged, no key used)
User without a Copilot connection 403 403 (unchanged, plugin refuses)

/chat/completions on a Copilot model still works as a control. One model the test account isn't entitled to returned GitHub's own 400 ("not available for integrator"), which shows the request reached Copilot with the caller's key.

After merging, please use a merge commit, not squash or rebase, so this commit's SHA ends up on the branch. JuliaHub can then pin it in a follow-up after JuliaComputing/JuliaHub#25720 merges.

@tanmaykm
tanmaykm merged commit a98a2c8 into v1.110.1_with_jh_fixes Nov 20, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants