Skip to content

Commit dbdfc3c

Browse files
committed
changes
1 parent 2030b28 commit dbdfc3c

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

codex-rs/app-server/README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,98 @@ Currently, you can dump a TypeScript version of the schema using `codex generate
1313
```
1414
codex generate-ts --out DIR
1515
```
16+
17+
## Auth endpoints (v2)
18+
19+
The v2 JSON-RPC auth/account surface exposes request/response methods plus server-initiated notifications (no `id`). Use these to determine auth state, start or cancel logins, logout, and inspect ChatGPT rate limits.
20+
21+
### Quick reference
22+
- `account/read` — fetch current account info; optionally refresh tokens.
23+
- `account/login/start` — begin login (`apiKey` or `chatgpt`).
24+
- `account/login/completed` (notify) — emitted when a login attempt finishes (success or error).
25+
- `account/login/cancel` — cancel a pending ChatGPT login by `loginId`.
26+
- `account/logout` — sign out; triggers `account/updated`.
27+
- `account/updated` (notify) — emitted whenever auth mode changes (`authMode`: `apikey`, `chatgpt`, or `null`).
28+
- `account/rateLimits/read` — fetch ChatGPT rate limits; updates arrive via `account/rateLimits/updated` (notify).
29+
30+
### 1) Check auth state
31+
32+
Request:
33+
```json
34+
{ "method": "account/read", "id": 1, "params": { "refreshToken": false } }
35+
```
36+
37+
Response examples:
38+
```json
39+
{ "id": 1, "result": { "account": null, "requiresOpenaiAuth": false } } // no auth needed
40+
{ "id": 1, "result": { "account": null, "requiresOpenaiAuth": true } } // auth needed
41+
{ "id": 1, "result": { "account": { "type": "apiKey" }, "requiresOpenaiAuth": true } }
42+
{ "id": 1, "result": { "account": { "type": "chatgpt", "email": "[email protected]", "planType": "pro" }, "requiresOpenaiAuth": true } }
43+
```
44+
45+
Field notes:
46+
- `refreshToken` (bool): set `true` to force a token refresh.
47+
- `requiresOpenaiAuth` reflects the active provider; when `false`, Codex can run without OpenAI credentials.
48+
49+
### 2) Log in with an API key
50+
51+
1. Send:
52+
```json
53+
{ "method": "account/login/start", "id": 2, "params": { "type": "apiKey", "apiKey": "sk-…" } }
54+
```
55+
2. Expect:
56+
```json
57+
{ "id": 2, "result": { "type": "apiKey" } }
58+
```
59+
3. Notifications:
60+
```json
61+
{ "method": "account/login/completed", "params": { "loginId": null, "success": true, "error": null } }
62+
{ "method": "account/updated", "params": { "authMode": "apikey" } }
63+
```
64+
65+
### 3) Log in with ChatGPT (browser flow)
66+
67+
1. Start:
68+
```json
69+
{ "method": "account/login/start", "id": 3, "params": { "type": "chatgpt" } }
70+
{ "id": 3, "result": { "type": "chatgpt", "loginId": "<uuid>", "authUrl": "https://chatgpt.com/…&redirect_uri=http%3A%2F%2Flocalhost%3A<port>%2Fauth%2Fcallback" } }
71+
```
72+
2. Open `authUrl` in a browser; the app-server hosts the local callback.
73+
3. Wait for notifications:
74+
```json
75+
{ "method": "account/login/completed", "params": { "loginId": "<uuid>", "success": true, "error": null } }
76+
{ "method": "account/updated", "params": { "authMode": "chatgpt" } }
77+
```
78+
79+
### 4) Cancel a ChatGPT login
80+
81+
```json
82+
{ "method": "account/login/cancel", "id": 4, "params": { "loginId": "<uuid>" } }
83+
{ "method": "account/login/completed", "params": { "loginId": "<uuid>", "success": false, "error": "" } }
84+
```
85+
86+
### 5) Logout
87+
88+
```json
89+
{ "method": "account/logout", "id": 5 }
90+
{ "id": 5, "result": {} }
91+
{ "method": "account/updated", "params": { "authMode": null } }
92+
```
93+
94+
### 6) Rate limits (ChatGPT)
95+
96+
```json
97+
{ "method": "account/rateLimits/read", "id": 6 }
98+
{ "id": 6, "result": { "rateLimits": { "primary": { "usedPercent": 25, "windowDurationMins": 15, "resetsAt": 1730947200 }, "secondary": null } } }
99+
{ "method": "account/rateLimits/updated", "params": { "rateLimits": { } } }
100+
```
101+
102+
Field notes:
103+
- `usedPercent` is current usage within the OpenAI quota window.
104+
- `windowDurationMins` is the quota window length.
105+
- `resetsAt` is a Unix timestamp (seconds) for the next reset.
106+
107+
### Dev notes
108+
109+
- `codex generate-ts --out <dir>` emits v2 typings under `v2/`.
110+
- See “Authentication and authorization” in the [config docs](../../docs/config.md#authentication-and-authorization) for configuration knobs.

0 commit comments

Comments
 (0)