Skip to content
2api2api Docs
Open console

Codex

Codex with ChatGPT sign-in + API

Sign in to the account with ChatGPT and send model requests through 2api. For people who also use the mobile app, official plugins and similar features.

Pure API mode (see Codex CLI) can’t use these features, which need a ChatGPT sign-in:

  • Continuing or viewing Codex sessions in the mobile app
  • Official plugins and connectors that need a ChatGPT sign-in
  • Features such as long-term goals and background tasks

If you need them, set it up as follows. You sign in with ChatGPT, and model requests still go through 2api and are charged there. Ordinary API users can skip this page.

  1. Fully quit Codex.

  2. Back up ~/.codex/auth.json, then delete it. Do not delete ~/.codex/sessions. It holds your session history.

  3. Start Codex again and sign in with your ChatGPT account.

  4. Open ~/.codex/config.toml and add an experimental_bearer_token line under [model_providers.sub2api]. Its value is your 2api key:

    ~/.codex/config.toml
    model_provider = "sub2api"
    [model_providers.sub2api]
    name = "sub2api"
    base_url = "https://2api.dev/v1"
    wire_api = "responses"
    requires_openai_auth = true
    experimental_bearer_token = "sk-your-key"
  5. Save, quit Codex and open it again, then start a new session.