Network error

Resolved 💬 9 comments Opened Apr 16, 2025 by JonathanMShaw Closed Apr 16, 2025
💡 Likely answer: A maintainer (tibo-openai, collaborator) responded on this thread — see the highlighted reply below.

Codex runs, but only responds with a network error message. I can connect to ChatGPT.com and talk to o4-mini without any problems, and if I change my OPENAI_API_KEY to something invalid I get a very different error message. The message below isn't very informative, though. Any idea why it's not working?

I'm running Ubuntu 20.04, have 128Gb of RAM (mostly free), and NodeJs v22.14.0.

╭──────────────────────────────────────────────────────────────╮
│ ● OpenAI Codex (research preview) v0.1.04161006 │
╰──────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────╮
│ localhost session: 21349ad9a2974d4d9908f251feed32c5 │
│ ↳ workdir: ~/xri/gates/src │
│ ↳ model: o4-mini │
│ ↳ approval: suggest │
╰──────────────────────────────────────────────────────────────╯
user
test

system
⚠️ Network error while contacting OpenAI. Please check your connection and try again.
╭──────────────────────────────────────────────────────────────╮
│ send a message │
╰──────────────────────────────────────────────────────────────╯
send q or ctrl+c to exit | send "/clear" to reset | send "/help" for commands | press enter to send

View original on GitHub ↗

9 Comments

tibo-openai collaborator · 1 year ago

We are looking at this 👀

JonathanMShaw · 1 year ago

Oops, my bad. On the web page, I misread 4o-mini as o4-mini. I need to upgrade my API access to talk to o4-mini, but I can at least run codex against 4o-mini (which is probably a recipe for disaster). Some improvements to the error message might be nice, but otherwise, problem solved!

jaddoescad · 1 year ago

Still getting the error, whaere exactly did you change this?

hankberger · 1 year ago

I'm also hitting this error. I'm able to CURL the api from my WSL session and get a successful response. I think I had an incorrect model set initially, but just set it as the same model my buddy is running and still hitting "⚠️ Network error while contacting OpenAI. Please check your connection and try again."

hankberger · 1 year ago

Built it locally and it's able to connect using git bash 🤷‍♂️

JonathanMShaw · 1 year ago

It seems using the default model (o4-mini) doesn't actually work. After going to the dashboard and enabling o4-mini access (which HR did; I'm not sure what the dashboard actually looks like), the trick was to run with:

codex -m o4-mini-2025-04-16

With those two changes, it works like a charm!

AndreMaciel66 · 1 year ago

I'm having this issue, i'm wondering if i need to setup any proxy or ssl cert from my end. I also tried codex -m o4-mini-2025-04-16

physiclaw · 1 year ago
We are looking at this 👀
diff

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;

physiclaw · 1 year ago

need to pass httpAgent argument to OpenAI instance constructor