PHPackages                             armin/open-ai-device-auth - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. armin/open-ai-device-auth

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

armin/open-ai-device-auth
=========================

OpenAI device code authentication CLI for ChatGPT tokens.

08↓100%PHP

Since Apr 28Pushed 1mo agoCompare

[ Source](https://github.com/a-r-m-i-n/open-ai-device-auth)[ Packagist](https://packagist.org/packages/armin/open-ai-device-auth)[ RSS](/packages/armin-open-ai-device-auth/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

open-ai-device-auth
===================

[](#open-ai-device-auth)

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
------------

[](#requirements)

- PHP 8.4+
- Composer
- Device Code authentication enabled in your ChatGPT account

Installation
------------

[](#installation)

```
composer require armin/open-ai-device-auth
```

Usage
-----

[](#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

[](#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)

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

[](#usage-1)

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
----

[](#flow)

1. Run the `login` command.
2. Open `https://auth.openai.com/codex/device` in any browser.
3. Enter the displayed one-time code.
4. Wait for authorization to complete.
5. The CLI writes `./auth.json` unless `--auth-file` is provided.

All three commands support `--auth-file` and `-a`. The default path is `./auth.json`.

Output Format
-------------

[](#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
-----

[](#notes)

- The file format is tailored for ChatGPT token storage, not generic API key auth.
- `account_id` is extracted from the returned `id_token`.
- `last_refresh` is written as the current UTC timestamp when the file is created.
- `refresh` replaces the stored tokens in-place and updates `last_refresh`.
- `usage` reads the stored `access_token` and prints either a human-readable summary or JSON.

License
-------

[](#license)

MIT

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance60

Regular maintenance activity

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 70% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/355aa463a532a530009c06219f83ab8b20a9b80a2bc8995064b6d390c6427735?d=identicon)[ArminVieweg](/maintainers/ArminVieweg)

---

Top Contributors

[![a-r-m-i-n](https://avatars.githubusercontent.com/u/1275298?v=4)](https://github.com/a-r-m-i-n "a-r-m-i-n (7 commits)")[![tumf](https://avatars.githubusercontent.com/u/69994?v=4)](https://github.com/tumf "tumf (3 commits)")

### Embed Badge

![Health badge](/badges/armin-open-ai-device-auth/health.svg)

```
[![Health](https://phpackages.com/badges/armin-open-ai-device-auth/health.svg)](https://phpackages.com/packages/armin-open-ai-device-auth)
```

###  Alternatives

[kartik-v/yii2-password

Useful password strength validation utilities for Yii Framework 2.0

761.2M17](/packages/kartik-v-yii2-password)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
