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> |
||
|---|---|---|
| .. | ||
| blog | ||
| docs | ||
| img | ||
| release_notes | ||
| src | ||
| static | ||
| .gitignore | ||
| babel.config.js | ||
| Dockerfile | ||
| docusaurus.config.js | ||
| index.md | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| sidebars-release-notes.js | ||
| sidebars.js | ||
Website
This website is built using Docusaurus 2, a modern static website generator.
Installation
$ yarn
Local Development
$ yarn start
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
Build
$ yarn build
This command generates static content into the build directory and can be served using any static contents hosting service.
Deployment
Using SSH:
$ USE_SSH=true yarn deploy
Not using SSH:
$ GIT_USER=<Your GitHub username> yarn deploy
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the gh-pages branch.