network connection error

Resolved 💬 17 comments Opened Apr 21, 2025 by jachenms Closed Aug 7, 2025

What version of Codex is running?

_No response_

Which model were you using?

_No response_

What platform is your computer?

_No response_

What steps can reproduce the bug?

!Image

when rin the codex, always generate the erro .

What is the expected behavior?

_No response_

What do you see instead?

_No response_

Additional information

_No response_

View original on GitHub ↗

17 Comments

qcname · 1 year ago

我也遇到了相同的问题

nivzx · 1 year ago

Hi, two questions-

  1. Are you using a proxy server?
  2. Can you share the logs when you start codex with DEBUG environment variable set to true?
export DEBUG=true
physiclaw · 1 year ago

of course you need to get access to openai in China via VPN, the issue may come from the OPENAI package the codex project depends, it initialize the OPENAI package without specify the proxy or agent

physiclaw · 1 year ago
Hi, two questions- 1. Are you using a proxy server? 2. Can you share the logs when you start codex with DEBUG environment variable set to true? `` export DEBUG=true ``

it just start the post request, nothing response from the server, the codex just not respect the $HTTP_PROXY $HTTPS_PROXY env variable

physiclaw · 1 year ago

import OpenAI from 'openai';
import { HttpsProxyAgent } from 'https-proxy-agent'; // import agent module

const client = new OpenAI({
apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
httpAgent: new HttpsProxyAgent(process.env.HTTPS_PROXY), // pass the httpAgent
});

const response = await client.responses.create({
model: 'gpt-4o',
instructions: 'You are a coding assistant that talks like a pirate',
input: 'how to efficiently learn JavaScript?',
});

console.log(response.output_text);

physiclaw · 1 year ago
import OpenAI from 'openai'; import { HttpsProxyAgent } from 'https-proxy-agent'; // import agent module const client = new OpenAI({ apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted httpAgent: new HttpsProxyAgent(process.env.HTTPS_PROXY), // pass the httpAgent }); const response = await client.responses.create({ model: 'gpt-4o', instructions: 'You are a coding assistant that talks like a pirate', input: 'how to efficiently learn JavaScript?', }); console.log(response.output_text);

every where the codex new OpenAI instance, must provide the httpAgent argument, this is easy fix with several place

physiclaw · 1 year ago

diff --git a/codex-cli/package.json b/codex-cli/package.json
index 7b852ca..0caaaf9 100644
--- a/codex-cli/package.json
+++ b/codex-cli/package.json
@@ -37,6 +37,7 @@
"fast-npm-meta": "^0.4.2",
"figures": "^6.1.0",
"file-type": "^20.1.0",

  • "https-proxy-agent": "^7.0.6",

"ink": "^5.2.0",
"js-yaml": "^4.1.0",
"marked": "^15.0.7",

diff --git a/codex-cli/src/utils/agent/agent-loop.ts b/codex-cli/src/utils/agent/agent-loop.ts
index aaca48f..dc0e114 100644
--- a/codex-cli/src/utils/agent/agent-loop.ts
+++ b/codex-cli/src/utils/agent/agent-loop.ts
@@ -11,7 +11,7 @@ import type {
} from "openai/resources/responses/responses.mjs";
import type { Reasoning } from "openai/resources.mjs";

