Skip to content

Optimize GitHub Copilot quota usage for Tool Calling #1519

@pxwg

Description

@pxwg

Description

I have observed that when using the GitHub Copilot provider in this plugin, every Tool Calling API request consumes the user's quota. This leads to significantly higher costs/usage compared to the official VS Code Copilot Chat extension, especially when multiple tools are invoked in a single turn.

This issue has been previously identified and addressed in other open-source Copilot implementations, such as in OpenCode v1.1.31.

Technical Analysis

After analyzing the network traffic of the official VS Code Copilot Chat extension, I found that the distinction between a Tool Calling request (which shouldn't consume standard quota) and a regular chat request lies in the x-initiator header:

  • x-initiator: agent: Used for Tool Calling / background intents. Does not count towards the primary user message quota.
  • x-initiator: user: Used for standard user-initiated chat messages.

The official implementation in VS Code follows this logic, as seen in their toolCallingLoop.ts.

Suggested Fix

In the Copilot provider's request logic, when the model is performing tool calling (or for the intermediate steps of a tool loop), the x-initiator HTTP header should be set to agent.

This would ensure that copilotchat.nvim users have a consistent experience with the official extension and avoid unnecessary quota exhaustion.

Additional Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions