> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bettertoken.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Use a third-party GPT Image API while staying signed in to Codex

> Keep your Codex sign-in and chat settings while a separate image skill calls BetterToken GPT Image API. Follow setup, generation, editing, and troubleshooting.

Use a separate image skill: Codex keeps handling conversations with your existing official account, while the skill calls the image endpoint with your BetterToken API Key and saves the result locally. Image requests are billed at BetterToken's current prices.

This guide uses the community project [Wangnov/gpt-image-2-skill](https://github.com/Wangnov/gpt-image-2-skill). Its independent OpenAI-compatible image configuration lets you keep your Codex chat model and sign-in files. After setup, request images and edits in natural language.

## Prepare Codex and an API Key

1. Sign in with your official account in the local Codex App or Codex CLI and open a project.
2. <a href={"https://bettertoken.ai/register"}>Create a BetterToken API Key</a> or use an existing key.
3. Check the image model and current pricing in the <a href={"https://bettertoken.ai/pricing"}>model plaza</a>. Start with `gpt-image-2`.

Codex must be able to run local scripts and reach `bettertoken.ai`. This workflow is for the local App and CLI; cloud tasks need their own runtime and credentials.

## Step 1: send the setup prompt to Codex

Copy the whole prompt below. It contains a placeholder, so you do not need to share a real key.

```text theme={null}
Install and configure a separate image skill for my local Codex.

Repository: https://github.com/Wangnov/gpt-image-2-skill
Skill subdirectory: skills/gpt-image-2-skill
Install under my user .agents/skills/gpt-image-2-skill; inspect and reuse an existing installation.

Keep my official Codex sign-in, chat model, config.toml, auth.json, and OPENAI_API_KEY unchanged.
Check Node.js and use the repository's Node wrapper to prepare the released runtime for my system. Do not require a Rust development environment.

Save image settings in gpt-image-2-skill/config.json under the current CODEX_HOME;
otherwise use ~/.codex/gpt-image-2-skill/config.json.
Merge existing settings and preserve other entries. Add an image service named bettertoken-image:
type = openai-compatible
api_base = https://bettertoken.ai/v1
model = gpt-image-2
credentials.api_key = {"source":"file","value":"YOUR_BETTERTOKEN_API_KEY"}
Set this image skill's default_provider to bettertoken-image.

Explicitly pass --provider bettertoken-image for generation and editing.
Do not use --provider codex, the built-in official image tool, or switch to another image service.
Leave the key as a placeholder for me to fill in locally. Do not ask me to paste the real key into chat.
Only install and check configuration now; do not submit paid image requests.
Report the absolute skill and config paths, Base URL, and Model ID. Never display the key.
```

If Node.js is missing, follow Codex's instructions to install Node.js LTS. The wrapper normally downloads the released runtime for your system.

## Step 2: fill in the key locally

Open the config file that Codex reports. Replace the placeholder in `credentials.api_key.value` with your BetterToken API Key.

| System | Default config file |
| - | - |
| macOS / Linux | `~/.codex/gpt-image-2-skill/config.json` |
| Windows | `%USERPROFILE%\.codex\gpt-image-2-skill\config.json` |

For a custom `CODEX_HOME`, use the absolute path Codex reports. This image configuration is separate from your Codex sign-in file.

A new configuration looks like this. When a file already exists, edit only the relevant entry:

```json theme={null}
{
  "version": 1,
  "default_provider": "bettertoken-image",
  "providers": {
    "bettertoken-image": {
      "type": "openai-compatible",
      "api_base": "https://bettertoken.ai/v1",
      "model": "gpt-image-2",
      "credentials": {
        "api_key": {
          "source": "file",
          "value": "YOUR_BETTERTOKEN_API_KEY"
        }
      }
    }
  }
}
```

Keep the file private and outside project repositories and screenshots. `providers` is a configuration field of the community tool.

## Step 3: generate your first image

Save the configuration, start a new Codex chat, and send:

```text theme={null}
Use $gpt-image-2-skill with --provider bettertoken-image to generate an image.
Model: gpt-image-2. Generate one PNG at 1024x1024.
Subject: a green ceramic mug in a white studio, soft natural light, no text.
Save it as output/images/mug.png in the current project and display the image.
Do not use the built-in official image tool or switch image services.
If the request fails, report the reason without changing models or submitting another request.
```

Allow the script's image API network request when Codex asks. Generation can take a few minutes; wait for the current request to finish.

Confirm that your original Codex account remains signed in, `output/images/mug.png` exists and opens, and the BetterToken usage log contains the matching image model request.

## Edit a reference image

Put the reference image in the project or provide its local path:

```text theme={null}
Use $gpt-image-2-skill with --provider bettertoken-image to edit an image.
Reference: output/images/mug.png.
Change only the background to light gray; keep the mug's color, shape, and composition.
Use gpt-image-2 and save as output/images/mug-edited.png.
Do not overwrite the original, use the built-in official image tool, or switch image services.
```

The skill uses the image editing endpoint. See [image editing](/en/api-reference/images-edits) for uploads and masks. To change image models, specify the full Model ID from the model plaza.

## Troubleshooting

| Symptom | What to do |
| - | - |
| Skill not found | Ask Codex to check the installed `SKILL.md`, then start a new chat. Restart Codex if it is still missing. |
| Official image tool still used | Name `$gpt-image-2-skill` and `--provider bettertoken-image`; have Codex check the image configuration's URL and model. |
| `401` or authentication failure | Check that the image config contains a complete, active key rather than the placeholder. |
| `404` or model not found | Use `https://bettertoken.ai/v1`, without `/responses` or a second `/v1`; check the exact Model ID. |
| Network blocked | Allow this image script's network request and check the local network or proxy. |
| Timeout, rate limit, or insufficient balance | Check BetterToken usage and balance first. After a timeout, confirm the request status before retrying. |

## Related documentation

* [Image generation API](/en/api-reference/images-generations)
* [Official Codex sign-in with third-party text APIs](/en/faq/codex/official-login-third-party-api)
* [OpenAI: local skill installation and discovery](https://learn.chatgpt.com/docs/build-skills)
* [Community skill configuration and usage](https://github.com/Wangnov/gpt-image-2-skill)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.