@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
@@ -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
  ]
@@ -2,6 +2,11 @@ import { type RouterModelPrice } from "@mupt-ai/dari-router/policy-engine";
2
2
  import type { ClientHarness, ResolvedRouterModelConfig, SubscriptionKind } from "../types.js";
3
3
  /** The model provider whose models a plan serves, such as `openai`. */
4
4
  export declare function subscriptionModelProvider(kind: SubscriptionKind): string;
5
+ /**
6
+ * The plans that can serve a model, in the order they serve it: each whose
7
+ * provider is the model's maker or serves it as its own model.
8
+ */
9
+ export declare function modelSubscriptions(modelId: string): SubscriptionKind[];
5
10
  /**
6
11
  * The only client a plan may serve, or undefined when it serves any client:
7
12
  * ChatGPT plans serve any client through the Codex backend.
@@ -1,13 +1,21 @@
1
- import { nativeModelId } from "@mupt-ai/dari-router/policy-engine";
1
+ import { nativeModelId, providerForModel } from "@mupt-ai/dari-router/policy-engine";
2
+ import { providerModel } from "./canonical.js";
2
3
  const CODEX_BACKEND_URL = "https://chatgpt.com/backend-api";
3
4
  // The execution providers whose models each kind of plan serves; a ChatGPT
4
5
  // plan's OpenAI models execute as `openai-codex` once resolve points them at
5
6
  // the Codex backend.
7
+ //
8
+ // The order is the order a model's plans serve it in, maker plans first, then
9
+ // the router's API credential. It matches the control plane's
10
+ // SUBSCRIPTION_OAUTH_PROVIDERS; keep the two in sync.
6
11
  const SUBSCRIPTION_MODEL_PROVIDERS = {
7
- openai_codex: ["openai", "openai-codex"],
8
12
  anthropic_claude_code: ["anthropic"],
13
+ openai_codex: ["openai", "openai-codex"],
14
+ xai_grok: ["xai"],
9
15
  meta_muse: ["meta"],
10
16
  opencode_go: ["opencode-go"],
17
+ github_copilot: ["github-copilot"],
18
+ vercel_token_pass: ["vercel-token-pass"],
11
19
  };
12
20
  // The client each plan is limited to, as its provider limits it: a Claude Code
13
21
  // plan serves only Claude Code, and a Muse Code plan only Muse Code.
@@ -19,6 +27,17 @@ const SUBSCRIPTION_CLIENTS = {
19
27
  export function subscriptionModelProvider(kind) {
20
28
  return SUBSCRIPTION_MODEL_PROVIDERS[kind][0];
21
29
  }
30
+ /**
31
+ * The plans that can serve a model, in the order they serve it: each whose
32
+ * provider is the model's maker or serves it as its own model.
33
+ */
34
+ export function modelSubscriptions(modelId) {
35
+ const maker = providerForModel(modelId);
36
+ return Object.keys(SUBSCRIPTION_MODEL_PROVIDERS).filter((kind) => {
37
+ const provider = subscriptionModelProvider(kind);
38
+ return provider === maker || providerModel(modelId, provider) !== undefined;
39
+ });
40
+ }
22
41
  /**
23
42
  * The only client a plan may serve, or undefined when it serves any client:
24
43
  * ChatGPT plans serve any client through the Codex backend.
@@ -7,7 +7,9 @@ import { type ProviderExecution, type StartedCompletion, type StartedStream } fr
7
7
  export type ProviderChoice = {
8
8
  decision: RoutingDecision;
9
9
  execution: ProviderExecution;
10
+ fallback?: number;
10
11
  };
12
+ export type NextProviderChoice = (choice: ProviderChoice) => Promise<ProviderChoice | undefined>;
11
13
  export type PreparedStreamExecution = {
12
14
  choice: ProviderChoice;
13
15
  started: StartedStream;
@@ -25,6 +27,7 @@ export declare function executeNonStreaming(args: {
25
27
  interaction: InteractionRequest;
26
28
  primary: ProviderChoice;
27
29
  primaryRetries: number;
30
+ nextChoice?: NextProviderChoice;
28
31
  reporter: RoutedRuntimeReporter;
29
32
  protocol: RoutedProtocol;
30
33
  startedCompletion?: StartedCompletion;
@@ -36,6 +39,7 @@ export declare function completeNonStreaming(args: {
36
39
  interaction: InteractionRequest;
37
40
  primary: ProviderChoice;
38
41
  primaryRetries: number;
42
+ nextChoice?: NextProviderChoice;
39
43
  reporter: RoutedRuntimeReporter;
40
44
  protocol: RoutedProtocol;
41
45
  startedCompletion?: StartedCompletion;
@@ -47,6 +51,7 @@ export declare function prepareStreamingExecution(args: {
47
51
  interaction: InteractionRequest;
48
52
  primary: ProviderChoice;
49
53
  primaryRetries: number;
54
+ nextChoice?: NextProviderChoice;
50
55
  reporter: RoutedRuntimeReporter;
51
56
  startedStream?: StartedStream;
52
57
  initialError?: unknown;
@@ -12,6 +12,7 @@ import { runProviderAttemptPlan, } from "./provider_attempt_runner.js";
12
12
  import { estimatedCancelUsage, NO_DELIVERED_OUTPUT, observeDeliveredOutput, } from "./cancel_estimate.js";
13
13
  import { providerResponseCaptureFromError } from "./response_capture.js";
14
14
  import { createStreamFinalizer } from "./stream_finalization.js";
15
+ import { copilotEndpoint } from "./github_copilot.js";
15
16
  import { readCodexModelLimitReset, readCodexUsage } from "./codex_usage.js";
16
17
  import { detectSubscriptionUsageLimit, codexUsageLimitError, subscriptionOAuthProviderFor, subscriptionUsageFromHeaders, museSubscriptionUsage, failureWithSubscriptionUsageLimit, retryAfterSeconds, subscriptionUsageLimitFromFailure, subscriptionSwitchedMessage, subscriptionUsageLimitMessage, } from "./subscription_limits.js";
17
18
  export async function executeNonStreaming(args) {
@@ -150,6 +151,7 @@ async function completeWithRetries(args) {
150
151
  }),
151
152
  recordFailedAttempt: ({ choice, attempt, result }) => recordSettledFailure(args.reporter, choice, attempt, result),
152
153
  onSubscription: onNextSubscription,
154
+ nextChoice: args.nextChoice,
153
155
  });
154
156
  }
155
157
  async function runCompletionAttempt(args) {
@@ -293,6 +295,7 @@ export async function prepareStreamingExecution(args) {
293
295
  }),
294
296
  recordFailedAttempt: ({ choice, attempt, result }) => recordSettledFailure(args.reporter, choice, attempt, result),
295
297
  onSubscription: onNextSubscription,
298
+ nextChoice: args.nextChoice,
296
299
  });
297
300
  args.reporter.attachServingDecision(result.choice.decision);
298
301
  if (result.kind === "customer_canceled") {
@@ -447,6 +450,9 @@ async function providerFailedAttempt(message, latencyMs, execution, responseCapt
447
450
  logUnclassifiedRefusal(execution, responseCapture);
448
451
  // The customer's own key was refused: theirs to fix, not a gateway fault.
449
452
  const rejected = execution.providerKeySource === "user" && (status === 401 || status === 403);
453
+ // A plan whose token is refused cannot serve; the model's next candidate
454
+ // may. The plan is not held: a refused token is not a usage limit.
455
+ const planRefused = execution.providerKeySource === "subscription" && (status === 401 || status === 403);
450
456
  return {
451
457
  kind: "provider_failed",
452
458
  message: rejected
@@ -454,6 +460,7 @@ async function providerFailedAttempt(message, latencyMs, execution, responseCapt
454
460
  : message,
455
461
  latencyMs,
456
462
  retryable: !isPromptPolicyRejection(message),
463
+ ...(planRefused ? { failover: true } : {}),
457
464
  };
458
465
  }
459
466
  const limit = detected.oauthProvider === "openai_codex" && detected.model === undefined
@@ -473,7 +480,8 @@ async function providerFailedAttempt(message, latencyMs, execution, responseCapt
473
480
  ...(execution.subscriptionLinkGrantId ? { linkGrantId: execution.subscriptionLinkGrantId } : {}),
474
481
  });
475
482
  // Nothing reached the client yet, so the same request is retried on the
476
- // next plan with quota for this model, including model-specific limits.
483
+ // next plan of this kind with quota for this model, including
484
+ // model-specific limits; with none, on the model's next candidate.
477
485
  const nextSubscription = switched
478
486
  ? await nextSubscriptionFor(execution)
479
487
  : undefined;
@@ -482,7 +490,7 @@ async function providerFailedAttempt(message, latencyMs, execution, responseCapt
482
490
  message: failureWithSubscriptionUsageLimit(message, { ...limit, switched }),
483
491
  latencyMs,
484
492
  retryable: false,
485
- ...(nextSubscription === undefined ? {} : { nextSubscription }),
493
+ ...(nextSubscription === undefined ? { failover: true } : { nextSubscription }),
486
494
  };
487
495
  }
488
496
  // The provider call was in flight, so the prompt was paid for. A completion
@@ -597,6 +605,8 @@ function onNextSubscription(choice, next) {
597
605
  apiKey: next.apiKey,
598
606
  auth: { type: "bearer", apiKey: next.apiKey },
599
607
  subscriptionCredentialId: next.credentialId,
608
+ // A Copilot token names its own account's API origin.
609
+ ...(choice.execution.provider === "github-copilot" ? { endpoint: copilotEndpoint(next.apiKey) } : {}),
600
610
  },
601
611
  };
602
612
  }
@@ -0,0 +1,8 @@
1
+ import type { ProviderEndpoint } from "./pi.js";
2
+ export declare const COPILOT_HEADERS: Readonly<Record<string, string>>;
3
+ /**
4
+ * Where a Copilot token is served: its account's API origin, which the token
5
+ * names as `proxy-ep=proxy.<host>` (`api.<host>` serves the models), with the
6
+ * Copilot headers. A token that names none keeps the configured origin.
7
+ */
8
+ export declare function copilotEndpoint(token: string): ProviderEndpoint;
@@ -0,0 +1,21 @@
1
+ // Copilot serves only editors that name themselves; these are VS Code's
2
+ // Copilot Chat, whose sign-in Dari runs.
3
+ export const COPILOT_HEADERS = {
4
+ "User-Agent": "GitHubCopilotChat/0.35.0",
5
+ "Editor-Version": "vscode/1.107.0",
6
+ "Editor-Plugin-Version": "copilot-chat/0.35.0",
7
+ "Copilot-Integration-Id": "vscode-chat",
8
+ };
9
+ /**
10
+ * Where a Copilot token is served: its account's API origin, which the token
11
+ * names as `proxy-ep=proxy.<host>` (`api.<host>` serves the models), with the
12
+ * Copilot headers. A token that names none keeps the configured origin.
13
+ */
14
+ export function copilotEndpoint(token) {
15
+ const proxy = /(?:^|;)proxy-ep=([^;]+)/.exec(token)?.[1];
16
+ const host = proxy?.replace(/^proxy\./, "api.");
17
+ return {
18
+ ...(host && /^[a-z0-9.-]+$/i.test(host) ? { baseUrl: `https://${host}` } : {}),
19
+ headers: { ...COPILOT_HEADERS },
20
+ };
21
+ }
@@ -280,7 +280,10 @@ function resolveModelMetadata(pi, provider, modelId, nativeId) {
280
280
  // Claude deployments through the Anthropic registry, whose model metadata
281
281
  // (input modalities, adaptive-thinking compat, thinking level maps) is the
282
282
  // same on Foundry; the resolved config still owns api, base URL, and cost.
283
+ // A Vercel Token Pass key serves Vercel AI Gateway's own models.
283
284
  function registryProvider(provider, modelId) {
285
+ if (provider === "vercel-token-pass")
286
+ return "vercel-ai-gateway";
284
287
  if (provider !== "azure")
285
288
  return provider;
286
289
  return providerForModel(modelId) === "anthropic" ? "anthropic" : "azure-openai-responses";
@@ -5,6 +5,7 @@ export type ProviderAttemptFailure = {
5
5
  latencyMs: number;
6
6
  retryable: boolean;
7
7
  nextSubscription?: NextSubscription;
8
+ failover?: true;
8
9
  } | {
9
10
  kind: "customer_canceled";
10
11
  message: Record<string, unknown>;
@@ -47,6 +48,7 @@ type RunProviderAttemptPlanArgs<TChoice, TValue, TInitial> = {
47
48
  result: ProviderAttemptFailure;
48
49
  }) => void;
49
50
  onSubscription?: (choice: TChoice, next: NextSubscription) => TChoice;
51
+ nextChoice?: (choice: TChoice) => Promise<TChoice | undefined>;
50
52
  };
51
53
  /**
52
54
  * Owns the order-sensitive provider plan shared by completion and stream setup:
@@ -66,6 +66,15 @@ async function runChoice(args, firstChoice, initial) {
66
66
  maxAttempts += 1;
67
67
  continue;
68
68
  }
69
+ if (result.kind === "provider_failed" && result.failover === true && args.nextChoice) {
70
+ const next = await args.nextChoice(choice);
71
+ if (next !== undefined) {
72
+ // The next candidate gets the router's full retry budget.
73
+ choice = next;
74
+ maxAttempts = attempt + args.retries + 1;
75
+ continue;
76
+ }
77
+ }
69
78
  if (!result.retryable)
70
79
  break;
71
80
  }
@@ -7,6 +7,7 @@ import { providerAuthForSelectedModel } from "../strategies/routing.js";
7
7
  import { scrubSecretValues } from "../telemetry/scrub.js";
8
8
  import { usageContextFor, } from "../telemetry/usage.js";
9
9
  import { awsRoleCredentials } from "./aws_assume_role.js";
10
+ import { copilotEndpoint } from "./github_copilot.js";
10
11
  import { attachProviderResponseCapture, createProviderResponseCapture, } from "./response_capture.js";
11
12
  import { subscriptionOAuthProviderFor } from "./subscription_limits.js";
12
13
  import { completeInteractionModel, streamInteractionModel, } from "./pi.js";
@@ -50,7 +51,10 @@ export function prepareProviderExecution(args) {
50
51
  ...(args.systemPromptSuffix ? { systemPromptSuffix: args.systemPromptSuffix } : {}),
51
52
  ...(supplied?.baseUrl || supplied?.headers
52
53
  ? { endpoint: { baseUrl: supplied.baseUrl, headers: supplied.headers } }
53
- : {}),
54
+ // A Copilot token names its account's own API origin.
55
+ : provider === "github-copilot" && auth.type === "bearer"
56
+ ? { endpoint: copilotEndpoint(auth.apiKey) }
57
+ : {}),
54
58
  provider,
55
59
  providerKeySource,
56
60
  // Only resolved personal subscriptions are held at their usage limit;
@@ -58,7 +62,7 @@ export function prepareProviderExecution(args) {
58
62
  ...(providerKeySource === "subscription" && (!supplied || supplied.credentialId !== undefined) && args.credentials.attributed_user_id
59
63
  ? {
60
64
  subscriptionUserId: args.credentials.attributed_user_id,
61
- subscriptionCredentialId: supplied?.credentialId ?? args.credentials.subscription_credential_ids?.[provider],
65
+ subscriptionCredentialId: supplied?.credentialId,
62
66
  ...(args.credentials.link_grant_id ? { subscriptionLinkGrantId: args.credentials.link_grant_id } : {}),
63
67
  }
64
68
  : {}),
@@ -1,6 +1,6 @@
1
- import type { ProviderKeySource } from "../types.js";
1
+ import type { ProviderKeySource, SubscriptionKind } from "../types.js";
2
2
  import type { CapturedProviderResponse } from "./response_capture.js";
3
- export type SubscriptionOAuthProvider = "anthropic_claude_code" | "openai_codex" | "meta_muse" | "opencode_go";
3
+ export type SubscriptionOAuthProvider = SubscriptionKind;
4
4
  export type SubscriptionUsageLimit = {
5
5
  oauthProvider: SubscriptionOAuthProvider;
6
6
  resetsAt: Date;
@@ -60,9 +60,10 @@ export declare function subscriptionOAuthProviderFor(provider: string, keySource
60
60
  /**
61
61
  * Recognize a personal subscription that has run out of quota. Claude Code
62
62
  * answers 429 with the unified rate-limit headers; the ChatGPT backend answers
63
- * 429 with a structured `error.code` and `resets_at`. Meta documents no
64
- * usage-limit signature for Muse Code plans, so any 429 on one holds it until
65
- * the reset Meta gives, if any. OpenCode Go names its refusal
63
+ * 429 with a structured `error.code` and `resets_at`. Meta, GitHub Copilot,
64
+ * xAI, Kimi, and Vercel Token Pass document no usage-limit signature for their
65
+ * plans, so any 429 on one holds it until the reset it gives, if any. OpenCode
66
+ * Go names its refusal
66
67
  * `GoUsageLimitError`. The Codex WebSocket
67
68
  * transport bypasses fetch, so its usage-limit error only survives as message
68
69
  * text and is matched there without a reset time.
@@ -105,6 +105,9 @@ const SUBSCRIPTION_LABEL = {
105
105
  openai_codex: "ChatGPT",
106
106
  meta_muse: "Muse Code",
107
107
  opencode_go: "OpenCode Go",
108
+ github_copilot: "GitHub Copilot",
109
+ xai_grok: "Grok",
110
+ vercel_token_pass: "Vercel Token Pass",
108
111
  };
109
112
  // Providers whose plan page the accounts page links to for buying another.
110
113
  const BUYABLE_SUBSCRIPTIONS = new Set(["anthropic_claude_code", "openai_codex"]);
@@ -119,14 +122,21 @@ export function subscriptionOAuthProviderFor(provider, keySource) {
119
122
  return "meta_muse";
120
123
  if (provider === "opencode-go")
121
124
  return "opencode_go";
125
+ if (provider === "github-copilot")
126
+ return "github_copilot";
127
+ if (provider === "xai")
128
+ return "xai_grok";
129
+ if (provider === "vercel-token-pass")
130
+ return "vercel_token_pass";
122
131
  return null;
123
132
  }
124
133
  /**
125
134
  * Recognize a personal subscription that has run out of quota. Claude Code
126
135
  * answers 429 with the unified rate-limit headers; the ChatGPT backend answers
127
- * 429 with a structured `error.code` and `resets_at`. Meta documents no
128
- * usage-limit signature for Muse Code plans, so any 429 on one holds it until
129
- * the reset Meta gives, if any. OpenCode Go names its refusal
136
+ * 429 with a structured `error.code` and `resets_at`. Meta, GitHub Copilot,
137
+ * xAI, Kimi, and Vercel Token Pass document no usage-limit signature for their
138
+ * plans, so any 429 on one holds it until the reset it gives, if any. OpenCode
139
+ * Go names its refusal
130
140
  * `GoUsageLimitError`. The Codex WebSocket
131
141
  * transport bypasses fetch, so its usage-limit error only survives as message
132
142
  * text and is matched there without a reset time.
@@ -139,11 +149,12 @@ export function detectSubscriptionUsageLimit(args) {
139
149
  if (oauthProvider === "anthropic_claude_code") {
140
150
  return anthropicUsageLimit(args.captured, args.model, now);
141
151
  }
142
- if (oauthProvider === "meta_muse")
143
- return museUsageLimit(args.captured, now);
144
152
  if (oauthProvider === "opencode_go")
145
153
  return openCodeGoUsageLimit(args.captured, now);
146
- return codexUsageLimit(args.captured, providerFailureMessage(args.failure), args.model, now);
154
+ if (oauthProvider === "openai_codex") {
155
+ return codexUsageLimit(args.captured, providerFailureMessage(args.failure), args.model, now);
156
+ }
157
+ return planRateLimit(oauthProvider, args.captured, now);
147
158
  }
148
159
  // Claude Code plans also cap some model families on their own
149
160
  // (`seven_day_opus`, `seven_day_sonnet`). The representative claim names the
@@ -215,13 +226,13 @@ function codexModelLimitExhausted(headers) {
215
226
  });
216
227
  return other && !plan;
217
228
  }
218
- function museUsageLimit(captured, now) {
229
+ function planRateLimit(oauthProvider, captured, now) {
219
230
  if (captured === undefined || captured.status !== 429)
220
231
  return null;
221
232
  return {
222
- oauthProvider: "meta_muse",
233
+ oauthProvider,
223
234
  resetsAt: laterReset(codexErrorBody(captured.bodyText)?.resets_at, captured.headers, now),
224
- reason: "Muse Code usage limit reached.",
235
+ reason: `${SUBSCRIPTION_LABEL[oauthProvider]} usage limit reached.`,
225
236
  };
226
237
  }
227
238
  // OpenCode Go refuses an exhausted plan with 429 and a `GoUsageLimitError`
@@ -0,0 +1,2 @@
1
+ import type { ClientHarness } from "../types.js";
2
+ export declare function withModelMenuHint(error: unknown, clientHarness: ClientHarness | undefined): unknown;
@@ -0,0 +1,13 @@
1
+ import { errorResponseHeaders, HttpError, normalizeError } from "../http/errors.js";
2
+ /* Codex fills its /model menu from the router's model list and keeps the
3
+ copy it read: one read before the router's models changed still offers a
4
+ model the router no longer serves. Codex shows the user this error's
5
+ message, so for Codex the message says how to bring the menu up to date. */
6
+ export function withModelMenuHint(error, clientHarness) {
7
+ if (clientHarness !== "codex")
8
+ return error;
9
+ const { status, message, code, param } = normalizeError(error);
10
+ if (code !== "model_not_enabled")
11
+ return error;
12
+ return new HttpError(status, `${message} Codex's /model list may be out of date: run \`dari setup codex --refresh\`.`, code, param, errorResponseHeaders(error), error instanceof HttpError ? error.body : undefined);
13
+ }
@@ -1,6 +1,6 @@
1
1
  import { type InteractionRequest } from "../interaction/types.js";
2
2
  import type { SelectorBackend } from "../strategies/routing.js";
3
- import type { ClientHarness } from "../types.js";
3
+ import type { ClientHarness, ResolvedRouter } from "../types.js";
4
4
  import type { HarnessConversationIdentity } from "./harness_identity/index.js";
5
5
  import type { RoutedProtocol } from "./routed_protocol.js";
6
6
  export declare function handleRoutedCompletion(args: {
@@ -14,4 +14,5 @@ export declare function handleRoutedCompletion(args: {
14
14
  selectorBackend: SelectorBackend;
15
15
  clientHarness?: ClientHarness;
16
16
  harnessConversationIdentity?: HarnessConversationIdentity;
17
+ responseHeaders?: (router: ResolvedRouter) => Record<string, string>;
17
18
  }): Promise<Response>;