-import { OPENAI_TIMEOUT_MS, getApiKey, getBaseUrl } from "../config.js";
+import { OPENAI_TIMEOUT_MS, HTTPS_PROXY_URL, getApiKey, getBaseUrl } from "../config.js";
import { log } from "../logger/log.js";
import { parseToolCallArguments } from "../parsers.js";
import { responsesCreateViaChatCompletions } from "../responses.js";
@@ -25,6 +25,7 @@ import {
import { handleExecCommand } from "./handle-exec-command.js";
import { randomUUID } from "node:crypto";
import OpenAI, { APIConnectionTimeoutError } from "openai";
+import { HttpsProxyAgent } from "https-proxy-agent";

// Wait time before retrying after rate limit errors (ms).
const RATE_LIMIT_RETRY_WAIT_MS = parseInt(
@@ -288,6 +289,7 @@ export class AgentLoop {
this.sessionId = getSessionId() || randomUUID().replaceAll("-", "");
// Configure OpenAI client with optional timeout (ms) from environment
const timeoutMs = OPENAI_TIMEOUT_MS;

  • const https_proxy = HTTPS_PROXY_URL;

const apiKey = getApiKey(this.provider);
const baseURL = getBaseUrl(this.provider);

@@ -306,7 +308,9 @@ export class AgentLoop {
session_id: this.sessionId,
},
...(timeoutMs !== undefined ? { timeout: timeoutMs } : {}),

  • ...(https_proxy ? { httpAgent: new HttpsProxyAgent(https_proxy)} : {}),

});

  • console.debug((https_proxy ? { httpAgent: new HttpsProxyAgent(https_proxy)} : {}))

setSessionId(this.sessionId);
setCurrentModel(this.model);

diff --git a/codex-cli/src/utils/config.ts b/codex-cli/src/utils/config.ts
index 1df2e19..04b340f 100644
--- a/codex-cli/src/utils/config.ts
+++ b/codex-cli/src/utils/config.ts
@@ -36,6 +36,7 @@ export const OPENAI_TIMEOUT_MS =
parseInt(process.env["OPENAI_TIMEOUT_MS"] || "0", 10) || undefined;
export const OPENAI_BASE_URL = process.env["OPENAI_BASE_URL"] || "";
export let OPENAI_API_KEY = process.env["OPENAI_API_KEY"] || "";
+export const HTTPS_PROXY_URL = process.env["HTTPS_PROXY"] || process.env["HTTP_PROXY"] || "";

export function setApiKey(apiKey: string): void {
OPENAI_API_KEY = apiKey;

AppKidd · 1 year ago

Was also experiencing this network error. Resolved by switching from a personally-owned secret key to a service account one.

mjpizz · 1 year ago

also ran into this today. I expected the OpenAI object to use my HTTPS_PROXY env var transparently, but as @echosprint points out it looks like all the API calls need to be modified to support it.

jachenms · 1 year ago

!Image

still error, appreciated to help me to solve the issue.

jachenms · 1 year ago

╭──────────────────────────────────────────────────────────────╮
│ ● OpenAI Codex (research preview) v0.1.2504172351 │
╰──────────────────────────────────────────────────────────────╯
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│Warning! It can be dangerous to run a coding agent outside of a git repo in case there are changes that you want to revert. Do you want to continue? │
│ │
│/mnt/d/codex-main(1) │
│ │
│y/N │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
OpenAI:DEBUG:request https://api.openai.com/v1/models { method: 'get', path: '/models' } {
accept: 'application/json',
'content-type': 'application/json',
'user-agent': 'br/JS 4.94.0',
'x-stainless-lang': 'js',
'x-stainless-package-version': '4.94.0',
'x-stainless-os': 'Linux',
'x-stainless-arch': 'x64',
'x-stainless-runtime': 'node',
'x-stainless-runtime-version': 'v22.13.0',
authorization: 'REDACTED',
'x-stainless-retry-count': '0',
'x-stainless-timeout': '600'
}
OpenAI:DEBUG:request https://api.openai.com/v1/models { method: 'get', path: '/models' } {
accept: 'application/json',
'content-type': 'application/json',
'user-agent': 'br/JS 4.94.0',
'x-stainless-lang': 'js',
'x-stainless-package-version': '4.94.0',
'x-stainless-os': 'Linux',
'x-stainless-arch': 'x64',
'x-stainless-runtime': 'node',
'x-stainless-runtime-version': 'v22.13.0',
authorization: 'REDACTED',
'x-stainless-retry-count': '1',
'x-stainless-timeout': '600'
}
OpenAI:DEBUG:request https://api.openai.com/v1/models { method: 'get', path: '/models' } {
accept: 'application/json',
'content-type': 'application/json',
'user-agent': 'br/JS 4.94.0',
'x-stainless-lang': 'js',
'x-stainless-package-version': '4.94.0',
'x-stainless-os': 'Linux',
'x-stainless-arch': 'x64',
'x-stainless-runtime': 'node',
'x-stainless-runtime-version': 'v22.13.0',
authorization: 'REDACTED',
'x-stainless-retry-count': '2',
'x-stainless-timeout': '600'
}

jachenms · 1 year ago

1 I have used proxt agent

BitTuner-Jack · 1 year ago

Hi, @jachenms resolved it yet?

victordov · 1 year ago

This issue still persists, and I run 3-4 requests with network error and only 1 successful. It is frustrating, the least I can say

seanhederman · 1 year ago

Makes codex completely useless. Going back to Claude. It may be a much worse model, but at least their CLI works.

codex-maintainers · 11 months ago

Thank you for the feedback! Please try again with the latest version of Codex CLI. If the issue persists, let us know. You can also check out the native/Rust implementation for improved stability and performance.

NukeThemAII · 9 months ago

i run cli on vps, usa server and it dont have internet acces, no proxy no vpn