mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-17 04:34:25 +00:00
This PR fixes GitHub Copilot billing behavior for multi-turn agentic workflows by implementing proper X-Initiator header classification. Previously, all turns consumed a premium request. After this fix, only the first user-initiated turn consumes a premium request; follow-up assistant/tool turns (agent-initiated) do not. **Changes:** 1. **New X-Initiator header classification** (common_utils.py): - Added `determine_x_initiator()` helper that analyzes input messages/items - Returns "user" if messages are user-only (new conversation = premium request) - Returns "agent" if messages contain assistant/tool roles (continuation = free) 2. **Wired X-Initiator header into completion paths**: - Chat API: chat/transformation.py sets X-Initiator from validate_environment() - Responses API: responses/transformation.py sets X-Initiator from validate_environment() - Main completion path: main.py passes X-Initiator through extra_headers 3. **Optional conversation correlation header**: - Added `copilot_conversation_id` metadata parameter for session-scoped billing - Sets X-Conversation-Id header when provided (optional, for caller opt-in) - Verified via API testing that billing is governed by X-Initiator, not session correlation 4. **Comprehensive test coverage**: - Unit tests for X-Initiator classification logic (test_conversation_id.py) - Integration tests for Chat API (test_github_copilot_transformation.py) - Integration tests for Responses API (test_github_copilot_responses_transformation.py) - Billing integration tests (test_github_copilot_billing.py) **Billing impact:** - Multi-turn agentic workflows: 1 premium request instead of N (where N = number of turns) - Single-turn conversations: No change (still 1 premium request) - Tool calls: 1 premium request for the full user→tool→tool_response→assistant exchange Fixes: #25276 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| my-website | ||