VSCode Extension in Windows always Failed:Missing environment variable: `APIROUTER_API_KEY`. but i can use it in WSL,powershell,cmd,and i can normal use in VS code Extension 0.4.46-
Resolved 💬 9 comments Opened Dec 12, 2025 by canyue233OVO Closed Mar 29, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor)
responded on this thread — see the highlighted reply below.
What version of the VS Code extension are you using?
0.4.51
What subscription do you have?
Team
Which IDE are you using?
Vs code
What platform is your computer?
Microsoft Windows NT 10.0.19045.0 x64
What issue are you seeing?
VSCode Extension in Windows always Failed:Missing environment variable: APIROUTER_API_KEY. but i can use it in WSL,powershell,cmd,and i can normal use in VS code Extension 0.4.46-
What steps can reproduce the bug?
Just always Missing environment variable: APIROUTER_API_KEY.
What is the expected behavior?
_No response_
Additional information
_No response_
9 Comments
Am I correct in assuming that you've configured codex to look for environment variable
APIROUTER_API_KEYin your configuration file (config.toml)? This error indicates that you've told codex to use that environment variable's value as the API key for your model. If it's not available in the environment you're running codex in, then you'll see this error.我不清楚,环境配置都是配置好的,且我可以在WSL,cmd,powershell等环境运行正常,但是单在VS code里面就不行。对话就会显示Failed: Missing environment variable: APIROUTER_API_KEY.
I'm not sure. The environment configuration is already set up, and I can run it normally in environments like WSL, cmd, and PowerShell, but it just doesn't work in VS Code Extension without WSL connect in 0.4.46+,but can normal use in 0.4.46-. always shows: Failed: Missing environment variable: APIROUTER_API_KEY.
That indicates the environment variable isn't being preserved / inherited when you start VS Code.
<img width="440" height="153" alt="Image" src="https://github.com/user-attachments/assets/5e3ac472-46e9-47aa-89a6-90663b6d07e5" />
可是我在0.4.46-版本中是可以正常使用的,我检查了,环境变量是有被保留或继承的,应该还是CodeX的问题。
But in version 0.4.46 and earlier, it can be worked fine. I checked, and the environment variables are preserved or inherited properly. The issue is likely still with CodeX.
Yeah, the fact that you're seeing a difference in behavior across versions does seem to indicate a potential regression here. You mentioned that it worked on 0.4.46 but didn't on 0.4.51. Since you have a repro, are you able to narrow it down any further? For example, do you see the problem with 0.4.47?
我试了一下0.4.47,结果就出现了Failed:Missing environment variable: APIROUTER_API_KEY.
oh,it starts at 0.4.47,i test it,then Failed:Missing environment variable: APIROUTER_API_KEY. appeared.
could you please to fix it? thanks a lot.
when can i use 0.4.46+ codex? i wanna use gpt-5.2-codex immediately
This bug report hasn't received any upvotes or additional posts in three months. Closing.