Skip to content

feat(client): support extra headers from model resolution#1575

Open
RoseSecurity wants to merge 3 commits into
CopilotC-Nvim:mainfrom
RoseSecurity:use-auto-model-lookup-by-default
Open

feat(client): support extra headers from model resolution#1575
RoseSecurity wants to merge 3 commits into
CopilotC-Nvim:mainfrom
RoseSecurity:use-auto-model-lookup-by-default

Conversation

@RoseSecurity

Copy link
Copy Markdown
Contributor

what and why

I woke up this morning to my :CopilotChatCommits failing. I read some docs, added support for Copilot's auto model session flow, and fired up a new session and this code worked for me.

Allegedly, GitHub now uses Copilot auto model selection as the default and only model selection experience for Free and Student plans. Instead of assuming that auto maps to a known static model, this PR updates the Copilot provider to resolve auto through the /models/session endpoint and pass the returned Copilot-Session-Token along with the chat request.


  • Allow provider model resolution to return extra request headers.
  • Include Copilot's session token when using the resolved auto-selected model.
  • Avoid failing when auto resolves to a model that is not present in the local model list by reusing the auto model config with the resolved model id.
  • Stop storing Copilot billing multipliers from the model list response.

Copilot auto model selection is now a first-class flow, especially for Free and Student users. Supporting the session token returned by Copilot's auto model endpoint keeps requests aligned with GitHub's current model routing behavior instead of treating auto like a normal static model alias.

  • Tested on my local system

Michael Rosenfeld added 2 commits June 25, 2026 16:46
- Allow providers to return extra headers from resolve_model callback
- Merge resolved headers into request authentication
- Handle 'auto' model fallback when resolution fails
- Return Copilot-Session-Token from copilot provider

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The multiplier removal breaks the existing Copilot model-selection UI. The provider type annotation and README also need to reflect the new resolve_model return value.

Reviewed changes — Adds support for extra headers returned by provider resolve_model, merges them into chat requests, and makes Copilot's auto model resolution a first-class flow by calling /models/session and forwarding the session token.

  • lua/CopilotChat/client.lua — Caches the originally requested model, accepts an optional second return value from resolve_model, falls back to the auto model config when the resolved model is absent from the local list, and merges resolved headers into the authenticated request headers.
  • lua/CopilotChat/config/providers.luaresolve_model now calls /models/session and returns Copilot-Session-Token; get_models stops storing billing.multiplier.

⚠️ billing.multiplier removal breaks model-selection cost indicators

lua/CopilotChat/init.lua still reads model.multiplier at line 346 and renders xN labels at lines 362-363. Removing multiplier from the copilot provider table means those indicators silently disappear.

Technical details
# `billing.multiplier` removal breaks model-selection cost indicators

## Affected sites
- `lua/CopilotChat/config/providers.lua:658` — removes `multiplier = model.billing and model.billing.multiplier or nil` from the model table built by `get_models`.
- `lua/CopilotChat/init.lua:346` — copies `model.multiplier` into the model picker choices.
- `lua/CopilotChat/init.lua:362-363` — appends `'x' .. tostring(item.multiplier)` to the picker label when present.

## Required outcome
- The Copilot model picker must either continue showing cost multipliers for Copilot models, or the dead code reading/displaying `multiplier` must be removed.

## Suggested approach
- Keep `multiplier` in the copilot provider model table, or
- Remove the `multiplier` field from `lua/CopilotChat/init.lua:338-348` and the `xN` indicator block at `lua/CopilotChat/init.lua:362-364`.

## Open questions for the human
- Was the multiplier intentionally dropped from the UI, or should it remain?

⚠️ resolve_model return-value contract is not documented

The provider API now accepts an optional second return value (extra headers), but the LuaCATS annotation at lua/CopilotChat/config/providers.lua:533 and the README example at README.md:455 still declare only a string return. Custom-provider authors won't know they can return headers.

Technical details
# `resolve_model` return-value contract is not documented

## Affected sites
- `lua/CopilotChat/config/providers.lua:533` — current annotation: `---@field resolve_model nil|fun(headers:table, model: string):string`
- `README.md:455` — current example: `resolve_model?(headers: table, model: string): string,`

## Required outcome
- Type signature and README example should document the optional headers table return.

## Suggested approach
- Update the LuaCATS annotation to something like `---@field resolve_model nil|fun(headers:table, model: string):string, table<string, string>?`.
- Update `README.md:455` to `resolve_model?(headers: table, model: string): string, table<string, string>?`.
- `doc/CopilotChat.txt` will be regenerated from the README by CI and should not be edited manually.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

Comment thread lua/CopilotChat/config/providers.lua
Update provider config to allow resolve_model to return model id and
lookup table. Add model multiplier mapping for Copilot provider and align
README type definitions.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — the follow-up commit addresses the two concerns from the previous review and makes a formatting-only update to the workflow file.

  • Restored billing.multiplier in lua/CopilotChat/config/providers.lua so the Copilot model picker keeps showing cost multipliers.
  • Documented the extra headers return value in the provider LuaCATS annotation and README resolve_model example.
  • Reformatted .github/workflows/pullfrog.yml spacing with no semantic change.

Pullfrog  | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@jeffreyrockstudio

Copy link
Copy Markdown

is it just me or the tools call (e.g. @copilot) doesn't work anymore after I merged this PR locally?

@RoseSecurity

Copy link
Copy Markdown
Contributor Author

is it just me or the tools call (e.g. @copilot) doesn't work anymore after I merged this PR locally?

The :Copilot command is failing for you?

@jeffreyrockstudio

Copy link
Copy Markdown

is it just me or the tools call (e.g. @copilot) doesn't work anymore after I merged this PR locally?

The :Copilot command is failing for you?

Tool Usage
for some reason it doesn't call tools correctly, usually it will wait for approval for a tool call:
Screenshot_20260627_023416

but now it just does this, like it's unable to call the tool:
Screenshot_20260627_023242

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants