fix: add GitHub Copilot optimization headers for billing.#2813
Merged
tusharmath merged 5 commits intomainfrom Apr 3, 2026
Merged
fix: add GitHub Copilot optimization headers for billing.#2813tusharmath merged 5 commits intomainfrom
tusharmath merged 5 commits intomainfrom
Conversation
Add initiator tracking to Context and Request types to distinguish user vs agent-initiated conversations. Implement GitHub Copilot-specific HTTP headers (x-initiator, Openai-Intent, Copilot-Vision-Request, anthropic-beta) for billing optimization and model compatibility. Update agent executor to mark agent-spawned conversations with initiator="agent". Include comprehensive test coverage for all header scenarios.
This was referenced Apr 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add GitHub Copilot optimization headers (
x-initiator,Openai-Intent,Copilot-Vision-Request,anthropic-beta) to reduce request usage and improve billing accuracy for GitHub Copilot subscriptions.Context
GitHub Copilot uses specific HTTP headers to optimize request counting and billing.
x-initiator: Distinguishes between user-initiated vs agent-initiated requestsOpenai-Intent: Signals conversation context for billing optimizationCopilot-Vision-Request: Enables vision model optimizations when images are presentanthropic-beta: Required when Copilot proxies Anthropic Claude modelsChanges
initiatorfield toContextstruct to track who initiated a conversationAgentExecutorto mark agent-spawned conversations withinitiator: "agent"OpenAIProviderCopilot-Vision-RequestheaderContextRecordfor proper JSON serialization of initiator fieldKey Implementation Details
The headers are only added for
GITHUB_COPILOTprovider, ensuring no impact on other providers (OpenAI, Anthropic, ZAI, etc.). Theinitiatorfield is stored within the JSON-serializedContextin the existing database column - no schema migration required.Header Logic:
x-initiator: Usesrequest.initiatorif set, otherwise falls back to detecting from the last message role (non-User = agent)Openai-Intent: Always "conversation-edits" for GitHub CopilotCopilot-Vision-Request: "true" when image content is detected in messagesanthropic-beta: Added when model name contains "claude"Use Cases
x-initiator: agentfor proper billing categorizationx-initiator: userwhen no initiator is setCopilot-Vision-Request: truefor model optimizationTesting
All 272 tests pass, including 4 new tests specifically for GitHub Copilot headers:
test_get_headers_with_request_github_copilot_user_initiatedtest_get_headers_with_request_github_copilot_agent_initiatedtest_get_headers_with_request_github_copilot_vision_contenttest_get_headers_with_request_non_github_copilot_no_extra_headersLinks
crates/forge_repo/src/provider/openai.rs- Header generationcrates/forge_domain/src/context.rs- Added initiator fieldcrates/forge_app/src/agent_executor.rs- Subagent initiator markingcrates/forge_repo/src/conversation/conversation_record.rs- Serialization supportCo-Authored-By: ForgeCode noreply@forgecode.dev