@mupt-ai/dari-gateway 1.0.338 → 1.0.340

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +9 -7
  2. package/dist/index.d.ts +1 -1
  3. package/dist/ingress/codex.js +11 -5
  4. package/dist/ingress/codex_models.d.ts +2 -1
  5. package/dist/ingress/codex_models.js +60 -26
  6. package/dist/ingress/models.js +9 -4
  7. package/dist/link/assets.js +7 -0
  8. package/dist/link/endpoints.js +26 -6
  9. package/dist/link/errors.js +3 -0
  10. package/dist/link/self_hosted.js +8 -2
  11. package/dist/models/catalog.js +1 -0
  12. package/dist/models/execution_provider.d.ts +6 -1
  13. package/dist/models/execution_provider.js +12 -0
  14. package/dist/models/provider_defaults.js +9 -0
  15. package/dist/models/provider_models.json +217 -0
  16. package/dist/models/subscriptions.d.ts +5 -0
  17. package/dist/models/subscriptions.js +21 -2
  18. package/dist/providers/execution.d.ts +5 -0
  19. package/dist/providers/execution.js +12 -2
  20. package/dist/providers/github_copilot.d.ts +8 -0
  21. package/dist/providers/github_copilot.js +21 -0
  22. package/dist/providers/pi.js +3 -0
  23. package/dist/providers/provider_attempt_runner.d.ts +2 -0
  24. package/dist/providers/provider_attempt_runner.js +9 -0
  25. package/dist/providers/provider_call.js +6 -2
  26. package/dist/providers/subscription_limits.d.ts +6 -5
  27. package/dist/providers/subscription_limits.js +20 -9
  28. package/dist/runtime/model_menu_hint.d.ts +2 -0
  29. package/dist/runtime/model_menu_hint.js +13 -0
  30. package/dist/runtime/routed_completion.d.ts +2 -1
  31. package/dist/runtime/routed_completion.js +6 -2
  32. package/dist/runtime/routed_runtime.js +68 -3
  33. package/dist/self_host/resolve.d.ts +11 -9
  34. package/dist/self_host/resolve.js +247 -181
  35. package/dist/self_host/subscriptions/index.d.ts +6 -5
  36. package/dist/self_host/subscriptions/index.js +6 -5
  37. package/dist/self_host/subscriptions/oauth.d.ts +7 -3
  38. package/dist/self_host/subscriptions/oauth.js +195 -5
  39. package/dist/self_host/subscriptions/store.js +3 -0
  40. package/dist/telemetry/prefix_state.d.ts +1 -0
  41. package/dist/telemetry/prefix_state.js +1 -1
  42. package/dist/telemetry/report.js +2 -3
  43. package/dist/types.d.ts +6 -2
  44. package/package.json +2 -2
  45. package/src/index.ts +1 -1
  46. package/src/ingress/codex.ts +11 -5
  47. package/src/ingress/codex_models.ts +71 -27
  48. package/src/ingress/models.ts +9 -4
  49. package/src/link/assets.ts +7 -0
  50. package/src/link/endpoints.ts +27 -7
  51. package/src/link/errors.ts +3 -0
  52. package/src/link/self_hosted.ts +9 -1
  53. package/src/models/catalog.ts +1 -0
  54. package/src/models/execution_provider.ts +24 -1
  55. package/src/models/provider_defaults.ts +9 -0
  56. package/src/models/provider_models.json +217 -0
  57. package/src/models/subscriptions.ts +22 -2
  58. package/src/providers/execution.ts +22 -2
  59. package/src/providers/github_copilot.ts +24 -0
  60. package/src/providers/pi.ts +2 -0
  61. package/src/providers/provider_attempt_runner.ts +15 -0
  62. package/src/providers/provider_call.ts +6 -2
  63. package/src/providers/subscription_limits.ts +20 -10
  64. package/src/runtime/model_menu_hint.ts +20 -0
  65. package/src/runtime/routed_completion.ts +9 -3
  66. package/src/runtime/routed_runtime.ts +79 -3
  67. package/src/self_host/resolve.ts +253 -186
  68. package/src/self_host/subscriptions/index.ts +7 -4
  69. package/src/self_host/subscriptions/oauth.ts +264 -8
  70. package/src/self_host/subscriptions/store.ts +3 -0
  71. package/src/telemetry/prefix_state.ts +4 -1
  72. package/src/telemetry/report.ts +2 -3
  73. package/src/types.ts +27 -3
@@ -62,7 +62,7 @@ import { isReasoningEffort, providerForModel } from "@mupt-ai/dari-router/policy
62
62
  import { bearerToken } from "../http/auth.js";
63
63
  import { errorResponse, HttpError } from "../http/errors.js";
64
64
  import { SUBSCRIPTION_PLAN_LABELS } from "./errors.js";
