@diegopetrucci/pi-fast 0.1.5 → 0.1.7

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 (3) hide show
  1. package/README.md +63 -12
  2. package/index.ts +194 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # fast
2
2
 
3
- A pi extension that provides one `/fast` toggle for supported direct OpenAI API, OpenAI Codex, and Anthropic Claude models. It selects the provider-specific Fast-mode request shape from the currently selected model.
3
+ A pi extension that provides `/fast` and `/ultrafast` toggles for supported direct OpenAI API, OpenAI Codex, and Anthropic Claude models. It selects the provider-specific Fast-mode request shape from the currently selected model.
4
4
 
5
5
  For eligible direct OpenAI API models it injects:
6
6
 
@@ -51,20 +51,56 @@ request shape is support evidence, not live certification; this change was
51
51
  validated only with mocked eligibility and request payloads, not live or paid
52
52
  provider calls.
53
53
 
54
+ ### Ultrafast support (initial, fail-closed)
55
+
56
+ Ultrafast is intentionally narrower than ordinary Fast mode. It requires all of
57
+ the following on every activation and provider request:
58
+
59
+ - Provider `openai`.
60
+ - API `openai-responses`.
61
+ - Model `gpt-6-astra`.
62
+ - Direct API-key auth, not Codex OAuth or direct OpenAI OAuth.
63
+ - Base URL exactly `https://api.openai.com/v1` (a single trailing slash is also accepted).
64
+
65
+ It does not support Chat Completions, preview models, regional or proxy endpoints,
66
+ or Anthropic Ultrafast. Eligible payloads receive the requested
67
+ `service_tier: "ultrafast"` only when they do not already contain a
68
+ `service_tier` field. Existing values and mismatched/malformed payloads are left
69
+ untouched. The extension reports a requested tier; it does not claim that OpenAI
70
+ accepted or applied it, and it never silently falls back to ordinary Fast.
71
+
72
+ OpenAI documents this request shape in the [Ultrafast API guide](https://developers.openai.com/api/docs/guides/ultrafast-mode)
73
+ and lists the account/model pricing in its [API pricing](https://developers.openai.com/api/docs/pricing).
74
+ Actual Ultrafast API pricing is **6x Standard**, while Pi's current cost display
75
+ omits that premium. Treat the activation warning as a deliberate paid-usage
76
+ warning.
77
+
54
78
  OpenAI Codex Fast mode requires all of the following:
55
79
 
56
80
  - Provider `openai-codex`.
57
81
  - API `openai-codex-responses`.
58
- - Model `gpt-5.5`, `gpt-5.6-sol`, `gpt-5.6-terra`, or `gpt-5.6-luna`.
82
+ - Model `gpt-5.5`, `gpt-5.6-sol`, `gpt-5.6-terra`, `gpt-5.6-luna`, `gpt-6-astra`, `gpt-6.1-sol`, `gpt-6-sol`, or `gpt-6-luna`.
59
83
  - ChatGPT OAuth/subscription auth, not API-key auth.
60
84
  - No existing `service_tier` field in the request payload.
61
85
 
62
- GPT-6.1 Sol is intentionally unsupported on this legacy Codex route. The
63
- Codex speed documentation lists GPT-6.1 Sol Fast with `service_tier: "fast"`,
64
- but Pi's legacy Codex service-tier cost handling currently accounts for
65
- `priority` and `flex`, not `fast`. The direct OpenAI API's `priority` alias is
66
- not evidence for the legacy Codex endpoint, so this extension leaves the route
67
- fail-closed without patching upstream pricing.
86
+ Codex evidence, 2026-10-03: the [maintainer's PR #103 review](https://github.com/diegopetrucci/pi-extensions/pull/103)
87
+ reports that the Codex model list advertises Fast as `priority` for `gpt-6-astra`,
88
+ `gpt-6.1-sol`, `gpt-6-sol`, and `gpt-6-luna`. The official Codex CLI
89
+ [sends Fast as `priority`](https://github.com/openai/codex/blob/b741e480e203f037ca726bc2a76d99a8e8668e66/codex-rs/protocol/src/config_types.rs#L539-L553).
90
+ The maintainer's live check through Pi 1.0.0 on that date returned HTTP 200 and
91
+ completed normally for `gpt-6-astra` and `gpt-6.1-sol`; `gpt-6-sol` and
92
+ `gpt-6-luna` are enabled based on the model list only. In that check,
93
+ `response.completed` always reported `service_tier: "default"`, with or without
94
+ `priority`, so the response cannot confirm Fast was applied.
95
+
96
+ Pi trusts the requested tier and applies a 2× multiplier to its displayed cost
97
+ estimate for `priority`; this does not measure included subscription allowance
98
+ consumption or confirm Fast was applied. [OpenAI's Codex speed documentation](https://developers.openai.com/codex/speed),
99
+ checked on 2026-10-03, lists `gpt-6-sol` and `gpt-6-luna` among supported Fast
100
+ models where available. It specifies 2.5× the Standard rate for included
101
+ subscription limits and 2× for purchased credits and Enterprise pay-as-you-go
102
+ billing. Treating Pi's 2× estimate as a subscription-limit multiplier would
103
+ understate the documented allowance consumption.
68
104
 
69
105
  Anthropic Fast mode requires all of the following:
70
106
 
@@ -79,11 +115,26 @@ Anthropic Fast mode supports both API-key and Claude Code OAuth access when the
79
115
 
80
116
  ```text
81
117
  /fast
118
+ /ultrafast
119
+ /fast ultrafast
82
120
  ```
83
121
 
84
- Run `/fast` to toggle Fast mode for the current session/runtime. The enabled state follows model changes: switching between eligible OpenAI and Anthropic models automatically changes the request format without resetting the toggle. The footer shows `fast` only while the selected model is eligible and Fast mode is enabled.
122
+ Run `/fast` to toggle ordinary Fast mode for the current session/runtime. The
123
+ enabled state follows model changes: switching between eligible OpenAI and
124
+ Anthropic models automatically changes the request format without resetting the
125
+ toggle. The footer shows `fast` only while the selected model is eligible and
126
+ Fast mode is enabled.
127
+
128
+ `/ultrafast` and `/fast ultrafast` are equivalent toggles for the session-only
129
+ Ultrafast override. Ultrafast defaults off, is never enabled by global or project
130
+ configuration, and can be undone with either command. Running ordinary `/fast`
131
+ while Ultrafast is selected turns Ultrafast off rather than silently switching to
132
+ another paid tier. Switching to an unsupported model or endpoint disables
133
+ Ultrafast and does not re-enable it when `gpt-6-astra` is selected again. The
134
+ footer uses `ultrafast` while an eligible request is selected; status text says
135
+ that the tier is requested, not remotely applied.
85
136
 
86
- The extension defaults to off so installing the full collection does not accidentally spend Fast-mode credits.
137
+ The extension defaults to off so installing the full collection does not accidentally spend Fast-mode credits. Ultrafast verification is mocked-only: tests use local eligibility checks, fake payloads, and a fake fetch through Pi's `openai-responses` `streamSimple`; they make no live or paid provider requests.
87
138
 
88
139
  ## Config
89
140
 
@@ -148,9 +199,9 @@ The collection package loads this unified extension instead of `openai-fast` and
148
199
  - Anthropic Fast mode has separate rate limits, costs more than standard speed, and does not share prompt-cache prefixes with standard-speed requests.
149
200
  - Direct OpenAI Fast mode is limited to the confirmed GPT-6 API models above; Fast pricing, availability, and rate limits remain provider- and account-dependent.
150
201
  - Authoritative support evidence: [OpenAI Fast mode](https://developers.openai.com/api/docs/guides/fast-mode) explicitly uses `gpt-6.1-sol` with `service_tier: "fast"` and documents `priority` as an equivalent alias for supported API models; the [GPT-6.1 Sol model page](https://developers.openai.com/api/docs/models/gpt-6.1-sol) documents the model itself.
151
- - The [Codex speed guide](https://developers.openai.com/codex/speed/) documents GPT-6.1 Sol Fast for ChatGPT-signed-in Codex, but legacy Codex support remains pending separate wire and cost validation; this ticket makes no live-certification claim.
202
+ - Codex Fast availability depends on plan, client, workspace settings, and rollout. Local eligibility is not live-provider certification.
152
203
  - Pi's provider catalog remains the source of reported model pricing, including any tiered pricing; this extension does not apply guessed discounts or rewrite cost metadata.
153
- - OpenAI Codex Fast mode intentionally does not affect API-key models, and GPT-6.1 Sol remains blocked on the legacy Codex route.
204
+ - OpenAI Codex Fast mode intentionally does not affect API-key models.
154
205
  - The retired `openai-fast` and `claude-fast` packages remain legacy standalone boundaries; new provider/auth behavior belongs only to this unified extension.
155
206
  - Existing `speed` and `service_tier` fields are never overwritten.
156
207
  - Pi's model catalog may not include a Fast-mode premium. Cost accounting depends on the provider reporting the effective tier in its streamed response, and this extension does not patch usage totals.
package/index.ts CHANGED
@@ -25,11 +25,19 @@ const OPENAI_SUPPORTED_MODELS = new Set([
25
25
  "gpt-5.6-sol",
26
26
  "gpt-5.6-terra",
27
27
  "gpt-5.6-luna",
28
+ "gpt-6-astra",
29
+ "gpt-6.1-sol",
30
+ "gpt-6-sol",
31
+ "gpt-6-luna",
28
32
  ]);
29
33
  const OPENAI_API_PROVIDER_ID = "openai";
30
34
  const OPENAI_API_IDS = new Set(["openai-responses", "openai-completions"]);
31
35
  const OPENAI_API_FAST_SERVICE_TIER = "fast";
32
36
  const OPENAI_API_SUPPORTED_MODELS = new Set(["gpt-6.1-sol", "gpt-6-astra", "gpt-6-sol", "gpt-6-luna"]);
37
+ const OPENAI_ULTRAFAST_MODEL = "gpt-6-astra";
38
+ const OPENAI_ULTRAFAST_API_ID = "openai-responses";
39
+ const OPENAI_ULTRAFAST_SERVICE_TIER = "ultrafast";
40
+ const OPENAI_CANONICAL_BASE_URL = "https://api.openai.com/v1";
33
41
 
34
42
  const DEFAULT_CONFIG: FastConfig = {
35
43
  enabled: false,
@@ -49,6 +57,8 @@ type FastConfig = {
49
57
  type SessionState = {
50
58
  config: FastConfig;
51
59
  override: FastOverride;
60
+ /** Session-only Ultrafast selection; never loaded from configuration. */
61
+ ultrafast: boolean;
52
62
  lastInjectedAt?: number;
53
63
  lastInjectedModel?: string;
54
64
  };
@@ -235,6 +245,73 @@ function getEligibility(ctx: ExtensionContext): Eligibility {
235
245
  };
236
246
  }
237
247
 
248
+ function isCanonicalOpenAIEndpoint(baseUrl: unknown): boolean {
249
+ return baseUrl === OPENAI_CANONICAL_BASE_URL || baseUrl === `${OPENAI_CANONICAL_BASE_URL}/`;
250
+ }
251
+
252
+ function getUltrafastEligibility(ctx: ExtensionContext): Eligibility {
253
+ const model = ctx.model;
254
+ if (!model) {
255
+ return { eligible: false, modelKey: "no-model", reason: "no model is selected" };
256
+ }
257
+
258
+ const key = `${model.provider}/${model.id}`;
259
+ if (model.provider !== OPENAI_API_PROVIDER_ID) {
260
+ return {
261
+ eligible: false,
262
+ modelKey: key,
263
+ reason: "Ultrafast mode requires the direct OpenAI provider",
264
+ };
265
+ }
266
+
267
+ if (model.api !== OPENAI_ULTRAFAST_API_ID) {
268
+ return {
269
+ eligible: false,
270
+ modelKey: key,
271
+ reason: `Ultrafast mode requires API ${OPENAI_ULTRAFAST_API_ID}`,
272
+ };
273
+ }
274
+
275
+ if (model.id !== OPENAI_ULTRAFAST_MODEL) {
276
+ return {
277
+ eligible: false,
278
+ modelKey: key,
279
+ reason: `Ultrafast mode is only enabled for ${OPENAI_ULTRAFAST_MODEL}`,
280
+ };
281
+ }
282
+
283
+ if (!isCanonicalOpenAIEndpoint(model.baseUrl)) {
284
+ return {
285
+ eligible: false,
286
+ modelKey: key,
287
+ reason: `Ultrafast mode requires the canonical endpoint ${OPENAI_CANONICAL_BASE_URL}`,
288
+ };
289
+ }
290
+
291
+ try {
292
+ if (ctx.modelRegistry.isUsingOAuth(model)) {
293
+ return {
294
+ eligible: false,
295
+ modelKey: key,
296
+ reason: "Ultrafast mode requires direct OpenAI API-key auth; OAuth is unsupported",
297
+ };
298
+ }
299
+ } catch {
300
+ return {
301
+ eligible: false,
302
+ modelKey: key,
303
+ reason: "Ultrafast mode requires direct OpenAI API-key auth; auth could not be verified",
304
+ };
305
+ }
306
+
307
+ return {
308
+ eligible: true,
309
+ modelKey: key,
310
+ provider: "openai",
311
+ serviceTier: OPENAI_ULTRAFAST_SERVICE_TIER,
312
+ };
313
+ }
314
+
238
315
  function updateStatus(ctx: ExtensionContext, state: SessionState): void {
239
316
  if (!ctx.hasUI) return;
240
317
  if (!state.config.showStatus) {
@@ -242,6 +319,12 @@ function updateStatus(ctx: ExtensionContext, state: SessionState): void {
242
319
  return;
243
320
  }
244
321
 
322
+ if (state.ultrafast) {
323
+ const eligibility = getUltrafastEligibility(ctx);
324
+ ctx.ui.setStatus(EXTENSION_ID, eligibility.eligible ? "ultrafast" : undefined);
325
+ return;
326
+ }
327
+
245
328
  const eligibility = getEligibility(ctx);
246
329
  ctx.ui.setStatus(
247
330
  EXTENSION_ID,
@@ -250,13 +333,22 @@ function updateStatus(ctx: ExtensionContext, state: SessionState): void {
250
333
  }
251
334
 
252
335
  function getStatusMessage(ctx: ExtensionContext, state: SessionState): string {
253
- const enabled = isFastEnabled(state);
254
- const eligibility = getEligibility(ctx);
255
- const active = enabled && eligibility.eligible;
256
336
  const injected = state.lastInjectedAt
257
337
  ? ` Last injected for ${state.lastInjectedModel ?? "unknown model"} ${Math.max(0, Math.round((Date.now() - state.lastInjectedAt) / 1000))}s ago.`
258
338
  : "";
259
339
 
340
+ if (state.ultrafast) {
341
+ const eligibility = getUltrafastEligibility(ctx);
342
+ if (eligibility.eligible) {
343
+ return `Ultrafast mode is on (session only) and eligible for ${eligibility.modelKey}; requested service_tier=${OPENAI_ULTRAFAST_SERVICE_TIER}. Actual API pricing is 6x Standard, but Pi's current cost display omits this premium.${injected}`;
344
+ }
345
+ return `Ultrafast mode is on (session only), but not eligible for ${eligibility.modelKey}: ${eligibility.reason}.${injected}`;
346
+ }
347
+
348
+ const enabled = isFastEnabled(state);
349
+ const eligibility = getEligibility(ctx);
350
+ const active = enabled && eligibility.eligible;
351
+
260
352
  if (active) {
261
353
  const wireSetting =
262
354
  eligibility.provider === "anthropic"
@@ -312,7 +404,7 @@ async function injectAnthropicFastHeader(
312
404
  state: SessionState,
313
405
  hasActiveTools: boolean,
314
406
  ): Promise<void> {
315
- if (!isFastEnabled(state)) return;
407
+ if (state.ultrafast || !isFastEnabled(state)) return;
316
408
  const eligibility = getEligibility(ctx);
317
409
  if (!eligibility.eligible || eligibility.provider !== "anthropic") return;
318
410
 
@@ -333,12 +425,29 @@ async function injectAnthropicFastHeader(
333
425
  headers[outputKey] = next.join(",");
334
426
  }
335
427
 
428
+ function injectUltrafastPayload(
429
+ payload: unknown,
430
+ ctx: ExtensionContext,
431
+ state: SessionState,
432
+ ): PayloadRecord | undefined {
433
+ if (!state.ultrafast) return undefined;
434
+ const eligibility = getUltrafastEligibility(ctx);
435
+ if (!eligibility.eligible || !eligibility.serviceTier) return undefined;
436
+ if (!isPayloadRecord(payload)) return undefined;
437
+ if (payload.model !== ctx.model?.id) return undefined;
438
+ if ("service_tier" in payload) return undefined;
439
+
440
+ state.lastInjectedAt = Date.now();
441
+ state.lastInjectedModel = eligibility.modelKey;
442
+ return { ...payload, service_tier: eligibility.serviceTier };
443
+ }
444
+
336
445
  function injectFastPayload(
337
446
  payload: unknown,
338
447
  ctx: ExtensionContext,
339
448
  state: SessionState,
340
449
  ): PayloadRecord | undefined {
341
- if (!isFastEnabled(state)) return undefined;
450
+ if (state.ultrafast || !isFastEnabled(state)) return undefined;
342
451
  const eligibility = getEligibility(ctx);
343
452
  if (!eligibility.eligible || !eligibility.provider) return undefined;
344
453
  if (!isPayloadRecord(payload)) return undefined;
@@ -358,6 +467,34 @@ function injectFastPayload(
358
467
  return { ...payload, service_tier: eligibility.serviceTier };
359
468
  }
360
469
 
470
+ function disableUltrafast(ctx: ExtensionContext, state: SessionState, reason?: string): void {
471
+ state.ultrafast = false;
472
+ // Do not fall back to ordinary Fast when a selected Ultrafast model becomes ineligible.
473
+ state.override = "off";
474
+ updateStatus(ctx, state);
475
+ if (reason) {
476
+ ctx.ui.notify(`Ultrafast mode disabled: ${reason}. It remains off until manually enabled.`, "warning");
477
+ }
478
+ }
479
+
480
+ function toggleUltrafast(ctx: ExtensionContext, state: SessionState): void {
481
+ if (state.ultrafast) {
482
+ disableUltrafast(ctx, state);
483
+ ctx.ui.notify("Ultrafast mode is off (session only); regular Fast remains off until /fast is toggled.", "info");
484
+ return;
485
+ }
486
+
487
+ const eligibility = getUltrafastEligibility(ctx);
488
+ if (!eligibility.eligible) {
489
+ ctx.ui.notify(`Cannot enable Ultrafast mode for ${eligibility.modelKey}: ${eligibility.reason}.`, "error");
490
+ return;
491
+ }
492
+
493
+ state.ultrafast = true;
494
+ updateStatus(ctx, state);
495
+ ctx.ui.notify(getStatusMessage(ctx, state), "info");
496
+ }
497
+
361
498
  export default function fastExtension(pi: ExtensionAPI) {
362
499
  const states = new WeakMap<object, SessionState>();
363
500
 
@@ -367,6 +504,7 @@ export default function fastExtension(pi: ExtensionAPI) {
367
504
  state = {
368
505
  config: loadConfig(ctx),
369
506
  override: "auto",
507
+ ultrafast: false,
370
508
  };
371
509
  states.set(ctx.sessionManager, state);
372
510
  }
@@ -377,13 +515,26 @@ export default function fastExtension(pi: ExtensionAPI) {
377
515
  const state: SessionState = {
378
516
  config: loadConfig(ctx),
379
517
  override: "auto",
518
+ ultrafast: false,
380
519
  };
381
520
  states.set(ctx.sessionManager, state);
382
521
  updateStatus(ctx, state);
383
522
  });
384
523
 
385
524
  pi.on("model_select", (_event, ctx) => {
386
- updateStatus(ctx, getState(ctx));
525
+ const state = getState(ctx);
526
+ if (state.ultrafast) {
527
+ const eligibility = getUltrafastEligibility(ctx);
528
+ if (!eligibility.eligible) {
529
+ disableUltrafast(
530
+ ctx,
531
+ state,
532
+ `the selected model ${eligibility.modelKey} is unsupported (${eligibility.reason})`,
533
+ );
534
+ return;
535
+ }
536
+ }
537
+ updateStatus(ctx, state);
387
538
  });
388
539
 
389
540
  pi.on("before_provider_headers", async (event, ctx) => {
@@ -393,11 +544,38 @@ export default function fastExtension(pi: ExtensionAPI) {
393
544
 
394
545
  pi.on("before_provider_request", (event, ctx) => {
395
546
  const state = getState(ctx);
547
+ if (state.ultrafast) {
548
+ const eligibility = getUltrafastEligibility(ctx);
549
+ if (!eligibility.eligible) {
550
+ disableUltrafast(
551
+ ctx,
552
+ state,
553
+ `the current model ${eligibility.modelKey} is unsupported (${eligibility.reason})`,
554
+ );
555
+ return undefined;
556
+ }
557
+ const nextPayload = injectUltrafastPayload(event.payload, ctx, state);
558
+ updateStatus(ctx, state);
559
+ return nextPayload;
560
+ }
561
+
396
562
  const nextPayload = injectFastPayload(event.payload, ctx, state);
397
563
  updateStatus(ctx, state);
398
564
  return nextPayload;
399
565
  });
400
566
 
567
+ pi.registerCommand("ultrafast", {
568
+ description: "Toggle session-only Ultrafast mode for direct OpenAI API-key GPT-6 Astra",
569
+ getArgumentCompletions: () => null,
570
+ handler: async (args, ctx) => {
571
+ if (args.trim()) {
572
+ ctx.ui.notify("Usage: /ultrafast", "warning");
573
+ return;
574
+ }
575
+ toggleUltrafast(ctx, getState(ctx));
576
+ },
577
+ });
578
+
401
579
  pi.registerCommand("fast", {
402
580
  description: "Toggle Fast mode for supported direct OpenAI, OpenAI Codex, and Anthropic Claude models",
403
581
  getArgumentCompletions: () => null,
@@ -405,14 +583,23 @@ export default function fastExtension(pi: ExtensionAPI) {
405
583
  const state = getState(ctx);
406
584
  const action = args.trim();
407
585
 
586
+ if (action === "ultrafast") {
587
+ toggleUltrafast(ctx, state);
588
+ return;
589
+ }
590
+
408
591
  if (!action) {
592
+ if (state.ultrafast) {
593
+ toggleUltrafast(ctx, state);
594
+ return;
595
+ }
409
596
  state.override = isFastEnabled(state) ? "off" : "on";
410
597
  updateStatus(ctx, state);
411
598
  ctx.ui.notify(getStatusMessage(ctx, state), "info");
412
599
  return;
413
600
  }
414
601
 
415
- ctx.ui.notify("Usage: /fast", "warning");
602
+ ctx.ui.notify("Usage: /fast [ultrafast]", "warning");
416
603
  },
417
604
  });
418
605
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diegopetrucci/pi-fast",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "A pi extension that enables Fast mode for supported direct OpenAI API, OpenAI Codex, and Anthropic Claude models based on the currently selected model.",
5
5
  "keywords": [
6
6
  "pi-package",