The docs seem to indicate you can use your OpenAI API key with the VS Code Extension, but there isn’t a lot of detail on how to actually configure that. Can we get some clarity around what exactly needs to be updated in the extension config to enable this? I’ve hit my codex local limit and would like to pivot to using an API key. Thank you!
I haven’t personally done this, but perhaps it can help you a bit:
- These are the instructions for Codex CLI, but I think they are supposed to be related:
codex/docs/authentication.md at main · openai/codex · GitHub
- In the IDE settings, it refers to the same configuration file, so it is possible that once you set things for Codex CLI it might work for the IDE plugin too.
Please let us know if you make it work!
So as of a few minutes ago I think I figured it out. I had to install the codex CLI and then open the auth.json file in my IDE. I wiped out the existing token & refresh data from there and just saved the API key in that file, as well as set the config.toml file to have API key as my preferred auth method. After restarting VS code and opening the extension, it seems to be using the API key now!
Didn’t work for me on cursor, config.toml wasn’t there, i tried to create it manually, i’ve also tried to add the config directly into user settings and saved the apikey in auth.json but when i open codex i see “Sign in with ChatGPT” popup
same here bro, but i just figured it out!
After installing the extension, it still required login with chatgpt when I only set up the config
# ~/.codex/config.toml
preferred_auth_method = "apikey"
I guess we have to set env variable at the same time just like Codex Cli. So I launched VS Code from shell with the env var set up
% export OPENAI_API_KEY="your-api-key-here"
% code .
And it worked! I guess other ways to set up env for vs code extension would also be successful.
I can also confirm that setting the API key in auth.json worked for me. I had a bit of an issue since I couldn’t find the schema for auth.json anywhere so I logged in to force it to generate the file. Just for anyone else who finds this discussion later, the file just needs to look like this:
~/.codex/auth.json
{“OPENAI_API_KEY”: “YOUR_API_KEY_HERE”}
Once I restarted VS Code it picked up the API key and the Codex extension progressed past the login screen to the chat prompt.