65
- import { subscriptionClient, subscriptionModelProvider } from "../models/subscriptions.js";
65
+ import { modelSubscriptions, subscriptionClient } from "../models/subscriptions.js";
66
66
  import type {
67
67
  GatewayPlatform,
68
68
  LinkApp,
@@ -970,8 +970,10 @@ async function grantBody(platform: GatewayPlatform, request: Request, accessToke
970
970
  utilization: window.utilization,
971
971
  resets_at: window.resetsAt,
972
972
  })),
973
+ // A key's provider's models; a plan's are the ones it has an offering
974
+ // of, whoever makes them (every OpenCode Go model is another maker's).
973
975
  models: models(served.get(client))
974
- .filter((model) => providerForModel(model) === (keyFor ?? subscriptionModelProvider(kind)))
976
+ .filter((model) => keyFor === undefined ? modelSubscriptions(model).includes(kind) : providerForModel(model) === keyFor)
975
977
  .map(namedModel),
976
978
  };
977
979
  }),
@@ -1696,12 +1698,16 @@ function eventFor(authorize: AuthorizeRequest, step: LinkStep): PageEvent | unde
1696
1698
  };
1697
1699
  }
1698
1700
 
1699
- // How a kind of plan reads on the page, and whose sign-in connects it.
1700
- const KINDS: Record<SubscriptionKind, { name: string; plan: string; at: string }> = {
1701
+ // How a kind of plan reads on the page, and whose sign-in connects it. A
1702
+ // `pastedKey` plan connects with a key the user creates there instead.
1703
+ const KINDS: Record<SubscriptionKind, { name: string; plan: string; at: string; pastedKey?: true }> = {
1701
1704
  anthropic_claude_code: { name: "Claude", plan: "Pro, Max or Ultra plan", at: "Claude" },
1702
1705
  openai_codex: { name: "ChatGPT", plan: "Plus or Pro plan", at: "OpenAI" },
1703
1706
  meta_muse: { name: "Meta Muse", plan: "Muse Code plan", at: "Meta" },
1704
1707
  opencode_go: { name: "OpenCode Go", plan: "Go plan", at: "OpenCode" },
1708
+ github_copilot: { name: "GitHub Copilot", plan: "Copilot plan", at: "GitHub" },
1709
+ xai_grok: { name: "Grok", plan: "SuperGrok plan", at: "xAI" },
1710
+ vercel_token_pass: { name: "Vercel Token Pass", plan: "Token Pass", at: "Vercel", pastedKey: true },
1705
1711
  };
1706
1712
 
1707
1713
  // The first page a new user sees: what connecting means, and one button.
@@ -1770,11 +1776,25 @@ function keyPage(authorize: AuthorizeRequest, provider: LinkKeyProvider, error?:
1770
1776
  });
1771
1777
  }
1772
1778
 
