cat articles/openai-api-server-via-codex

OpenAI API-Compatible Access Without Additional API Billing via Codex

A Codex-authenticated OpenAI API-compatible server for Responses, Chat Completions, and image generation. Within the Codex subscription scope, it can be used without additional API usage billing.

I built a local server that uses Codex credentials and exposes an OpenAI API-compatible interface. In addition to the Responses API and Chat Completions API, the current version also supports /v1/images/generations for image generation, although that support is still not a complete implementation of the official OpenAI API surface.

The main benefit is that, within the scope of a Codex subscription, you can use an OpenAI API-compatible interface without additional OpenAI API usage billing. If your environment is already authenticated with Codex, you can start the compatible server with a single uvx command.

uvx openai-api-server-via-codex

This starts a local server. By default it listens on http://127.0.0.1:18080, and clients that can call the OpenAI API can use endpoints such as /v1/responses, /v1/chat/completions, and /v1/images/generations. This is convenient when you want to use existing OpenAI SDKs or GUI clients.

For image generation, the server can be called through OpenAI SDK methods such as client.images.generate(...). At the moment, however, responses are returned as base64 b64_json; URL responses, streaming, and image edit APIs are not supported. It is better to think of this as a practical compatibility layer for local experiments and personal tooling, not a complete replacement for the official OpenAI API.

For example, if you point a GUI client that supports the OpenAI API at the local server, it looks like this. The screenshot below uses a model that was available through Codex when the article was first published.

OpenAI API compatible server screenshot


Why Subscription-Scoped Use Matters

OpenAI's official API usage is billed separately from ChatGPT and Codex subscriptions. For example, on the official OpenAI pricing page, gpt-5.5 is listed at 5.00 USD per 1M input tokens and 30.00 USD per 1M output tokens.

This server does not make the official OpenAI API free. It uses Codex credentials and exposes the models and execution environment available through Codex as a local OpenAI API-compatible interface. Within subscription limits and the applicable terms, that can make it possible to experiment with expensive model capabilities from local development tools or personal workflows without additional API usage charges.

This is especially useful when you want to keep using existing OpenAI SDK-compatible tools, or when you are iterating quickly on a local prototype. It should not be used to bypass limits, resell access, provide an API to third parties, or run the backend of a public service.

How It Works

This approach is also used by Pi, one of the agent execution engines used when OpenClaw runs through Codex. It uses Codex authentication information and calls the Codex API endpoint at https://chatgpt.com/backend-api/codex.

I was not sure whether it was acceptable to use this API endpoint directly, but after reading Simon Willison's article, A pelican for GPT-5.5 via the semi-official Codex backdoor API, it seemed likely enough to be usable. "Semi-official" is a fitting description.

Notes and Caveats

This project is not an official OpenAI API. It is only a way to use Codex credentials that you are authorized to use and convert them into an OpenAI API-compatible shape in a local or development environment. Uses such as the following may violate OpenAI's terms:

  • Using it to bypass ChatGPT or Codex usage limits
  • Providing it as an API to people other than yourself
  • Reselling or sharing a subscription
  • Using it as the backend for a public API or third-party service
  • Sharing Codex credentials or tokens with someone else

The Codex backend may also change without notice. Request formats or model names that work today may suddenly stop working.

Difference Between the Codex and Claude Code Subscription Positions

In April 2026, Claude Code announced that subscription use through tools such as OpenClaw would be prohibited. In contrast, Codex has started publishing mechanisms such as Codex App Server and Codex SDK, at least for now, to support broader use even with subscriptions. The difference in stance is interesting.

Anthropic seems to be placing strict limits because inference resources for Claude are currently tight. OpenAI, on the other hand, gives the impression of having more room and being comparatively generous. That said, if OpenAI's resources become tight, or if competition weakens, it is entirely possible that the policy could become stricter or subscriptions could change in the future. It is hard to predict what will happen.