1# Access tokens1# Access tokens
2 2
3Codex access tokens are ChatGPT access tokens scoped to Codex permissions that let trusted automation run Codex local with a ChatGPT workspace identity. Use them when a script, scheduled job, or CI runner needs repeatable, non-interactive Codex access.3Codex access tokens are ChatGPT workspace credentials scoped to Codex permissions. They authenticate trusted non-interactive local workflows, including Codex CLI and app-server-based automation, with a ChatGPT workspace identity. Use them when a script, scheduled job, or CI runner needs repeatable local access.
4 4
5Codex access tokens are currently supported for ChatGPT Business and5Codex access tokens are currently supported for ChatGPT Business and
6 Enterprise workspaces.6 Enterprise workspaces.
7 7
8Access tokens are created in the ChatGPT admin console at [Access tokens](https://chatgpt.com/admin/access-tokens). They are tied to the ChatGPT user and workspace that create them, and Codex uses them as agent identities for programmatic local workflows.8Access tokens are created in the ChatGPT admin console at [Access tokens](https://chatgpt.com/admin/access-tokens). They're tied to the ChatGPT user who creates them and that user's workspace. The tokens act as agent identities for programmatic local workflows.
9 9
10If a Platform API key works for your automation, keep using API key auth. Use10If a Platform API key works for your automation, keep using API key auth. Use
11 Codex access tokens when the workflow specifically needs ChatGPT workspace11 Codex access tokens when a trusted local workflow specifically needs ChatGPT
12 access, ChatGPT-managed Codex entitlements, or enterprise workspace controls.12 workspace access, workspace-managed entitlements, or enterprise controls.
13 13
14Need to trigger a published ChatGPT workspace agent from your own system? Use14Need to trigger a published ChatGPT workspace agent from your own system? Use
15 a Workspace Agent access token for the Workspace Agents API instead. Codex15 a Workspace Agent access token for the Workspace Agents API instead. Codex
16 access tokens authenticate Codex local workflows; they do not authenticate16 access tokens authenticate trusted local workflows through Codex CLI or an
17 workspace agent trigger calls. See [Authenticate with Workspace Agent access17 app-server client; they do not authenticate workspace agent trigger calls. See
18 [Authenticate with Workspace Agent access
18 tokens](https://developers.openai.com/workspace-agents/authentication).19 tokens](https://developers.openai.com/workspace-agents/authentication).
19 20
20## How access tokens work21## How access tokens work
21 22
22Use an access token when Codex needs to run without a user completing a browser sign-in. The token represents the ChatGPT workspace user who created it, so runs can use that user's Codex access and appear in workspace governance data.23Use an access token when Codex CLI or an app-server client needs to run without a user completing a browser sign-in. The token represents the ChatGPT workspace user who created it, so runs can use that user's access and appear in workspace governance data.
23 24
24Codex checks the token when a run starts and ties the run to that workspace identity. Treat the token like any other automation secret: store it in a secret manager, keep it out of logs, and rotate it regularly.25The client checks the token when a run starts and ties the run to that workspace identity. Treat the token like any other automation secret: store it in a secret manager, keep it out of logs, and rotate it regularly.
25 26
26Use access tokens for:27Use access tokens for:
27 28
28- `codex exec` jobs that run from trusted automation.29- `codex exec` jobs that run from trusted automation.
29- Local scripts that need repeatable, non-interactive Codex runs.30- Local scripts that need repeatable, non-interactive Codex CLI runs.
31- Trusted app-server-based automation.
30- Enterprise workflows where usage should be associated with a ChatGPT workspace user instead of an API organization key.32- Enterprise workflows where usage should be associated with a ChatGPT workspace user instead of an API organization key.
31 33
32Main risks to avoid:34Main risks to avoid:
33 35
34- **Leaked secrets:** anyone with the token can start Codex runs as the token creator. Store tokens in a secret manager, keep them out of logs, and rotate them regularly.36- **Leaked secrets:** anyone with the token can start local runs through Codex CLI or an app-server client as the token creator. Store tokens in a secret manager, keep them out of logs, and rotate them regularly.
35- **Untrusted runners:** public CI, forked pull requests, or shared machines can expose tokens to people outside your workspace. Use access tokens only on trusted runners.37- **Runner trust:** public CI, forked pull requests, or shared machines can expose tokens to people outside your workspace. Use access tokens only on trusted runners.
36- **Shared identities:** one person's token reused across unrelated teams makes ownership and audit trails harder to interpret. Create tokens for a specific workflow owner.38- **Shared identities:** one person's token reused across unrelated teams makes ownership and audit trails harder to interpret. Create tokens for a specific workflow owner.
37- **Stale credentials:** long-lived tokens can remain active after the workflow changes. Prefer finite expirations and revoke tokens that are no longer used.39- **Stale credentials:** long-lived tokens can remain active after the workflow changes. Prefer time-limited tokens and revoke tokens that are no longer used.
38- **Wrong credential type:** Codex access tokens are for Codex local workflows. Use Workspace Agent access tokens to trigger published ChatGPT workspace agents, and use Platform API keys for general OpenAI API calls.40- **Wrong credential type:** Codex access tokens are for trusted local automation through Codex CLI or an app-server client. Use Workspace Agent access tokens to trigger published ChatGPT workspace agents, and use Platform API keys for general OpenAI API calls.
39 41
40## Enable access token creation42## Enable access token creation
41 43
42Use the access token permission in workspace settings to turn on access token creation for allowed members.44Use the access token permission in workspace settings to turn on access token creation for allowed members.
43 45
46The access token permission controls token creation. It doesn't grant access to
47the ChatGPT desktop app, Codex CLI, or IDE extension, and it doesn't change a
48member's seat type, built-in workspace role, or local runtime permission
49profile. Configure those controls as needed.
50
51For the relationship between these controls, see
52[Roles and workspace permissions](https://learn.chatgpt.com/docs/enterprise/roles-and-workspace-permissions).
53
44<CodexScreenshot54<CodexScreenshot
45 alt="Access token access permission in ChatGPT workspace RBAC settings"55 alt="Access token access permission in ChatGPT workspace RBAC settings"
46 lightSrc="/images/codex/enterprise/rbac_access_token_access_permission.png"56 lightSrc="/images/codex/enterprise/rbac_access_token_access_permission.png"
51 61
521. Go to [Workspace Settings > Permissions & roles](https://chatgpt.com/admin/settings).621. Go to [Workspace Settings > Permissions & roles](https://chatgpt.com/admin/settings).
532. In the **Access tokens** section, turn on **Allow users to create access tokens** if all allowed members should be able to create access tokens.632. In the **Access tokens** section, turn on **Allow users to create access tokens** if all allowed members should be able to create access tokens.
543. If members need to use those tokens with the Codex app, CLI, or IDE extension, make sure **Allow members to use Codex Local** is also turned on in the **Codex Local** section.643. If the workflow also needs a covered local surface, make sure **Allow members to use Codex Local** is turned on in the **Codex Local** section. This control covers local use in the ChatGPT desktop app, Codex CLI, and IDE extension.
55 65
56Keep access token creation limited to people or service owners who understand where the token will be stored, which automation will use it, and how it will be rotated.66Keep access token creation limited to people or service owners who understand where the token will be stored, which automation will use it, and how it will be rotated.
57 67
58## Set an access token expiration limit68## Set an access token expiration limit
59 69
60Workspace owners and admins can set the longest expiration that members can choose when they create a Codex access token. Go to [Workspace Settings > Permissions & roles](https://chatgpt.com/admin/settings), then set **Access token expiration limit** in the Codex Local section.70Workspace owners and admins can set the longest expiration that members can choose when they create a Codex access token. Go to [Workspace Settings > Permissions & roles](https://chatgpt.com/admin/settings), then set **Access token expiration limit** in the **Codex Local** section.
61 71
62<CodexScreenshot72<CodexScreenshot
63 alt="Access token expiration limit in ChatGPT workspace permissions settings"73 alt="Access token expiration limit in ChatGPT workspace permissions settings"
96 106
974. Choose an expiration. Prefer a finite expiration such as 7, 30, 60, or 90 days. If you choose **No expiration**, rotate the token on a regular schedule.1074. Choose an expiration. Prefer a finite expiration such as 7, 30, 60, or 90 days. If you choose **No expiration**, rotate the token on a regular schedule.
985. Select **Create**.1085. Select **Create**.
996. Copy the generated access token immediately. You cannot view it again after you close the modal.1096. Copy the generated access token immediately. You can't view it again after you close the modal.
1007. Store the token in your secret manager or CI secret store.1107. Store the token in your secret manager or CI secret store.
101 111
102The shortest custom expiration is one day. Revoked and expired tokens cannot be used to start new Codex runs.112The shortest custom expiration is one day. Revoked and expired tokens can't be used to start new authenticated runs.
103 113
104## Use an access token with Codex CLI114## Use an access token with Codex CLI
105 115
106For ephemeral automation, store the token in `CODEX_ACCESS_TOKEN` and run Codex normally:116For ephemeral automation, store the token in `CODEX_ACCESS_TOKEN` and run Codex CLI normally:
107 117
108```bash118```bash
109export CODEX_ACCESS_TOKEN="<access-token>"119export CODEX_ACCESS_TOKEN="<access-token>"
117codex exec "summarize the last release diff"127codex exec "summarize the last release diff"
118```128```
119 129
120`codex login --with-access-token` stores an agent identity credential in Codex auth storage. If you prefer not to persist credentials on the machine, use the `CODEX_ACCESS_TOKEN` environment variable instead.130`codex login --with-access-token` stores an agent identity credential in Codex CLI auth storage. If you prefer not to persist credentials on the machine, use the `CODEX_ACCESS_TOKEN` environment variable instead.
131
132`codex app-server` can use the same credential through `CODEX_ACCESS_TOKEN` or
133a login created with `codex login --with-access-token` to authenticate its
134OpenAI requests. That credential is separate from client-to-app-server
135transport authentication. For a remote WebSocket connection, configure a
136separate bearer or capability token as described in
137[App server](https://learn.chatgpt.com/docs/app-server); don't reuse the Codex access token as the
138transport token. See
139[Authentication and network environment variables](https://learn.chatgpt.com/docs/config-file/environment-variables#authentication-and-network).
121 140
122## Rotate or revoke a token141## Rotate or revoke a token
123 142
132 151
133## Permission model152## Permission model
134 153
135Access token creation is controlled by the workspace's access token permission, which is separate from the general Codex local permission. A member can have access to the Codex app, CLI, or IDE extension without being allowed to create access tokens.154The workspace access token permission controls token creation. The **Allow
155members to use Codex Local** workspace permission separately gates access to
156local use in the ChatGPT desktop app, Codex CLI, and IDE extension. A member can
157have that local access without permission to create access tokens.
136 158
137| Capability | Workspace owners and admins | Member with access token permission | Member without access token permission |159| Capability | Workspace owners and admins | Member with access token permission | Member without access token permission |
138| ------------------------------------------------------------- | ---------------------------------------------------- | --------------------------------------------- | -------------------------------------- |160| ------------------------------------------------------------- | ------------------------------------------------ | --------------------------------------------- | -------------------------------------- |
139| Open [Access tokens](https://chatgpt.com/admin/access-tokens) | Yes | Yes | No |161| Open [Access tokens](https://chatgpt.com/admin/access-tokens) | Yes | Yes | No |
140| Create access tokens | Yes, for their own ChatGPT workspace identity | Yes, for their own ChatGPT workspace identity | No |162| Create access tokens | Yes, for their own ChatGPT workspace identity | Yes, for their own ChatGPT workspace identity | No |
141| List access tokens | Workspace list, including who created each token | Only tokens they created | No |163| List access tokens | Workspace list, including who created each token | Only tokens they created | No |
142| Revoke access tokens from the Access tokens page | Any token in the workspace | Only tokens they created | No page access |164| Revoke access tokens from the Access tokens page | Any token in the workspace | Only tokens they created | No page access |
143| Grant or remove access token permission | Yes | No | No |165| Grant or remove access token permission | Yes | No | No |
144| Manage other Codex enterprise settings | Yes, based on admin role and Codex admin permissions | No, unless separately granted | No |166| Manage other local-client or Codex cloud settings | Yes, based on workspace admin permissions | No, unless separately granted | No |
145 167
146In short: workspace owners and admins manage access at the workspace level. Members need the access token permission to create and manage their own tokens, but the permission does not grant admin rights or access to other members' tokens.168In short: workspace owners and admins manage access at the workspace level.
169Members need the access token permission to create and manage their own tokens,
170but that permission grants neither admin rights nor access to other members'
171tokens.
147 172
148## Troubleshooting173## Troubleshooting
149 174
150### The access tokens page returns 404 or forbidden175### The access tokens page returns 404 or forbidden
151 176
152Ask a workspace owner or admin to confirm that your role includes **Allow users to create access tokens** and that **Allow members to use Codex Local** is enabled if you plan to use the token with Codex.177Ask a workspace owner or admin to confirm that your role includes **Allow users to create access tokens**. If your workflow also needs a covered local surface, confirm that **Allow members to use Codex Local** is enabled for local use in the ChatGPT desktop app, Codex CLI, and IDE extension.
153 178
154### `codex login --with-access-token` fails179### `codex login --with-access-token` fails
155 180
156Confirm that you copied the generated access token, not a browser session token or Platform API key. Also confirm that the token has not expired or been revoked.181Confirm that you copied the generated access token, not a browser session token or Platform API key. Also confirm that the token hasn't expired or been revoked.
157 182
158## Related docs183## Related docs
159 184
160- [Authentication](https://developers.openai.com/codex/auth)185- [Authentication](https://learn.chatgpt.com/docs/auth)
161- [Non-interactive mode](https://developers.openai.com/codex/noninteractive)186- [Non-interactive mode](https://learn.chatgpt.com/docs/non-interactive-mode)
162- [Admin setup](https://developers.openai.com/codex/enterprise/admin-setup)187- [Admin rollout guide](https://learn.chatgpt.com/docs/enterprise/admin-setup)
163- [Governance](https://developers.openai.com/codex/enterprise/governance)188- [Groups and provisioning](https://learn.chatgpt.com/docs/enterprise/groups-and-provisioning)
189- [Roles and workspace permissions](https://learn.chatgpt.com/docs/enterprise/roles-and-workspace-permissions)
190- [Governance](https://learn.chatgpt.com/docs/enterprise/governance)