Skip to content

fix: add GitHub Copilot optimization headers for billing.#2813

Merged
tusharmath merged 5 commits intomainfrom
github-usage-fix
Apr 3, 2026
Merged

fix: add GitHub Copilot optimization headers for billing.#2813
tusharmath merged 5 commits intomainfrom
github-usage-fix

Conversation

@amitksingh1490
Copy link
Copy Markdown
Contributor

@amitksingh1490 amitksingh1490 commented Apr 3, 2026

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 requests
  • Openai-Intent: Signals conversation context for billing optimization
  • Copilot-Vision-Request: Enables vision model optimizations when images are present
  • anthropic-beta: Required when Copilot proxies Anthropic Claude models

Changes

  • Added initiator field to Context struct to track who initiated a conversation
  • Modified AgentExecutor to mark agent-spawned conversations with initiator: "agent"
  • Implemented GitHub Copilot-specific header injection in OpenAIProvider
  • Added vision content detection to set Copilot-Vision-Request header
  • Added Anthropic model detection to inject required beta flag
  • Updated ContextRecord for proper JSON serialization of initiator field
  • Added comprehensive test coverage for all header scenarios

Key Implementation Details

The headers are only added for GITHUB_COPILOT provider, ensuring no impact on other providers (OpenAI, Anthropic, ZAI, etc.). The initiator field is stored within the JSON-serialized Context in the existing database column - no schema migration required.

Header Logic:

  1. x-initiator: Uses request.initiator if set, otherwise falls back to detecting from the last message role (non-User = agent)
  2. Openai-Intent: Always "conversation-edits" for GitHub Copilot
  3. Copilot-Vision-Request: "true" when image content is detected in messages
  4. anthropic-beta: Added when model name contains "claude"

Use Cases

  • Subagent tool calls: Automatically marked as x-initiator: agent for proper billing categorization
  • Direct user interactions: Default to x-initiator: user when no initiator is set
  • Vision requests: Images in messages trigger Copilot-Vision-Request: true for model optimization
  • Anthropic models: Claude models get required beta flag for extended thinking

Testing

# Run provider tests to verify header generation
cargo test --package forge_repo -- test_get_headers

# Run all tests for modified packages
cargo test --package forge_repo --package forge_app --package forge_domain

All 272 tests pass, including 4 new tests specifically for GitHub Copilot headers:

  • test_get_headers_with_request_github_copilot_user_initiated
  • test_get_headers_with_request_github_copilot_agent_initiated
  • test_get_headers_with_request_github_copilot_vision_content
  • test_get_headers_with_request_non_github_copilot_no_extra_headers

Links

  • Files changed:
    • crates/forge_repo/src/provider/openai.rs - Header generation
    • crates/forge_domain/src/context.rs - Added initiator field
    • crates/forge_app/src/agent_executor.rs - Subagent initiator marking
    • crates/forge_repo/src/conversation/conversation_record.rs - Serialization support

Co-Authored-By: ForgeCode noreply@forgecode.dev

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.
@github-actions github-actions bot added the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label Apr 3, 2026
@amitksingh1490 amitksingh1490 changed the title feat: add GitHub Copilot optimization headers for billing fix: add GitHub Copilot optimization headers for billing. Apr 3, 2026
@amitksingh1490 amitksingh1490 added type: fix Iterations on existing features or infrastructure. and removed type: feature Brand new functionality, features, pages, workflows, endpoints, etc. labels Apr 3, 2026
@tusharmath tusharmath enabled auto-merge (squash) April 3, 2026 05:07
@tusharmath tusharmath merged commit 8c0af00 into main Apr 3, 2026
9 checks passed
@tusharmath tusharmath deleted the github-usage-fix branch April 3, 2026 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix Iterations on existing features or infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants