Skip to content
郭立 (leeguoo)

ChatGPT Subscription → Image Generation API Visual Overview: Understand chatgpt-imagegen at a Glance

A one-page visual overview: how a ChatGPT subscription is turned by chatgpt-imagegen into a command-line image generation tool—OAuth token retrieval, Responses API SSE streaming, capability boundary matrix, and scenarios where you should not use it, all explained at a glance.

visual guide · understand it on one page

Use Your ChatGPT Subscription as Your Image Generation API

Already paying the monthly fee for ChatGPT Plus / Pro / Team, but need to generate images from the command line or inside an AI agent? No need to top up OPENAI_API_KEY separately—a 300-line Python CLI directly reuses your subscription quota.

$ chatgpt-imagegen "a watercolor cat sitting on a windowsill" -o cat.png -> saved: cat.png (812,344 bytes) size=1024x1024 quality=medium # One command, no API key, no proxy, no daemon

There Are Actually Two Paths for OpenAI Image Generation

Most developers have only seen the path on the left. The path on the right is basically invisible to non-Codex CLI users—but it is actually already included in the subscription fee you pay every month.

Path A

Official API

Charged per image · Requires OPENAI_API_KEY
POST /v1/images/generations
Path B · Hidden Channel

ChatGPT Subscription

Fixed monthly fee · Auth via ~/.codex/auth.json
POST chatgpt.com/backend-api/codex/responses

Path B is the endpoint used by the built-in image_gen tool in OpenAI Codex CLI. What chatgpt-imagegen does is extract this route and wrap it in a CLI shell, making it scriptable and directly callable by AI agents.

Set It Up in 30 Seconds

# Prerequisite: install Codex CLI and log in once with your ChatGPT subscription account $ npm i -g @openai/codex $ codex login # Option A: install as an AI agent skill (Claude Code / Cursor / Codex Agent) $ npx skills add leeguooooo/chatgpt-imagegen -g # Option B: standalone CLI $ git clone https://github.com/leeguooooo/chatgpt-imagegen $ sudo install chatgpt-imagegen/chatgpt-imagegen /usr/local/bin/

Internal Protocol: What Happens During One Call

1
Read Codex login state ~/.codex/auth.json · ~/.codex/version.json
2
Construct the Responses API request tools: [{type: "image_generation"}]
3
POST to the internal endpoint chatgpt.com/backend-api/codex/responses
4
Consume the SSE stream image_generation_call.in_progress → generating → output_item.done
5
Decode and write to disk item.result (base64 PNG) → cat.png
6
Automatically refresh expired tokens auth.openai.com/oauth/token (refresh_token) → write back to auth.json

Capability Matrix: What Works and What Does Not

Capability Subscription Channel Notes
--size ✅ Works Stable in testing: 1024x1024, 1024x1536, 1536x1024. Larger sizes are passed through; success depends on your subscription tier
--format ✅ Works png / jpeg / webp all work
Image quality quality ⚠️ Server decides The subscription channel does not expose a controllable quality field. Requests for high are silently downgraded—so the CLI simply does not include this flag
Transparent background background: transparent ❌ Not supported You must use the official API + gpt-image-1.5
Image edits /v1/images/edits ❌ Not implemented If you need this, open an issue in the repository
Speed 15–40 s / image End-to-end SSE streaming

Concurrency Test

4×
Concurrent requests all returned 200
~27s
Total time ≈ slowest single image
0
429 / serialization
≤10/min
Recommended sustained rate limit

In testing, a Plus account ran 4 chatgpt-imagegen calls at the same time, and the server neither rate-limited nor serialized them. But the subscription quota is shared with the ChatGPT web app and Codex CLI—do not run at >10 images/minute for long, or you will hit the daily rate limit.

When You Should Not Use This Tool

If any of the following applies, use the official API directly:
  • You need strict quality=high or transparent backgrounds—the subscription channel cannot provide them
  • You are building a production service for end users—this both violates the OpenAI Terms of Use and will burn through your own ChatGPT quota
  • You need precise per-call cost allocation—the subscription is a monthly fee and cannot be allocated to each call
  • You need stable throughput of >10 images/minute—subscription rate limits are tighter

Choose One: Local CLI or HTTP Gateway?

This repository

chatgpt-imagegen

Occasional image generation on a laptop, as a skill for an AI agent, or called from shell scripts. One Python file, no network service.

Sister project

agent-cli-to-api

Wraps the same subscription channel into an OpenAI-compatible /v1/chat/completions HTTP service for teams / multiple clients / remote calls.

Use Cases for AI agents

This is the core use case for this project. In the past, wanting Claude Code / Cursor / Codex Agent to "quickly draw one" usually meant stuffing in another OPENAI_API_KEY or hearing it say "I can't generate images." After installing this skill:

$ npx skills add leeguooooo/chatgpt-imagegen -g

The agent directly reuses the subscription quota you've already paid for—no new key, new account, or new environment variable needed. The repository's SKILL.md already spells out when the agent should call it, how to choose sizes, and how to handle errors.

Further Reading

Technical Post: Dissecting It in 300 Lines of Python GitHub Repository HTTP Gateway: agent-cli-to-api

More in this category · AI & Agent

Jun 18, 2026
7 min read
Let Claude Code Draw the Image Itself: The Original Intent and Principles Behind chatgpt-imagegen
When an AI agent needs an image while writing, the traditional path either requires an API key and money, or a human has to go to ChatGPT, generate the image, and paste it back in—the agent can only get stuck waiting. chatgpt-imagegen lets the agent generate images on its own using your existing ChatGPT subscription: no API key required, no Codex quota consumed by default, and image-to-image generation supported. This article explains its original intent, how its two backends work, and why it was designed for agents.
→
Jun 22, 2026
10 min read
Let Claude Code Automatically Generate Images with Your ChatGPT Subscription: No API Key, and How It Gets Around Turnstile
Let agents like Claude Code and Cursor generate images along the way when writing docs or READMEs, without an OPENAI_API_KEY, without paying extra, and using the ChatGPT subscription you already have. This article dissects the most interesting implementation path behind it: the web backend. Why you can’t just POST directly, why the real wall among the three layers of anti-scraping is the single-use Turnstile token, and the complete flow for driving your already-logged-in Chrome to generate images.
→
Oct 11, 2026
6 min read
switch-use: Let AI agents operate a real Nintendo Switch
An open-source command-line tool that lets agents like Claude Code and Codex operate a Switch running Atmosphère and sys-botbase over a local network: OCR for reading screen text, tapping by text, waiting for screens to appear, buttons and sticks, touch, and screenshots.
→
← previous
Tokyo Commuting Area Home Purchase Candidate List
next →
Facing AI Audits: How Can You “Legalize” Your Reverse Engineering Project?

Comments

Replies are public immediately and may be moderated for policy violations.

Max 1000 characters.