Skip to content

feat: dynamic Copilot model discovery and context tiers - #3

Open
Omzig wants to merge 4 commits into
milespossing:mainfrom
Omzig:fix/startup-model-discovery
Open

feat: dynamic Copilot model discovery and context tiers#3
Omzig wants to merge 4 commits into
milespossing:mainfrom
Omzig:fix/startup-model-discovery

Conversation

@Omzig

@Omzig Omzig commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Discover Copilot's live model catalog before Pi resolves enabledModels scope.
  • Parse Copilot billing metadata for default and long-context tiers for every discovered model.
  • Map Copilot AI-credit prices into Pi's dollar-per-million-token Model.cost fields, including input, output, cache-read, cache-write, and long-context rates.
  • Publish Pi-only aliases such as gpt-5.6-luna@200k, gpt-5.6-luna@1m, gpt-5.4@272k, and grok-4.5@500k.
  • Translate aliases back to the canonical Copilot model ID before native streaming; suffixed IDs are never sent to Copilot.
  • Route responses-only models through the correct native API family.
  • Document the generic behavior and bump the package to 0.5.0.

Billing behavior

Copilot reports token prices in AI credits per million tokens, where one AI credit is $0.01. The extension converts those values to the dollar-per-million-token rates expected by Pi. The smaller context alias uses the default tier, while the larger alias retains Pi's automatic long-context cost tier.

Validation

  • Strict TypeScript check passes.
  • git diff --check passes.
  • Live authenticated /models request returned HTTP 200 with billing metadata.
  • Live discovery produced the expected canonical models and context aliases.
  • pi --list-models gpt-5.6 shows the Copilot aliases at startup.
  • Real requests succeeded with both github-copilot/gpt-5.6-luna@200k and github-copilot/gpt-5.6-luna@1m.
  • Verified a real gpt-5.6-luna@200k session reports nonzero billing in Pi’s footer (for example, $0.021 (sub)).

The local Pi installation was switched from the stale npm package to this checkout so the installed workflow is exercised while the PR is reviewed.

Base-branch note

The upstream main branch already contains the responses-only routing change in src/families.ts. The fork-local comparison therefore shows 7 changed files, while this upstream-targeted PR correctly shows 6. The final head tree still contains the same src/families.ts content; it is simply already present in the upstream base. The billing fix is included in commit 661ae63 and is part of this PR.

Pi resolves enabledModels during startup before session_start. Registering the discovery provider on session_start left scoped models like gemini-3.6-flash and grok-4.5 missing until /copilot-refresh.

Run best-effort /models discovery during extension load, register the provider override immediately, and resolve the built-in provider via builtinProviders() (jiti-safe import).

Co-authored-by: Cursor <cursoragent@cursor.com>
@Omzig

Omzig commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

@milespossing, fixed another small problem, enjoy ;)

@Omzig Omzig changed the title fix: discover Copilot models before enabledModels scope resolution feat: dynamic Copilot model discovery and context tiers Aug 5, 2026
@Omzig

Omzig commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

the default one still defaults to max :(
image

@Omzig

Omzig commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

I also created a PR to get the sort to work in pi.dev: earendil-works/pi#7692

@milespossing

Copy link
Copy Markdown
Owner

Hey sorry for the delay. Shipping a few things. This all looks good to me, but let me test it and set up some automation so you don't need to wait so long for me to do a bunch of manual stuff

Comment thread src/index.ts
return builtin;
}

function getAuthPath(): string {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hey in the past I had some strange issues with auth and stored creds. I'm not sure what you've done here is wrong, but the behavior I saw before was that the extension would start and work for maybe an hour or so, but eventually we would get token expired exceptions.

I'm not reading super closely yet, but I wanted to be sure that pi is still owning the token acquisition and we aren't exposing ourselves to auth token rot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i will admit, i vibed through the issue, i dont know much about pi, but the outcome was good, doesnt mean what i did is 'correct'

@milespossing

Copy link
Copy Markdown
Owner

Alright just did some reading and validation.

I don't see any issues in my validations, but I'm just slightly concerned about the shift back towards wrapping and owning auth. As I mentioned in my other comment, there were issues with token refresh when I'd first started to make this work in this way.

If you've been using this new version for a while, then I imagine it's fine and you found the right balance with the tokens (or pi has improved this aspect of its api), but I want to be sure

@Omzig

Omzig commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

i have been fighting it a little, because when i restart pi, sometimes it will remove models that i have already added by using /scoped-models, i have had the seam traced, but pi will dump the models if the auth is expired on the next rerun of pi from the shell

@Omzig

Omzig commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

i feel like pi should reauth before it goes and says xyz model is not found

@Omzig

Omzig commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

next battle:

PS C:\temp\test pi> pi
pi-copilot-discovery: startup discovery failed (copilot /models: 401 IDE token expired: unauthorized: token expired
)
Warning: No models match pattern "github-copilot/gpt-5.6-luna@200k"
Warning: No models match pattern "github-copilot/gpt-5.6-luna@1m"
Model scope: haiku, auto, kimi, gemini, glm-5.2, kimi-k3, opus-5@1m, sonnet-5@300k, grok-4.5:slow, opus-5@1m:slow, gpt-5-6-sol@1m, gpt-5.6-luna@1m:slow, gpt-5.6-sol@272k:slow, gpt-5.6-terra@1m:slow, gpt-5.6-luna@272k:slow, gpt-5.6-terra@272k:slow, composer-2.5, composer-2-5:slow, claude-sonnet-5@300k, claude-opus-5@1m:slow, claude-opus-5@300k:slow, gpt-5.6-sol@1m:slow, kimi-k2.7-code, claude-opus-5, claude-sonnet-5, claude-haiku-4.5, mai-code-1-flash-picker, gpt-5.6-terra, gpt-5.6-sol, gpt-5-mini, claude-sonnet-4-5@20250929, claude-haiku-4-5@20251001, gpt-5.6-luna (Ctrl+P to cycle)

pi v0.84.0
escape interrupt · ctrl+c/ctrl+d clear/exit · / commands · ! bash · ctrl+o more
Press ctrl+o to show full startup help and loaded resources.

Pi can explain its own features and look up its docs. Ask it how to use or extend Pi.

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