1773
- // The provider's sign-in: a link to it, and the code to bring back or take there.
1779
+ // The provider's sign-in: a link to it, and the code to bring back or take
1780
+ // there; or, for a plan that is a key, where to create the key to paste back.
1774
1781
  function providerPage(authorize: AuthorizeRequest, connect: Connect, error?: string): Response {
1775
- const { name, at } = KINDS[connect.kind];
1782
+ const { name, at, pastedKey } = KINDS[connect.kind];
1776
1783
  const open = (style: string) =>
1777
- `<a class="btn ${style}" href="${escapeHtml(connect.url)}" target="_blank" rel="noopener noreferrer">Open ${name}${ICONS.external}</a>`;
1784
+ `<a class="btn ${style}" href="${escapeHtml(connect.url)}" target="_blank" rel="noopener noreferrer">Open ${pastedKey ? at : name}${ICONS.external}</a>`;
1785
+ if (pastedKey) {
1786
+ return pane(authorize, {
1787
+ title: `Add Your ${name} Key`,
1788
+ step: "connect_subscription",
1789
+ back: "select",
1790
+ error,
1791
+ body: `<span class="who">${logo(connect.kind, name)}</span>
1792
+ <h1>Add Your ${name} Key</h1>
1793
+ <div class="step"><span class="n">1</span><div><p>Create a ${name} key at ${at}.</p>${open("outline")}</div></div>
1794
+ <div class="step"><span class="n">2</span><div><label for="authorization_response">Paste the key.</label><input id="authorization_response" type="password" name="authorization_response" autocomplete="off" spellcheck="false" placeholder="Paste Key" required></div></div>`,
1795
+ footer: `<button class="btn primary" type="submit" name="decision" value="complete">Continue</button>`,
1796
+ });
1797
+ }
1778
1798
  const head = `<span class="who">${logo(connect.kind, name)}</span>
1779
1799
  <h1>Sign In To ${name}</h1>`;
1780
1800
  if (connect.userCode === null) {
@@ -49,6 +49,9 @@ export const SUBSCRIPTION_PLAN_LABELS: Record<SubscriptionKind, string> = {
49
49
  openai_codex: "ChatGPT Plus/Pro",
50
50
  meta_muse: "Meta Muse",
51
51
  opencode_go: "OpenCode Go",
52
+ github_copilot: "GitHub Copilot",
53
+ xai_grok: "Grok",
54
+ vercel_token_pass: "Vercel Token Pass",
52
55
  };
53
56
 
54
57
  const ONLY_CLIENT: Partial<Record<SubscriptionKind, string>> = {
@@ -10,8 +10,10 @@ import { checkProviderKey } from "../providers/key_check.js";
10
10
  import { gatewayKeyIndex, type SelfHostedResolverDeps } from "../self_host/resolve.js";
11
11
  import {
12
12
  CODEX_APPROVAL_PENDING,
13
+ GITHUB_APPROVAL_PENDING,
13
14
  META_APPROVAL_PENDING,
14
15
  OPENCODE_APPROVAL_PENDING,
16
+ XAI_APPROVAL_PENDING,
15
17
  SUBSCRIPTION_PROVIDERS,
16
18
  SubscriptionOAuthInputError,
17
19
  SubscriptionOAuthProviderError,
@@ -132,7 +134,13 @@ export function selfHostedLink(
132
134
  tokens = await completeOAuth(session.provider, session.flow, authorizationResponse, { fetch: deps.fetch });
133
135
  } catch (error) {
134
136
  if (error instanceof SubscriptionOAuthInputError) {
135
- if ([CODEX_APPROVAL_PENDING, META_APPROVAL_PENDING, OPENCODE_APPROVAL_PENDING].includes(error.message)) return null;
137
+ if ([
138
+ CODEX_APPROVAL_PENDING,
139
+ META_APPROVAL_PENDING,
140
+ OPENCODE_APPROVAL_PENDING,
141
+ GITHUB_APPROVAL_PENDING,
142
+ XAI_APPROVAL_PENDING,
143
+ ].includes(error.message)) return null;
136
144
  throw new HttpError(400, error.message, "invalid_request");
137
145
  }
138
146
  if (error instanceof SubscriptionOAuthProviderError) {
@@ -69,6 +69,7 @@ export const DEFAULT_CATALOG_PROVIDERS: readonly string[] = [
69
69
  "google",
70
70
  "fireworks",
71
71
  "opencode-go",
72
+ "github-copilot",
72
73
  "openrouter",
73
74
  "vercel-ai-gateway",
74
75
  ];
@@ -1,5 +1,10 @@
1
1
  import { providerForModel } from "@mupt-ai/dari-router/policy-engine";
2
- import type { ProviderKeySource, ResolvedRouter } from "../types.js";
2
+ import type {
3
+ ProviderCredential,
4
+ ProviderKeySource,
5
+ ResolvedRouter,
6
+ ResolvedRouterModelConfig,
7
+ } from "../types.js";
3
8
 
4
9
  /** Actual serving provider for a canonical model on a resolved managed router. */
5
10
  export function executionProviderForModel(
@@ -23,3 +28,21 @@ export function keySourceForModel(
23
28
  if (supplied) return supplied.subscription ? "subscription" : "user";
24
29
  return credentials.provider_key_sources?.[executionProviderForModel(credentials, model)] ?? "user";
25
30
  }
31
+
32
+ /**
33
+ * The router as one of a model's fallbacks serves it: the fallback's config,
34
+ * and its plan's credential or, without one, the router's API credential.
35
+ */
36
+ export function credentialsServedBy(
37
+ credentials: ResolvedRouter,
38
+ model: string,
39
+ config: ResolvedRouterModelConfig,
40
+ plan: ProviderCredential | undefined,
41
+ ): ResolvedRouter {
42
+ const { [model]: _replaced, ...others } = credentials.provider_credentials ?? {};
43
+ return {
44
+ ...credentials,
45
+ model_configs: { ...credentials.model_configs, [model]: config },
46
+ provider_credentials: plan === undefined ? others : { ...others, [model]: plan },
47
+ };
48
+ }
@@ -12,6 +12,8 @@ const PROVIDER_LABELS: Record<string, string> = {
12
12
  xai: "xAI",
13
13
  google: "Google",
14
14
  "opencode-go": "OpenCode Go",
15
+ "github-copilot": "GitHub Copilot",
16
+ "vercel-token-pass": "Vercel Token Pass",
15
17
  dari: "Dari",
16
18
  "amazon-bedrock": "Amazon Bedrock",
17
19
  azure: "Microsoft Azure",
@@ -39,6 +41,13 @@ const PROVIDER_BASE_URLS: Record<string, string> = {
39
41
  // A flat-rate plan for open models; each model keeps its own API path
40
42
  // under https://opencode.ai/inference/go/, and this is chat completions.
41
43
  "opencode-go": "https://opencode.ai/inference/go/openai/v1",
44
+ // Flat plans served only by personal subscriptions. Each Copilot account
45
+ // has its own API origin, named in its token (see github_copilot.ts); this
46
+ // one is the individual plans'.
47
+ "github-copilot": "https://api.individual.githubcopilot.com",
48
+ // A Token Pass key on Vercel AI Gateway, which serves only the gateway's
49
+ // featured models, over Anthropic Messages.
50
+ "vercel-token-pass": "https://ai-gateway.vercel.sh",
42
51
  // Meta's Model API serves OpenAI Responses and Chat Completions here, and
43
52
  // Anthropic Messages at https://api.meta.ai.
44
53
  meta: "https://api.meta.ai/v1",
@@ -1,4 +1,137 @@
1
1
  [
2
+ {
3
+ "model_id": "openai/gpt-6.2-astra",
4
+ "provider": "github-copilot",
5
+ "native_model_id": "gpt-6.2-astra",
6
+ "api": "openai-responses",
7
+ "base_url": "https://api.individual.githubcopilot.com"
8
+ },
9
+ {
10
+ "model_id": "openai/gpt-6-astra",
11
+ "provider": "github-copilot",
12
+ "native_model_id": "gpt-6-astra",
13
+ "api": "openai-responses",
14
+ "base_url": "https://api.individual.githubcopilot.com"
15
+ },
16
+ {
17
+ "model_id": "openai/gpt-6.1-terra",
18
+ "provider": "github-copilot",
19
+ "native_model_id": "gpt-6.1-terra",
20
+ "api": "openai-responses",
21
+ "base_url": "https://api.individual.githubcopilot.com"
22
+ },
23
+ {
24
+ "model_id": "openai/gpt-6.2-sol",
25
+ "provider": "github-copilot",
26
+ "native_model_id": "gpt-6.2-sol",
27
+ "api": "openai-responses",
28
+ "base_url": "https://api.individual.githubcopilot.com"
29
+ },
30
+ {
31
+ "model_id": "openai/gpt-6.1-sol",
32
+ "provider": "github-copilot",
33
+ "native_model_id": "gpt-6.1-sol",
34
+ "api": "openai-responses",
35
+ "base_url": "https://api.individual.githubcopilot.com"
36
+ },
37
+ {
38
+ "model_id": "openai/gpt-6-sol",
39
+ "provider": "github-copilot",
40
+ "native_model_id": "gpt-6-sol",
41
+ "api": "openai-responses",
42
+ "base_url": "https://api.individual.githubcopilot.com"
43
+ },
44
+ {
45
+ "model_id": "openai/gpt-6-luna",
46
+ "provider": "github-copilot",
47
+ "native_model_id": "gpt-6-luna",
48
+ "api": "openai-responses",
49
+ "base_url": "https://api.individual.githubcopilot.com"
50
+ },
51
+ {
52
+ "model_id": "openai/gpt-5.6-sol",
53
+ "provider": "github-copilot",
54
+ "native_model_id": "gpt-5.6-sol",
55
+ "api": "openai-responses",
56
+ "base_url": "https://api.individual.githubcopilot.com"
57
+ },
58
+ {
59
+ "model_id": "openai/gpt-5.6-terra",
60
+ "provider": "github-copilot",
61
+ "native_model_id": "gpt-5.6-terra",
62
+ "api": "openai-responses",
63
+ "base_url": "https://api.individual.githubcopilot.com"
64
+ },
65
+ {
66
+ "model_id": "openai/gpt-5.6-luna",
67
+ "provider": "github-copilot",
68
+ "native_model_id": "gpt-5.6-luna",
69
+ "api": "openai-responses",
70
+ "base_url": "https://api.individual.githubcopilot.com"
71
+ },
72
+ {
73
+ "model_id": "anthropic/claude-opus-5-5",
74
+ "provider": "github-copilot",
75
+ "native_model_id": "claude-opus-5.5",
76
+ "api": "anthropic-messages",
77
+ "base_url": "https://api.individual.githubcopilot.com"
78
+ },
79
+ {
80
+ "model_id": "anthropic/claude-opus-5",
81
+ "provider": "github-copilot",
82
+ "native_model_id": "claude-opus-5",
83
+ "api": "anthropic-messages",
84
+ "base_url": "https://api.individual.githubcopilot.com"
85
+ },
86
+ {
87
+ "model_id": "anthropic/claude-sonnet-5-5",
88
+ "provider": "github-copilot",
89
+ "native_model_id": "claude-sonnet-5.5",
90
+ "api": "anthropic-messages",
91
+ "base_url": "https://api.individual.githubcopilot.com"
92
+ },
93
+ {
94
+ "model_id": "anthropic/claude-sonnet-5",
95
+ "provider": "github-copilot",
96
+ "native_model_id": "claude-sonnet-5",
97
+ "api": "anthropic-messages",
98
+ "base_url": "https://api.individual.githubcopilot.com"
99
+ },
100
+ {
101
+ "model_id": "anthropic/claude-fable-5-2",
102
+ "provider": "github-copilot",
103
+ "native_model_id": "claude-fable-5.2",
104
+ "api": "anthropic-messages",
105
+ "base_url": "https://api.individual.githubcopilot.com"
106
+ },
107
+ {
108
+ "model_id": "anthropic/claude-fable-5-1",
109
+ "provider": "github-copilot",
110
+ "native_model_id": "claude-fable-5.1",
111
+ "api": "anthropic-messages",
112
+ "base_url": "https://api.individual.githubcopilot.com"
113
+ },
114
+ {
115
+ "model_id": "anthropic/claude-fable-5",
116
+ "provider": "github-copilot",
117
+ "native_model_id": "claude-fable-5",
118
+ "api": "anthropic-messages",
119
+ "base_url": "https://api.individual.githubcopilot.com"
120
+ },
121
+ {
122
+ "model_id": "anthropic/claude-haiku-5-5",
123
+ "provider": "github-copilot",
124
+ "native_model_id": "claude-haiku-5.5",
125
+ "api": "anthropic-messages",
126
+ "base_url": "https://api.individual.githubcopilot.com"
127
+ },
128
+ {
129
+ "model_id": "anthropic/claude-haiku-4-5",
130
+ "provider": "github-copilot",
131
+ "native_model_id": "claude-haiku-4.5",
132
+ "api": "anthropic-messages",
133
+ "base_url": "https://api.individual.githubcopilot.com"
134
+ },
2
135
  {
3
136
  "model_id": "meta/muse-spark-open",
4
137
  "provider": "fireworks",
@@ -55,6 +188,13 @@
55
188
  "api": "openai-completions",
56
189
  "base_url": "https://api.fireworks.ai/inference/v1"
57
190
  },
191
+ {
192
+ "model_id": "deepseek-ai/DeepSeek-V4.1-Flash",
193
+ "provider": "vercel-token-pass",
194
+ "native_model_id": "deepseek/deepseek-v4.1-flash",
195
+ "api": "anthropic-messages",
196
+ "base_url": "https://ai-gateway.vercel.sh"
197
+ },
58
198
  {
59
199
  "model_id": "deepseek-ai/DeepSeek-V4.1-Flash-1017",
60
200
  "provider": "fireworks",
@@ -62,6 +202,20 @@
62
202
  "api": "openai-completions",
63
203
  "base_url": "https://api.fireworks.ai/inference/v1"
64
204
  },
205
+ {
206
+ "model_id": "xai/grok-4.6",
207
+ "provider": "github-copilot",
208
+ "native_model_id": "grok-4.6",
209
+ "api": "openai-responses",
210
+ "base_url": "https://api.individual.githubcopilot.com"
211
+ },
212
+ {
213
+ "model_id": "xai/grok-4.7",
214
+ "provider": "github-copilot",
215
+ "native_model_id": "grok-4.7",
216
+ "api": "openai-responses",
217
+ "base_url": "https://api.individual.githubcopilot.com"
218
+ },
65
219
  {
66
220
  "model_id": "moonshotai/Kimi-K3",
67
221
  "provider": "opencode-go",
@@ -69,6 +223,20 @@
69
223
  "api": "openai-completions",
70
224
  "base_url": "https://opencode.ai/inference/go/openai/v1"
71
225
  },
226
+ {
227
+ "model_id": "moonshotai/Kimi-K3",
228
+ "provider": "github-copilot",
229
+ "native_model_id": "kimi-k3",
230
+ "api": "openai-completions",
231
+ "base_url": "https://api.individual.githubcopilot.com"
232
+ },
233
+ {
234
+ "model_id": "moonshotai/Kimi-K3",
235
+ "provider": "vercel-token-pass",
236
+ "native_model_id": "moonshotai/kimi-k3",
237
+ "api": "anthropic-messages",
238
+ "base_url": "https://ai-gateway.vercel.sh"
239
+ },
72
240
  {
73
241
  "model_id": "moonshotai/Kimi-K3.1-Pro",
74
242
  "provider": "fireworks",
@@ -83,6 +251,13 @@
83
251
  "api": "openai-completions",
84
252
  "base_url": "https://opencode.ai/inference/go/openai/v1"
85
253
  },
254
+ {
255
+ "model_id": "moonshotai/Kimi-K3.1-Pro",
256
+ "provider": "vercel-token-pass",
257
+ "native_model_id": "moonshotai/kimi-k3.1-pro",
258
+ "api": "anthropic-messages",
259
+ "base_url": "https://ai-gateway.vercel.sh"
260
+ },
86
261
  {
87
262
  "model_id": "zai-org/GLM-5.3",
88
263
  "provider": "opencode-go",
@@ -90,6 +265,13 @@
90
265
  "api": "openai-completions",
91
266
  "base_url": "https://opencode.ai/inference/go/openai/v1"
92
267
  },
268
+ {
269
+ "model_id": "zai-org/GLM-5.3",
270
+ "provider": "vercel-token-pass",
271
+ "native_model_id": "zai/glm-5.3",
272
+ "api": "anthropic-messages",
273
+ "base_url": "https://ai-gateway.vercel.sh"
274
+ },
93
275
  {
94
276
  "model_id": "zai-org/GLM-5.3-Flash",
95
277
  "provider": "opencode-go",
@@ -97,6 +279,13 @@
97
279
  "api": "openai-completions",
98
280
  "base_url": "https://opencode.ai/inference/go/openai/v1"
99
281
  },
282
+ {
283
+ "model_id": "zai-org/GLM-5.3-Flash",
284
+ "provider": "vercel-token-pass",
285
+ "native_model_id": "zai/glm-5.3-flash",
286
+ "api": "anthropic-messages",
287
+ "base_url": "https://ai-gateway.vercel.sh"
288
+ },
100
289
  {
101
290
  "model_id": "zai-org/GLM-5.2",
102
291
  "provider": "opencode-go",
@@ -110,5 +299,33 @@
110
299
  "native_model_id": "deepseek-v4.1-flash",
111
300
  "api": "openai-completions",
112
301
  "base_url": "https://opencode.ai/inference/go/openai/v1"
302
+ },
303
+ {
304
+ "model_id": "google/gemini-4-argon",
305
+ "provider": "github-copilot",
306
+ "native_model_id": "gemini-4-argon",
307
+ "api": "openai-completions",
308
+ "base_url": "https://api.individual.githubcopilot.com"
309
+ },
310
+ {
311
+ "model_id": "google/gemini-4-carbon",
312
+ "provider": "github-copilot",
313
+ "native_model_id": "gemini-4-carbon",
314
+ "api": "openai-completions",
315
+ "base_url": "https://api.individual.githubcopilot.com"
316
+ },
317
+ {
318
+ "model_id": "google/gemini-4-hydrogen",
319
+ "provider": "github-copilot",
320
+ "native_model_id": "gemini-4-hydrogen",
321
+ "api": "openai-completions",
322
+ "base_url": "https://api.individual.githubcopilot.com"
323
+ },
324
+ {
325
+ "model_id": "google/gemini-3.8-flash",
326
+ "provider": "github-copilot",
327
+ "native_model_id": "gemini-3.8-flash",
328
+ "api": "openai-completions",
329
+ "base_url": "https://api.individual.githubcopilot.com"
113
330
  }
114
331
  ]
@@ -1,5 +1,6 @@
1
- import { nativeModelId, type RouterModelPrice } from "@mupt-ai/dari-router/policy-engine";
1
+ import { nativeModelId, providerForModel, type RouterModelPrice } from "@mupt-ai/dari-router/policy-engine";
2
2
 
3
+ import { providerModel } from "./canonical.js";
3
4
  import type { ClientHarness, ResolvedRouterModelConfig, SubscriptionKind } from "../types.js";
4
5
 
5
6
  const CODEX_BACKEND_URL = "https://chatgpt.com/backend-api";
@@ -7,11 +8,18 @@ const CODEX_BACKEND_URL = "https://chatgpt.com/backend-api";
7
8
  // The execution providers whose models each kind of plan serves; a ChatGPT
8
9
  // plan's OpenAI models execute as `openai-codex` once resolve points them at
9
10
  // the Codex backend.
11
+ //
12
+ // The order is the order a model's plans serve it in, maker plans first, then
13
+ // the router's API credential. It matches the control plane's
14
+ // SUBSCRIPTION_OAUTH_PROVIDERS; keep the two in sync.
10
15
  const SUBSCRIPTION_MODEL_PROVIDERS: Record<SubscriptionKind, readonly string[]> = {
11
- openai_codex: ["openai", "openai-codex"],
12
16
  anthropic_claude_code: ["anthropic"],
17
+ openai_codex: ["openai", "openai-codex"],
18
+ xai_grok: ["xai"],
13
19
  meta_muse: ["meta"],
14
20
  opencode_go: ["opencode-go"],
21
+ github_copilot: ["github-copilot"],
22
+ vercel_token_pass: ["vercel-token-pass"],
15
23
  };
16
24
 
17
25
  // The client each plan is limited to, as its provider limits it: a Claude Code
@@ -26,6 +34,18 @@ export function subscriptionModelProvider(kind: SubscriptionKind): string {
26
34
  return SUBSCRIPTION_MODEL_PROVIDERS[kind][0]!;
27
35
  }
28
36
 
37
+ /**
38
+ * The plans that can serve a model, in the order they serve it: each whose
39
+ * provider is the model's maker or serves it as its own model.
40
+ */
41
+ export function modelSubscriptions(modelId: string): SubscriptionKind[] {
42
+ const maker = providerForModel(modelId);
43
+ return (Object.keys(SUBSCRIPTION_MODEL_PROVIDERS) as SubscriptionKind[]).filter((kind) => {
44
+ const provider = subscriptionModelProvider(kind);
45
+ return provider === maker || providerModel(modelId, provider) !== undefined;
46
+ });
47
+ }
48
+
29
49
  /**
30
50
  * The only client a plan may serve, or undefined when it serves any client:
31
51
  * ChatGPT plans serve any client through the Codex backend.
@@ -49,6 +49,7 @@ import {
49
49
  import type { NextSubscription } from "../platform/platform.js";
50
50
  import { providerResponseCaptureFromError, type ProviderResponseCapture } from "./response_capture.js";
51
51
  import { createStreamFinalizer } from "./stream_finalization.js";
52
+ import { copilotEndpoint } from "./github_copilot.js";
52
53
  import { readCodexModelLimitReset, readCodexUsage } from "./codex_usage.js";
53
54
  import {
54
55
  detectSubscriptionUsageLimit,
@@ -67,8 +68,14 @@ import {
67
68
  export type ProviderChoice = {
68
69
  decision: RoutingDecision;
69
70
  execution: ProviderExecution;
71
+ // Which of the model's fallbacks serves, or undefined for its first
72
+ // candidate.
73
+ fallback?: number;
70
74
  };
71
75
 
76
+ // The same model served by its next candidate; see ResolvedRouter.model_fallbacks.
77
+ export type NextProviderChoice = (choice: ProviderChoice) => Promise<ProviderChoice | undefined>;
78
+
72
79
  export type PreparedStreamExecution = {
73
80
  choice: ProviderChoice;
74
81
  started: StartedStream;
@@ -92,6 +99,7 @@ export async function executeNonStreaming(args: {
92
99
  interaction: InteractionRequest;
93
100
  primary: ProviderChoice;
94
101
  primaryRetries: number;
102
+ nextChoice?: NextProviderChoice;
95
103
  reporter: RoutedRuntimeReporter;
96
104
  protocol: RoutedProtocol;
97
105
  startedCompletion?: StartedCompletion;
@@ -132,6 +140,7 @@ export async function completeNonStreaming(args: {
132
140
  interaction: InteractionRequest;
133
141
  primary: ProviderChoice;
134
142
  primaryRetries: number;
143
+ nextChoice?: NextProviderChoice;
135
144
  reporter: RoutedRuntimeReporter;
136
145
  protocol: RoutedProtocol;
137
146
  startedCompletion?: StartedCompletion;
@@ -251,6 +260,7 @@ async function completeWithRetries(args: {
251
260
  interaction: InteractionRequest;
252
261
  primary: ProviderChoice;
253
262
  primaryRetries: number;
263
+ nextChoice?: NextProviderChoice;
254
264
  reporter: RoutedRuntimeReporter;
255
265
  startedCompletion?: StartedCompletion;
256
266
  clientSignal?: AbortSignal;
@@ -271,6 +281,7 @@ async function completeWithRetries(args: {
271
281
  recordFailedAttempt: ({ choice, attempt, result }) =>
272
282
  recordSettledFailure(args.reporter, choice, attempt, result),
273
283
  onSubscription: onNextSubscription,
284
+ nextChoice: args.nextChoice,
274
285
  });
275
286
  }
276
287
 
@@ -493,6 +504,7 @@ export async function prepareStreamingExecution(args: {
493
504
  interaction: InteractionRequest;
494
505
  primary: ProviderChoice;
495
506
  primaryRetries: number;
507
+ nextChoice?: NextProviderChoice;
496
508
  reporter: RoutedRuntimeReporter;
497
509
  startedStream?: StartedStream;
498
510
  initialError?: unknown;
@@ -520,6 +532,7 @@ export async function prepareStreamingExecution(args: {
520
532
  recordFailedAttempt: ({ choice, attempt, result }) =>
521
533
  recordSettledFailure(args.reporter, choice, attempt, result),
522
534
  onSubscription: onNextSubscription,
535
+ nextChoice: args.nextChoice,
523
536
  });
524
537
  args.reporter.attachServingDecision(result.choice.decision);
525
538
  if (result.kind === "customer_canceled") {
@@ -748,6 +761,9 @@ async function providerFailedAttempt(
748
761
  if (execution.providerKeySource === "subscription") logUnclassifiedRefusal(execution, responseCapture);
749
762
  // The customer's own key was refused: theirs to fix, not a gateway fault.
750
763
  const rejected = execution.providerKeySource === "user" && (status === 401 || status === 403);
764
+ // A plan whose token is refused cannot serve; the model's next candidate
765
+ // may. The plan is not held: a refused token is not a usage limit.
766
+ const planRefused = execution.providerKeySource === "subscription" && (status === 401 || status === 403);
751
767
  return {
752
768
  kind: "provider_failed",
753
769
  message: rejected
@@ -755,6 +771,7 @@ async function providerFailedAttempt(
755
771
  : message,
756
772
  latencyMs,
757
773
  retryable: !isPromptPolicyRejection(message),
774
+ ...(planRefused ? { failover: true as const } : {}),
758
775
  };
759
776
  }
760
777
  const limit = detected.oauthProvider === "openai_codex" && detected.model === undefined
@@ -774,7 +791,8 @@ async function providerFailedAttempt(
774
791
  ...(execution.subscriptionLinkGrantId ? { linkGrantId: execution.subscriptionLinkGrantId } : {}),
775
792
  });
776
793
  // Nothing reached the client yet, so the same request is retried on the
777
- // next plan with quota for this model, including model-specific limits.
794
+ // next plan of this kind with quota for this model, including
795
+ // model-specific limits; with none, on the model's next candidate.
778
796
  const nextSubscription = switched
779
797
  ? await nextSubscriptionFor(execution)
780
798
  : undefined;
@@ -783,7 +801,7 @@ async function providerFailedAttempt(
783
801
  message: failureWithSubscriptionUsageLimit(message, { ...limit, switched }),
784
802
  latencyMs,
785
803
  retryable: false,
786
- ...(nextSubscription === undefined ? {} : { nextSubscription }),
804
+ ...(nextSubscription === undefined ? { failover: true as const } : { nextSubscription }),
787
805
  };
788
806
  }
789
807
 
@@ -914,6 +932,8 @@ function onNextSubscription(choice: ProviderChoice, next: NextSubscription): Pro
914
932
  apiKey: next.apiKey,
915
933
  auth: { type: "bearer", apiKey: next.apiKey },
916
934
  subscriptionCredentialId: next.credentialId,
935
+ // A Copilot token names its own account's API origin.
936
+ ...(choice.execution.provider === "github-copilot" ? { endpoint: copilotEndpoint(next.apiKey) } : {}),
917
937
  },
918
938
  };
919
939
  }
@@ -0,0 +1,24 @@
1
+ import type { ProviderEndpoint } from "./pi.js";
2
+
3
+ // Copilot serves only editors that name themselves; these are VS Code's
4
+ // Copilot Chat, whose sign-in Dari runs.
5
+ export const COPILOT_HEADERS: Readonly<Record<string, string>> = {
6
+ "User-Agent": "GitHubCopilotChat/0.35.0",
7
+ "Editor-Version": "vscode/1.107.0",
8
+ "Editor-Plugin-Version": "copilot-chat/0.35.0",
9
+ "Copilot-Integration-Id": "vscode-chat",
10
+ };
11
+
12
+ /**
13
+ * Where a Copilot token is served: its account's API origin, which the token
14
+ * names as `proxy-ep=proxy.<host>` (`api.<host>` serves the models), with the
15
+ * Copilot headers. A token that names none keeps the configured origin.
16
+ */
17
+ export function copilotEndpoint(token: string): ProviderEndpoint {
18
+ const proxy = /(?:^|;)proxy-ep=([^;]+)/.exec(token)?.[1];
19
+ const host = proxy?.replace(/^proxy\./, "api.");
20
+ return {
21
+ ...(host && /^[a-z0-9.-]+$/i.test(host) ? { baseUrl: `https://${host}` } : {}),
22
+ headers: { ...COPILOT_HEADERS },
23
+ };
24
+ }
@@ -473,7 +473,9 @@ function resolveModelMetadata(
473
473
  // Claude deployments through the Anthropic registry, whose model metadata
474
474
  // (input modalities, adaptive-thinking compat, thinking level maps) is the
475
475
  // same on Foundry; the resolved config still owns api, base URL, and cost.
476
+ // A Vercel Token Pass key serves Vercel AI Gateway's own models.
476
477
  function registryProvider(provider: string, modelId: string): string {
478
+ if (provider === "vercel-token-pass") return "vercel-ai-gateway";
477
479
  if (provider !== "azure") return provider;
478
480
  return providerForModel(modelId) === "anthropic" ? "anthropic" : "azure-openai-responses";
479
481
  }