Skip to content

Linux + HTTP proxy: Codex CLI fails in both API key mode and device-auth mode, while curl works for Responses API #16079

Open

Description

@github-yxb

What version of Codex CLI is running?

codex-cli 0.117.0

What subscription do you have?

Organization

Which model were you using?

No response

What platform is your computer?

Linux server

What terminal emulator and version are you using (if applicable)?

No response

What issue are you seeing?

Codex CLI fails on a Linux server behind an HTTP proxy, even though direct curl works from the same shell session.

I tested all of the following in the same Linux shell:

  1. curl to the OpenAI Responses API works, including streaming:

    curl -N -v https://api.openai.com/v1/responses \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $OPENAI_API_KEY" \
      -d '{
        "model": "gpt-5.2",
        "input": "say hello",
        "stream": true
      }'
  2. Starting codex in the same shell fails during conversation with:
    Stream disconnected before completion: error sending request for url (https://api.openai.com/v1/responses)

  3. I also tried:

    • launching codex from the exact same shell as curl
    • explicitly passing proxy-related env vars when starting codex
    • upgrading Codex CLI to the latest version

    The failure still happens.

  4. After logging out, I tried ChatGPT device-code login on this headless Linux server:
    codex login --device-auth

    That also fails, with:
    error sending request for url (https://auth.openai.com/api/accounts/deviceauth/usercode)

So in this environment:

  • direct curl to https://api.openai.com/v1/responses works
  • Codex CLI request path to https://api.openai.com/v1/responses fails
  • Codex CLI device-auth request path to https://auth.openai.com/api/accounts/deviceauth/usercode also fails

This makes it look like the CLI’s HTTP/proxy/TLS handling is behaving differently from curl in the same environment.

What steps can reproduce the bug?

  1. Prepare a Linux server that accesses the internet through an HTTP proxy.

  2. Export the proxy environment variables in the shell where Codex CLI will be launched, for example:
    export https_proxy=http://<proxy-host>:<proxy-port>
    export http_proxy=http://<proxy-host>:<proxy-port>

  3. Verify that direct OpenAI API access works with curl from the same shell:
    curl -N -v https://api.openai.com/v1/responses -H "Content-Type: application/json" -H "Authorization: Bearer $OPENAI_API_KEY" -d '{"model":"gpt-5.2","input":"say hello","stream":true}'

  4. Launch Codex CLI from that same shell:
    codex

  5. Send any prompt in Codex CLI.

  6. Observe that the request fails with:
    Stream disconnected before completion: error sending request for url (https://api.openai.com/v1/responses)

  7. Log out and try device-code authentication:
    codex logout
    codex login --device-auth

  8. Observe that device auth also fails with:
    error sending request for url (https://auth.openai.com/api/accounts/deviceauth/usercode)

What is the expected behavior?

No response

Additional information

No response

Activity

  1. added
    bug
    on Mar 28, 2026
  2. added
    CLI
    auth
    on Mar 28, 2026
  3. removed
    CLI
    on Mar 28, 2026
  4. etraut-openai commented on Mar 28, 2026

    @etraut-openai
    Contributor

    This sounds specific to your proxy configuration. You'll need to investigate further and diagnose the problem.

  5. github-yxb commented on Mar 28, 2026

    @github-yxb
    Author

    This sounds specific to your proxy configuration. You'll need to investigate further and diagnose the problem.

    Thanks. I agree the proxy is part of the environment, but I don't think this has been narrowed down to "just a proxy misconfiguration" yet.

    Here is why I opened the issue:

    • curl to https://api.openai.com/v1/responses works from the same Linux server
    • the request is streamed successfully through the same proxy
    • codex fails from the same shell session, with the same proxy env vars
    • I also tried explicitly passing the proxy env vars and upgrading to the latest Codex version
    • after codex logout, codex login --device-auth also fails on https://auth.openai.com/api/accounts/deviceauth/usercode
  6. github-yxb commented on Mar 28, 2026

    @github-yxb
    Author

    I have a useful update.

    As a workaround, I asked another AI tool to generate a small local proxy service. It runs as an HTTP server on 127.0.0.1:9999, accepts Codex requests locally, and then forwards them to OpenAI through my existing proxy setup.

    After that, I updated ~/.codex/config.toml to use the local service:

    [model_providers.OpenAI]
    name = "OpenAI"
    base_url = "http://127.0.0.1:9999/v1"
    wire_api = "responses"
    requires_openai_auth = true

    With this configuration, Codex works.

    To me, this strongly suggests the issue is not simply “my proxy is broken”. The same environment fails when Codex talks to OpenAI directly, but succeeds when Codex talks to a local HTTP service that forwards the request through the proxy.

    That points to some difference in how Codex handles direct outbound proxy/TLS/networking compared with other clients.

    This workaround took hours to figure out, so I do think this issue deserves investigation, even if the root cause is an interaction with certain proxy environments.

  7. 928234269 commented on Apr 2, 2026

    @928234269

    This sounds specific to your proxy configuration. You'll need to investigate further and diagnose the problem.这听起来像是你的代理配置问题。你需要进一步调查并诊断问题所在。

    I also encountered the same problem. I looked into many issues, but it seems that the developers never regarded this as a problem. It's quite strange. Have they ever used Codex in the proxy scenario themselves?

  8. iamryanchia commented on Apr 11, 2026

    @iamryanchia

    Encounter the same problem

  9. MichaelErmer commented on Apr 23, 2026

    @MichaelErmer

    PSA: The issue is with TLS, you need to have your proxy/gateway support TLS1.2 until codex (Mac ARM) is fixed to support TLS1.3

  10. Haxel0rd commented on Jul 15, 2026

    @Haxel0rd

    There is clearly some issue with codex app about this,- in my case update to latest codex caused the same error, while minutes before everything was fine. I was not running traffic through any proxy and the issue also persists with reboot, while everything else works fine and as usual.

  11. Haxel0rd commented on Jul 16, 2026

    @Haxel0rd

    Was able to get codex working again for me, in my case the DNS resolution in WSL instance was broken, you can confirm it with running this in your WSL machine:

    curl -v https://auth.openai.com

    If this says name or service not known and the following ping returns normal answer:

    ping 8.8.4.4

    Then your issue is most likely in

    /etc/resolv.conf

    Quickfix: set google DNS as nameserver. This should make codex work again and from that moment on you can tell him to find out why it happened in the first place. resolv.conf should look something like this then:

    user@wsl:~$ cat /etc/resolv.conf
    nameserver 8.8.8.8
    nameserver 8.8.4.4
    options timeout:2 attempts:2
    user@wsl:~$

    and curl to auth.openai.com should now work again.

    == UPDATE ==

    found the source of the problem, it seems to be an issue with stale HSN Firewall rules. I used the following commands, found under https://learn.microsoft.com/en-us/windows/wsl/troubleshooting under "Troubleshooting DNS in WSL" under point 4.:

    PS C:\Windows\system32> wsl --shutdown
    PS C:\Windows\system32> Get-NetFirewallRule -Name "HNS*" | Get-NetFirewallPortFilter | where Protocol -eq UDP | where LocalPort -eq 53 | Remove-NetFirewallRule
    PS C:\Windows\system32> hnsdiag.exe delete all
    PS C:\Windows\system32> Restart-Service hns

    (note this will remove firewall rules for port 53/udp, usually not a problem unless you have explicit custom setup there).

    Then set DNS to local resolver and it my old setup before the quickfix (setting google dns), was working again as usual.

  12. ZzzTSudio commented on Sep 3, 2026

    @ZzzTSudio

    I encountered the same issue. On an ARM Linux machine like nvidia dgx spark, the login credentials are correct, but the conversation always remains in the connecting state, which is exactly the same as the abnormal situation described above.It seems that the codex cli and chatgpt app share a common login system, and this issue can be reproduced even with a proxy enabled.

  13. ZzzTSudio commented on Sep 3, 2026

    @ZzzTSudio

    The proxy service utilizes the open-source software Clash Verge, which functions perfectly on Windows systems and can be used with Codex.

  14. ZXCYFR commented on Oct 8, 2026

    @ZXCYFR

    我在 Ubuntu 24.04 上也遇到了类似情况,用的是 Clash Verge。CLI 在系统代理下正常,桌面版却一直没输出,开 TUN 才能用。

    我这边有效的办法是单独做一个启动脚本:给桌面程序传入代理环境变量,同时加上 Chromium 的代理参数。只开系统代理似乎没有让桌面里的所有网络请求都走代理。

    配置大致如下,7897 换成自己的 Clash HTTP/mixed 端口:

    #!/bin/sh
    proxy_url='http://127.0.0.1:7897'
    export HTTP_PROXY="$proxy_url" HTTPS_PROXY="$proxy_url" ALL_PROXY="$proxy_url"
    export http_proxy="$proxy_url" https_proxy="$proxy_url" all_proxy="$proxy_url"
    export NO_PROXY='localhost,127.0.0.1,::1'
    export no_proxy="$NO_PROXY"
    nohup /usr/bin/chatgpt --proxy-server="$proxy_url" \
      '--proxy-bypass-list=<local>;localhost;127.0.0.1;[::1]' \
      "$@" >/dev/null 2>&1 </dev/null &

    要先完全退出旧的桌面进程,再用脚本启动,否则可能还是原来的进程在运行。我另外加了一个 ChatGPT Clash 菜单入口,保留原版入口,方便以后切回去。有内网 VPN 的话,把实际内网网段也加进代理例外。

    这样关掉 TUN 后,本地桌面对话已经能用了。不过菜单冷启动的登录状态还需要观察,云端 durable 连接仍有超时。这个办法供“CLI 正常、桌面不正常”的情况参考,不一定适用于主帖里 CLI 也失败的问题。

  15. qiansu0725 commented on Oct 9, 2026

    @qiansu0725

    switch the proxy type from Socks5 to Socks5+Http just solve this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    authbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions