Skip to content

feat(rig-core): add ChatGPT Subscription, GitHub Copilot, and compatibility providers#1615

Merged
gold-silver-copper merged 21 commits into0xPlaygrounds:mainfrom
wey-gu:wey/subs-providers
Apr 16, 2026
Merged

feat(rig-core): add ChatGPT Subscription, GitHub Copilot, and compatibility providers#1615
gold-silver-copper merged 21 commits into0xPlaygrounds:mainfrom
wey-gu:wey/subs-providers

Conversation

@wey-gu
Copy link
Copy Markdown
Contributor

@wey-gu wey-gu commented Apr 10, 2026

This PR adds two subscription-backed providers and three compatibility providers, while keeping provider-specific behavior localized in rig-core instead of pushing quirks into callers.

What is included

  • ChatGPT Subscription

    • OAuth device flow
    • token refresh + local cache
    • /responses request normalization for the subscription backend
    • compatibility handling for current backend quirks observed in live testing:
      • instructions required
      • system messages must be lifted out of input
      • SSE responses may omit content-type
      • device-code interval may be returned as a string
  • GitHub Copilot

    • OAuth device flow
    • Copilot API-key bootstrap / refresh
    • per-account API base routing from the token bootstrap response
    • /responses routing for codex-class models, while keeping chat-completions for normal chat models
  • compatibility providers for documented OpenAI-compatible / Anthropic-compatible APIs

    • MiniMax
    • Moonshot
    • Z.AI

Why the shared plumbing changed

  • OpenAI-compatible model/client types were generalized so new providers can reuse existing request / response / streaming machinery instead of copying entire providers.
  • Anthropic-compatible builder/client plumbing was similarly generalized so providers such as MiniMax / Moonshot / Z.AI can expose documented Anthropic-compatible endpoints with small provider modules.
  • Provider-specific normalization remains inside the provider modules, not in downstream apps.

Validation

  • cargo check -p rig-core
  • targeted provider tests for ChatGPT, GitHub Copilot, MiniMax, Moonshot, and Z.AI
  • live end-to-end validation through Con for:
    • ChatGPT Subscription OAuth + streaming completions
    • GitHub Copilot OAuth + streaming completions
  • live manual validation for MiniMax China endpoints:
    • OpenAI-compatible mode
    • Anthropic-compatible mode

Reference alignment

  • ChatGPT Subscription and Copilot behavior was aligned against live backend behavior and LiteLLM’s current subscription-provider behavior.
  • MiniMax / Moonshot / Z.AI were checked against local LiteLLM and AI SDK references.
  • The only material gap found in audit was Moonshot-specific request shaping for tool_choice=required and assistant reasoning_content; that is handled in this PR.

Scope note

This is intentionally one cohesive provider/compatibility change because the subscription providers required small shared compatibility extensions. If maintainers prefer, I can split follow-up work into:

  1. shared OpenAI / Anthropic compatibility refactors
  2. MiniMax / Moonshot / Z.AI providers
  3. GitHub Copilot
  4. ChatGPT Subscription

@wey-gu
Copy link
Copy Markdown
Contributor Author

wey-gu commented Apr 10, 2026

btw i am building a rust desktop app and verified above providers manually :)

@wey-gu wey-gu changed the title feat: add subscription and compatibility providers feat(rig-core): add ChatGPT Subscription, GitHub Copilot, and compatibility providers Apr 10, 2026
@wey-gu wey-gu force-pushed the wey/subs-providers branch from 5fffd3b to 3193eac Compare April 11, 2026 04:44
@RileyMathews
Copy link
Copy Markdown

I was also working on trying to make a custom provider using OAuth codex login. So loved seeing this PR already open! This would be amazing to see added here. I’m also working on some agent tools and would love to be able to just reuse my existing codex subscription

@wey-gu
Copy link
Copy Markdown
Contributor Author

wey-gu commented Apr 11, 2026

I was also working on trying to make a custom provider using OAuth codex login. So loved seeing this PR already open! This would be amazing to see added here. I’m also working on some agent tools and would love to be able to just reuse my existing codex subscription

Thanks @RileyMathews !

Glad this is helpful for you, too!

@wey-gu wey-gu force-pushed the wey/subs-providers branch from 3193eac to 89f509b Compare April 14, 2026 02:35
@gold-silver-copper
Copy link
Copy Markdown
Contributor

