@99percentpeople/pi-codex-api 0.1.4 → 0.2.1
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.
- package/README.md +106 -178
- package/dist/index.ts +309 -28
- package/dist/index.ts.map +7 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,216 +1,144 @@
|
|
|
1
1
|
# @99percentpeople/pi-codex-api
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
an OpenAI API key, MCP server, or separate search provider.
|
|
3
|
+
Turn your ChatGPT subscription into Pi superpowers — image generation, web
|
|
4
|
+
search, Fast mode, and usage monitoring — **no OpenAI API key required**.
|
|
6
5
|
|
|
7
|
-
##
|
|
6
|
+
## Highlights
|
|
8
7
|
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
- **Image generation & editing** — `codex_image` creates or edits images via
|
|
9
|
+
your Codex subscription's `gpt-image-2`, and works from **any model**:
|
|
10
|
+
even with a third-party provider active (DeepSeek, Google, …), it reuses Pi's
|
|
11
|
+
logged-in `openai-codex` OAuth account (enable **Other providers** in
|
|
12
|
+
`/99settings`).
|
|
13
|
+
- **First-party search** — `codex_search` runs web and image queries, page
|
|
14
|
+
navigation, PDF screenshots, finance, weather, sports, and time lookups, and
|
|
15
|
+
renders clean result cards instead of raw citations.
|
|
16
|
+
- **Fast mode** — optional priority service tier for snappier responses.
|
|
17
|
+
- **Usage at a glance** — the status bar shows remaining Codex quota and
|
|
18
|
+
reset time; `/codex-usage` shows your plan, masked account, limits, credits,
|
|
19
|
+
and earned rate-limit reset cards.
|
|
20
|
+
- **Reset cards** — when you run out of messages, `/codex-redeem` redeems an
|
|
21
|
+
earned reset card safely: pick a card, confirm, done.
|
|
12
22
|
|
|
13
|
-
|
|
14
|
-
prompt or attempt an OAuth request during installation. A tool call instead
|
|
15
|
-
shows an actionable error directing you to `/login`; an expired login is
|
|
16
|
-
reported the same way after Pi's refresh attempt fails.
|
|
23
|
+
## Demo
|
|
17
24
|
|
|
18
|
-
|
|
19
|
-
ChatGPT subscription backend rather than metered Platform API usage.
|
|
25
|
+
Subscription usage, limit-reached state, and reset-card redemption:
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+

|
|
28
|
+
|
|
29
|
+
Web search with clean result cards (search → open a result → summarize):
|
|
30
|
+
|
|
31
|
+

|
|
32
|
+
|
|
33
|
+
Image generation with `gpt-image-2` (saved PNG + description):
|
|
34
|
+
|
|
35
|
+

