armin / open-ai-device-auth
OpenAI device code authentication CLI for ChatGPT tokens.
dev-master
2026-04-28 18:53 UTC
Requires
- php: ^8.4
- symfony/console: ^7.4 || ^8.0
- symfony/filesystem: ^7.4 || ^8.0
- symfony/http-client: ^7.4 || ^8.0
Requires (Dev)
- phpunit/phpunit: ^11.5
This package is auto-updated.
Last update: 2026-04-28 18:54:31 UTC
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