Thanks for the PR. Overall this looks good, but I have a couple of follow-up concerns about the auth flow.

Device flow polling: the OAuth polling logic is currently hardcoded to a fixed sleep/attempt count and only retries on authorization_pending. GitHub’s device flow docs mention interval and slow_down, so I think we should either handle those explicitly or document why that is not necessary here.

Cached token recovery: if a cached access token exists on disk but is stale or revoked, it looks like we return it directly and then fail when the Copilot token bootstrap rejects it. Is there a reason we don’t invalidate the cached token and fall back to re-auth in that case? Ideally this should recover automatically so the user does not need to manually clear cached tokens later.

@wey-gu wey-gu force-pushed the wey/subs-providers branch 2 times, most recently from 627613e to c8964ff Compare April 15, 2026 02:26
@wey-gu
Copy link
Copy Markdown
Contributor Author

wey-gu commented Apr 15, 2026

Thanks for the PR. Overall this looks good, but I have a couple of follow-up concerns about the auth flow.

Device flow polling: the OAuth polling logic is currently hardcoded to a fixed sleep/attempt count and only retries on authorization_pending. GitHub’s device flow docs mention interval and slow_down, so I think we should either handle those explicitly or document why that is not necessary here.

Cached token recovery: if a cached access token exists on disk but is stale or revoked, it looks like we return it directly and then fail when the Copilot token bootstrap rejects it. Is there a reason we don’t invalidate the cached token and fall back to re-auth in that case? Ideally this should recover automatically so the user does not need to manually clear cached tokens later.

Thanks @gold-silver-copper for the great suggestions!

Now addressed both concerns in the latest push.

  • GitHub Copilot device flow now uses the server-provided interval, honors slow_down by increasing the polling delay, and uses expires_in rather than a fixed attempt count.
  • If a cached GitHub access token is stale or revoked, and Copilot token bootstrap rejects it with 401/403, Rig now invalidates the cached token, re-runs device auth, and retries bootstrap automatically once.

Also added targeted tests around the new polling and stale-token recovery behavior.

Thanks again :)

Introduce upstream-ready providers and compatibility layers for subscription-backed and OpenAI/Anthropic-compatible services.

- add ChatGPT Subscription OAuth with device flow, token refresh, request normalization, and SSE compatibility handling
- add GitHub Copilot OAuth with device flow, cached API key refresh, per-account endpoint routing, and codex responses routing
- add MiniMax, Moonshot, and Z.AI providers for documented OpenAI-compatible and Anthropic-compatible endpoints
- generalize shared OpenAI and Anthropic compatibility plumbing so provider-specific behavior stays centralized and reusable
- expose app-friendly OAuth callbacks for embedding integrations such as Con settings UI
@gold-silver-copper
Copy link
Copy Markdown
Contributor

I'm going to work on fixing the final errors and merging this with #1415 so we can get this in by the end of today.

@wey-gu
Copy link
Copy Markdown
Contributor Author

wey-gu commented Apr 16, 2026

thanks @gold-silver-copper!

did a small patch to make ci happy

@gold-silver-copper
Copy link
Copy Markdown
Contributor

@wey-gu Hey there, I appreciate it but I'm going to revert it, I've already handled that on my local branch, sorry about that. I'm currently finishing up this PR, it'll be merged by tonight, don't worry about it :)

@wey-gu
Copy link
Copy Markdown
Contributor Author

wey-gu commented Apr 16, 2026

@wey-gu Hey there, I appreciate it but I'm going to revert it, I've already handled that on my local branch, sorry about that. I'm currently finishing up this PR, it'll be merged by tonight, don't worry about it :)

sure! sorry for that :-P thought i was helping follow the sun, didnt realize breaking your work :D

@gold-silver-copper
Copy link
Copy Markdown
Contributor

It's okay, I should've been communicating more :p

@gold-silver-copper gold-silver-copper added this pull request to the merge queue Apr 16, 2026
Merged via the queue into 0xPlaygrounds:main with commit 6dc36d8 Apr 16, 2026
6 checks passed
@github-actions github-actions bot mentioned this pull request Apr 15, 2026
@wey-gu wey-gu deleted the wey/subs-providers branch April 16, 2026 09:31
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.

3 participants