|
|
36
|
+
|
|
37
|
+
## Quick start
|
|
22
38
|
|
|
23
39
|
```bash
|
|
24
40
|
pi install npm:@99percentpeople/pi-codex-api
|
|
25
41
|
```
|
|
26
42
|
|
|
27
|
-
|
|
28
|
-
directory:
|
|
43
|
+
Requirements:
|
|
29
44
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
pi install ./extensions/codex-api
|
|
34
|
-
```
|
|
45
|
+
- Pi logged in with `/login` for `openai-codex`
|
|
46
|
+
- An active `openai-codex` model, or **Other providers** enabled in
|
|
47
|
+
`/99settings` to use the subscription from any model
|
|
35
48
|
|
|
36
|
-
|
|
49
|
+
That's it — just ask *"generate an image of a neon ramen shop"* or *"search
|
|
50
|
+
the web for today's Rust releases"* and the model calls the tools for you.
|
|
51
|
+
|
|
52
|
+
## Commands
|
|
37
53
|
|
|
38
|
-
### `
|
|
54
|
+
### `/codex-usage`
|
|
39
55
|
|
|
40
|
-
|
|
41
|
-
`gpt-image-2`.
|
|
56
|
+
Shows a fresh snapshot of your subscription in one block:
|
|
42
57
|
|
|
43
58
|
```text
|
|
44
|
-
|
|
45
|
-
```
|
|
59
|
+
Codex usage
|
|
46
60
|
|
|
47
|
-
|
|
61
|
+
account · Plus (user@example.com)
|
|
48
62
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
codex
|
|
64
|
+
weekly [█████████████░░░░░░░] 65% left resets in 5d 3h
|
|
65
|
+
no additional credits
|
|
66
|
+
|
|
67
|
+
rate limit redeem
|
|
68
|
+
Full reset (available, expires 2026-08-13 02:14 UTC+8)
|
|
54
69
|
```
|
|
55
70
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
dimensions are part of the task. It normally omits `quality`, inheriting the
|
|
63
|
-
user's **Image quality** preference, and only overrides it when the user
|
|
64
|
-
explicitly requests a draft or a quality level.
|
|
65
|
-
|
|
66
|
-
New images default to `output/codex-images/<tool-call-id>.png`. Reference and
|
|
67
|
-
output paths must stay inside the current workspace, and existing files are
|
|
68
|
-
never overwritten. The PNG is both saved locally and returned as image
|
|
69
|
-
content so Codex can inspect or revise it in later turns. If a network request
|
|
70
|
-
fails before an HTTP response, the error identifies the endpoint path and any
|
|
71
|
-
safe transport code (for example `ECONNRESET`). The extension itself never
|
|
72
|
-
retries image generation automatically, because the server may have accepted
|
|
73
|
-
the first request; decide whether to retry after reviewing the error.
|
|
74
|
-
|
|
75
|
-
### `codex_search`
|
|
76
|
-
|
|
77
|
-
Uses the first-party Codex standalone search API. Supported command families:
|
|
78
|
-
|
|
79
|
-
- web and image queries;
|
|
80
|
-
- open, click, and find operations using returned reference IDs;
|
|
81
|
-
- PDF page screenshots;
|
|
82
|
-
- finance, weather, sports, and time lookups.
|
|
83
|
-
|
|
84
|
-
Search mode is configurable as Auto, Cached, Indexed, or Live. In Auto, the AI
|
|
85
|
-
requests a per-call mode: Cached for stable facts and known references, Indexed
|
|
86
|
-
for recent documentation and announcements, and Live for same-day or real-time
|
|
87
|
-
information. An omitted request defaults to Indexed. Selecting a fixed mode
|
|
88
|
-
pins every call to that mode, regardless of the AI request. External content is
|
|
89
|
-
untrusted and should never be treated as instructions.
|
|
90
|
-
|
|
91
|
-
## Parameter ownership
|
|
92
|
-
|
|
93
|
-
The extension follows the current official Codex split between task intent,
|
|
94
|
-
user policy, and internal protocol fields:
|
|
95
|
-
|
|
96
|
-
| Owner | Search | Image |
|
|
97
|
-
| --- | --- | --- |
|
|
98
|
-
| AI per call | queries, recency, task-specific domains, navigation/lookup commands, response length, and the requested mode when Auto is enabled | prompt, local or recent-conversation references, task-specific size, explicit quality override, destination path |
|
|
99
|
-
| User in `/99settings` | Auto or a fixed Cached/Indexed/Live policy, plus search context size | default image quality |
|
|
100
|
-
| Extension/backend | session/model routing, caller policy and token ceiling | fixed `gpt-image-2`, automatic background, one PNG result, reference and dimension validation |
|
|
101
|
-
|
|
102
|
-
Model selection, batch count, output format, input fidelity, masks, moderation,
|
|
103
|
-
and transparent background are intentionally not advertised as AI arguments on
|
|
104
|
-
this subscription path. In particular, GPT Image 2 does not support native
|
|
105
|
-
transparent-background output; requesting transparency through an unsupported
|
|
106
|
-
field would be misleading.
|
|
107
|
-
|
|
108
|
-
## Bundled skill
|
|
109
|
-
|
|
110
|
-
The package also ships the Agent Skills-standard **`gpt-image-prompts`** skill
|
|
111
|
-
under `skills/`. Pi discovers it with the package and can load it on demand to
|
|
112
|
-
write or refine production-ready GPT Image 2 prompts for new images,
|
|
113
|
-
reference-guided work, and precise edits. Invoke it explicitly with:
|
|
71
|
+
- Plan type and masked email from Codex's official usage endpoint
|
|
72
|
+
- Each limit window shows remaining capacity as a bar; when exhausted it reads
|
|
73
|
+
`limit reached` instead of `0% left`
|
|
74
|
+
- Earned reset cards, sorted by expiry, with local-time expiry timestamps
|
|
75
|
+
- The status bar mirrors this compactly: `Codex weekly 65% 5d 3h` →
|
|
76
|
+
`Codex weekly limit reached 5d 14h`
|
|
114
77
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
```
|
|
78
|
+
Usage refreshes automatically on session start and model select;
|
|
79
|
+
`/codex-usage` always forces a fresh read.
|
|
118
80
|
|
|
119
|
-
|
|
120
|
-
document tools, construct API requests, manage credentials, or prescribe file
|
|
121
|
-
and execution workflows.
|
|
122
|
-
|
|
123
|
-
## Tool display
|
|
124
|
-
|
|
125
|
-
Web and image queries render normalized source cards instead of the backend's
|
|
126
|
-
raw citation dump. The collapsed view shows three title/domain/snippet cards;
|
|
127
|
-
Pi's configured tool-output expansion shortcut (`Ctrl+O` by default) expands
|
|
128
|
-
every source with its full URL. Internal reference markers,
|
|
129
|
-
word-limit metadata, and separators are hidden. Open/click/find/PDF operations
|
|
130
|
-
use cleaned document cards. Batched navigation renders each returned page as a
|
|
131
|
-
separate numbered card with a short per-page preview, one shared expansion hint,
|
|
132
|
-
and visible warning styling for unresolved references. Weather, finance,
|
|
133
|
-
sports, and time lookups use a compact data view. This changes only the TUI display copy: the model
|
|
134
|
-
still receives the complete original search output.
|
|
135
|
-
|
|
136
|
-
Search and image parameters stream into the call row while the model constructs
|
|
137
|
-
them; input parameters are never repeated in the result area. Both tools also
|
|
138
|
-
stream real execution stages into the active result row while they run
|
|
139
|
-
(authentication, request, reference loading, generation, and saving as
|
|
140
|
-
applicable). Successful `codex_search` and `codex_image` calls also request a
|
|
141
|
-
rate-limited background usage refresh. The Codex search and image endpoints
|
|
142
|
-
return one final response, so result bodies appear atomically rather than as
|
|
143
|
-
fabricated content chunks.
|
|
81
|
+
### `/codex-redeem`
|
|
144
82
|
|
|
145
|
-
|
|
83
|
+
Redeems an earned rate-limit reset card when you're out of messages:
|
|
146
84
|
|
|
147
85
|
```text
|
|
148
|
-
|
|
86
|
+
──────────────────────────────────────────────
|
|
87
|
+
Select a reset credit to redeem (30s)
|
|
88
|
+
|
|
89
|
+
→ Full reset (expires 2026-08-03)
|
|
90
|
+
Full reset (expires 2026-08-12)
|
|
91
|
+
|
|
92
|
+
↑↓ navigate ↵ select esc cancel
|
|
93
|
+
──────────────────────────────────────────────
|
|
94
|
+
↓ pick a card
|
|
95
|
+
──────────────────────────────────────────────
|
|
96
|
+
Redeem Full reset (expires 2026-08-12)? (30s)
|
|
97
|
+
|
|
98
|
+
→ No
|
|
99
|
+
Yes
|
|
100
|
+
|
|
101
|
+
↑↓ navigate ↵ select esc cancel
|
|
102
|
+
──────────────────────────────────────────────
|
|
149
103
|
```
|
|
150
104
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
are limited to once per minute.
|
|
158
|
-
|
|
159
|
-
Pi does not currently publish an OAuth-account-change event or expose its
|
|
160
|
-
credential store to extensions. As a temporary compatibility layer, this
|
|
161
|
-
extension watches Pi's agent-directory `auth.json`. A short debounce reloads
|
|
162
|
-
the public model registry and compares the resolved Codex Account ID. After
|
|
163
|
-
`/login` replaces the account, the old snapshot is removed, the status changes
|
|
164
|
-
to `Codex syncing…`, and a forced account-scoped refresh starts. `/logout`
|
|
165
|
-
clears the status. In-flight requests are revision-guarded, so an old account
|
|
166
|
-
cannot overwrite the newly active account. The watcher is closed on session
|
|
167
|
-
teardown and never accesses Pi's private authentication runtime.
|
|
168
|
-
|
|
169
|
-
`/codex-usage` groups every metered limit under a simple `Codex usage` heading.
|
|
170
|
-
Each server-provided window (for example 5h, daily, or weekly) uses a fixed
|
|
171
|
-
20-cell bar whose filled portion represents remaining capacity, followed only
|
|
172
|
-
by `% left` and its reset time. Additional credit availability stays under the
|
|
173
|
-
same limit group. Inactive zero-value placeholder windows are hidden. Response
|
|
174
|
-
headers remain supported as a fallback.
|
|
105
|
+
- Multiple cards show a picker (earliest expiry first); a single card skips to
|
|
106
|
+
confirmation
|
|
107
|
+
- **No is the default**, so a stray Enter never consumes anything
|
|
108
|
+
- Redemptions are idempotent: a retry after a network failure can never consume
|
|
109
|
+
a second card
|
|
110
|
+
- Without dialog UI, it falls back to a two-step confirm flow
|
|
175
111
|
|
|
176
112
|
## Settings
|
|
177
113
|
|
|
178
|
-
|
|
114
|
+
Configure under **Codex API** in `/99settings`:
|
|
179
115
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
116
|
+
- **Other providers** — let any model (DeepSeek, Google, …) use the logged-in
|
|
117
|
+
Codex subscription
|
|
118
|
+
- **Fast mode** — priority service tier (lower latency, faster limit use)
|
|
119
|
+
- **Search** — auto routing (Cached / Indexed / Live per call) or a fixed mode,
|
|
120
|
+
plus context size
|
|
121
|
+
- **Image quality** — default GPT Image 2 quality
|
|
122
|
+
- **Usage status** — show or hide the Codex quota line in the status bar
|
|
183
123
|
|
|
184
|
-
|
|
124
|
+
Settings live in `~/.pi/agent/99extensions.json` under the `codex-api`
|
|
125
|
+
namespace.
|
|
185
126
|
|
|
186
|
-
|
|
187
|
-
call `codex_image` and `codex_search`; the extension resolves only the
|
|
188
|
-
separately logged-in `openai-codex` OAuth account. It never sends the active
|
|
189
|
-
model provider's credentials to ChatGPT.
|
|
190
|
-
- **Fast mode** — enables or disables the priority service tier;
|
|
191
|
-
- Auto search routing, or a fixed Cached, Indexed, or Live policy;
|
|
192
|
-
- search context size;
|
|
193
|
-
- default GPT Image 2 quality (`Auto`, `Low`, `Medium`, or `High`);
|
|
194
|
-
- subscription usage status visibility.
|
|
127
|
+
## How it works
|
|
195
128
|
|
|
196
|
-
|
|
129
|
+
- Reuses Pi's existing `openai-codex` OAuth — no API key, no MCP server, no
|
|
130
|
+
separate search provider
|
|
131
|
+
- Tokens are fetched per call from Pi's model registry, never stored in
|
|
132
|
+
settings or tool results
|
|
133
|
+
- Images and search requests go to OpenAI's Codex backend and follow your
|
|
134
|
+
ChatGPT workspace's policies
|
|
135
|
+
- The extension also ships the **`gpt-image-prompts`** skill for crafting
|
|
136
|
+
production-grade image prompts — invoke it with `/skill:gpt-image-prompts`
|
|
197
137
|
|
|
198
|
-
|
|
199
|
-
~/.pi/agent/99extensions.json
|
|
200
|
-
```
|
|
138
|
+
## Development
|
|
201
139
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
Codex model specifically rather than using the active model's credentials.
|
|
208
|
-
Tokens are never copied into extension settings or tool results. The extracted
|
|
209
|
-
ChatGPT account ID is used only as an in-memory Usage-state key and is never
|
|
210
|
-
persisted or displayed. The watcher reacts only to the `auth.json` filename;
|
|
211
|
-
credential parsing and resolution remain inside Pi's public model registry.
|
|
212
|
-
|
|
213
|
-
Image prompts, reference images, search commands, and search context are sent
|
|
214
|
-
to OpenAI's Codex backend and are subject to the active ChatGPT workspace's
|
|
215
|
-
policies. Feature availability and request formats may change as Codex rolls
|
|
216
|
-
out backend updates.
|
|
140
|
+
```bash
|
|
141
|
+
bun run build:packages
|
|
142
|
+
bun run --cwd extensions/codex-api build
|
|
143
|
+
pi install ./extensions/codex-api
|
|
144
|
+
```
|