armin/open-ai-device-auth
Composer 安装命令:
composer require armin/open-ai-device-auth
包简介
OpenAI device code authentication CLI for ChatGPT tokens.
README 文档
README
Device Code authentication as a PHP Composer package. The CLI performs the OpenAI device login flow and writes an auth.json with ChatGPT tokens.
Requirements
- PHP 8.4+
- Composer
- Device Code authentication enabled in your ChatGPT account
Installation
composer require armin/open-ai-device-auth
Usage
The CLI exposes three commands:
vendor/bin/open-ai-device-auth login vendor/bin/open-ai-device-auth refresh vendor/bin/open-ai-device-auth usage
Login
Start the device login flow:
vendor/bin/open-ai-device-auth login
Write to a custom location:
vendor/bin/open-ai-device-auth login --auth-file=/path/to/auth.json
Refresh
Refresh tokens in ./auth.json:
vendor/bin/open-ai-device-auth refresh
Refresh tokens in a custom auth.json:
vendor/bin/open-ai-device-auth refresh --auth-file=/path/to/auth.json
Usage
Fetch ChatGPT usage and rate limits from ./auth.json:
vendor/bin/open-ai-device-auth usage
Fetch ChatGPT usage and rate limits from a custom auth.json:
vendor/bin/open-ai-device-auth usage --auth-file=/path/to/auth.json
Return the raw payload as JSON:
vendor/bin/open-ai-device-auth usage --auth-file=/path/to/auth.json --format=json
Flow
- Run the
logincommand. - Open
https://auth.openai.com/codex/devicein any browser. - Enter the displayed one-time code.
- Wait for authorization to complete.
- The CLI writes
./auth.jsonunless--auth-fileis provided.
All three commands support --auth-file and -a. The default path is ./auth.json.
Output Format
{
"auth_mode": "chatgpt",
"OPENAI_API_KEY": null,
"tokens": {
"id_token": "...",
"access_token": "...",
"refresh_token": "...",
"account_id": "..."
},
"last_refresh": "2026-04-24T11:17:48.681452Z"
}
Notes
- The file format is tailored for ChatGPT token storage, not generic API key auth.
account_idis extracted from the returnedid_token.last_refreshis written as the current UTC timestamp when the file is created.refreshreplaces the stored tokens in-place and updateslast_refresh.usagereads the storedaccess_tokenand prints either a human-readable summary or JSON.
License
MIT
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-26