OpenAI API proxies
Call the OpenAI API from a supported country on a fixed datacenter IP: set it in the Python or Node SDK, and add the fixed address to OpenAI’s IP allowlist.
View options and pricingOpenAI Codex CLI is a terminal tool for working with code that sends requests to OpenAI. If you work from a network that requires a proxy, Codex CLI can be pointed at it through environment variables. This guide covers the variables, permanent setup, checking the exit IP and common errors.
Command-line tools usually read standard proxy-related environment variables; check the documentation for your version of Codex CLI to see which ones it reads. In practice, two variables are enough: HTTPS_PROXY and NO_PROXY.
HTTPS_PROXY specifies the proxy address for HTTPS requests (this is the protocol the OpenAI API uses). The value format is http://host:port. Codex CLI does not support SOCKS5 proxies, so use an HTTP asset (port 2222 on Proxy302). If the proxy requires authentication, the username and password are embedded directly in the URL: http://username:password@host:port.
HTTP_PROXY is used for regular HTTP requests. In most cases, a single HTTPS_PROXY is sufficient, but if both variables are set, each is applied to its own type of request.
ALL_PROXY acts as a universal fallback: if the variable for a specific protocol is not set, ALL_PROXY is used instead. This is convenient when you have a single proxy for all traffic.
NO_PROXY (or no_proxy) is a list of hosts and domains that should be connected to directly, without the proxy. Default values: localhost,127.0.0.1. If you have internal services or corporate network domains, add them to this list separated by commas.
For a temporary setup in the current terminal session, use the export command:
export HTTPS_PROXY="http://username:password@proxy-host:port"
export NO_PROXY="localhost,127.0.0.1"Example only: replace the placeholder values with your own.
To make the variables permanent, add the export lines to your shell's profile file. For Bash, this is ~/.bash_profile or ~/.bashrc; for Zsh, it is ~/.zshrc. After saving the file, restart the terminal or run source ~/.bashrc.
You can verify that the variables are set with the command env | grep -i proxy.
In PowerShell, the current session uses the $env: syntax:
$env:HTTPS_PROXY = "http://username:password@proxy-host:port"
$env:NO_PROXY = "localhost,127.0.0.1"Example only: replace the placeholder values with your own.
For permanent setup, use the setx command, which writes the variables to the user registry:
setx HTTPS_PROXY "http://username:password@proxy-host:port"
setx NO_PROXY "localhost,127.0.0.1"Example only: replace the placeholder values with your own.
After running setx, restart PowerShell for the changes to take effect. For system-level variables (available to all users), run PowerShell as administrator and use [System.Environment]::SetEnvironmentVariable().
Before sending requests, check which IP address and country the proxy actually gives you, so you know traffic goes through it. The simplest way is a request through the proxy to any IP geolocation service:
curl -x "http://username:password@proxy-host:port" https://ipinfo.io/jsonExample only: replace the placeholder values with your own.
In the response, the ip field is the exit IP that OpenAI sees and the country field is its country. If the address is not the one you expect, traffic is not going through the proxy: check the variables again.
Which countries are supported is detailed in the guide to countries where ChatGPT, Claude, and Gemini work.
OpenAI publishes a list of countries and territories where its API operates. Requests coming from a non-supported region receive a response with code 403 and the error text "Country, region, or territory not supported".
A proxy only changes the network address visible to the service. The platform itself makes the access decision based on the IP address and other factors, and a proxy does not change OpenAI's terms. OpenAI warns that using its services from outside the supported list may get the account blocked or suspended. If you sign in with a ChatGPT account, ChatGPT's supported countries apply; with an API key, the OpenAI API list applies.
For Codex CLI on Proxy302, use an HTTP IP on port 2222; the host, username and password are shown in My assets.
If the proxy requires a username and password, pass them directly in the URL of the environment variable:
HTTPS_PROXY=http://user:password@host:portExample only: replace the placeholder values with your own.
A password may contain special characters (@, :, /, ?, #, %), which have meaning in a URL. They must be escaped using URL encoding (percent-encoding): @ becomes %40, : becomes %3A, / becomes %2F, and so on. For example, if the password is my@pass:123, it should look like my%40pass%3A123 in the URL.
Error 407 Proxy Authentication Required. The proxy received the request but did not accept the credentials. Check the correctness of the username and password in the URL, and make sure special characters are escaped. If the problem persists, ask your proxy administrator which type of authentication it requires.
Certificate errors. If a corporate proxy re-signs TLS, point CODEX_CA_CERTIFICATE at a PEM file with the company root CA before running codex login (Codex falls back to SSL_CERT_FILE when it is unset).
Timeouts. If requests hang and do not complete, the proxy is likely not configured or the address is incorrect. Check the variables with the command env | grep -i proxy, make sure the URL includes a scheme (http://), and that the port and host are accessible.
Error "Country, region, or territory not supported". A 403 means OpenAI does not support the region the request comes from; a proxy does not change that. OpenAI warns that using its services from outside the supported list may get the account blocked or suspended.
Full setup for the OpenAI API is on the OpenAI API proxies page. Claude Code works the same way; see the Claude Code proxy setup guide.
Add the lines export HTTPS_PROXY=... and export NO_PROXY=... to the file ~/.zshrc (macOS Catalina and newer) or ~/.bash_profile, then restart the terminal.
No. Codex CLI accepts only HTTP proxies (http://) in HTTPS_PROXY and ALL_PROXY; buy the IP with the HTTP protocol (port 2222).
The extension starts Codex with VS Code's own environment. If you set the variables after VS Code was opened, quit and reopen it fully, or launch it from a terminal where the variables are set (code .). On Windows, set them permanently with setx and restart VS Code.
Only if your organization has an IP allowlist enabled in OpenAI. Then add the proxy's exit IP (the one https://ipinfo.io/json shows through the proxy), not the proxy host; this needs a static IP, because a rotating exit changes.
MCP adds tools to Codex CLI. With the proxy302-mcp server, Codex can get a Proxy302 proxy and fetch pages through it. Add it with one command, or write the same entry into ~/.codex/config.toml.
proxy302-mcp is the official Proxy302 MCP server, open source on GitHub and maintained by the Proxy302 team. Proxy302 also runs it at https://proxy302.com/v1/mcp: clients that can send an Authorization header, such as Claude Code, Cursor and VS Code, connect with an API key and install nothing.
This is a separate setting from the proxy variables on this page. HTTPS_PROXY decides how Codex CLI itself reaches OpenAI; the MCP server's tools have their own settings, and installing the server does not change how Codex connects. The guide to the Proxy302 MCP server covers the tools, the other clients and the limits.
codex mcp add proxy302 --env PROXY302_API_KEY="<key id>:<secret>" -- npx -y github:proxy302/proxy302-mcpReplace <key id>:<secret> with your Proxy302 API key.
[mcp_servers.proxy302]
command = "npx"
args = ["-y", "github:proxy302/proxy302-mcp"]
env = { PROXY302_API_KEY = "<key id>:<secret>" }The same entry in the config file. Replace <key id>:<secret> with your Proxy302 API key.
A static ISP lease fits this routine: the IP stays fixed while the lease runs and does not rotate, so one address stays with one account or one tool. The page on OpenAI API proxies has the preset and the full setup, and the static ISP page describes the product.
Open the static ISP page, choose the country, the term and the quantity, and the protocol, HTTP or SOCKS5. The protocol is fixed for each IP when you buy it.
Generate the IPs, then open My assets (the console page that holds everything you bought) and copy HOST, PORT, USERNAME and PASSWORD. The Tools & checks page shows a ready example with your own endpoint.
Enter the details in the browser profile, tool or phone that will use the IP.
Check the exit with https://ipinfo.io/json through the proxy. The country field should match the country you chose.
From mainland China, open Proxy302 Fast Connect from the Tools & checks page, click 「一键加速」 (One-click boost) and keep it open while you use the proxy.
A static ISP IP costs US$0.50 for one day and US$7.99 for 30 days, about US$0.27 per day, the same in every country. Availability changes daily and is shown on the order page. There is no free trial, and the smallest purchase is one IP for one day. An IP does not lift a restriction, undo a ban or raise a limit.
| Item | Price | Protocols | Locations | Fits agent work like |
|---|---|---|---|---|
| Rotating residential | From US$1.50 per GB (Budget line); US$5 per GB (Premium line); lower per GB in larger packages | HTTP, SOCKS5 | 195+ countries and regions; state and major city on lines that support it | Browsing and research agents, data collection |
| Static ISP, per IP | US$0.50 for 1 day, US$7.99 for 30 days, the same in every country | HTTP or SOCKS5, chosen per IP | 30 countries on the order form; stock changes daily | One fixed IP for each account an agent signs in to |
| ISP for AI subscriptions | Per 30 days: Claude 15 PTC, GPT / Grok 10 PTC, Gemini 8 PTC; the first order in each tier is 50% off | HTTP or SOCKS5 | Claude: US, UK, DE, JP. GPT / Grok: US, UK, FR, JP, KR. Gemini: US, UK, FR, JP | Coding tools and agents signed in to ChatGPT, Claude, Gemini or Grok |
| Datacenter, per IP | US$0.25 for 1 day, US$3.99 for 30 days | HTTP or SOCKS5, chosen per IP | 8 countries | API calls and tool traffic where the IP type does not matter |
| proxy302-mcp | Free, open source (MIT) | MCP over stdio, started with npx | Uses the products above | Lets Claude Code, Codex, Cursor and other MCP clients get a proxy and fetch pages through it |
Prices are in PTC, paid from the wallet; 1 PTC = US$1. There is no free trial: the smallest purchase is 1 GB of rotating residential traffic or one IP for one day. Checked on 4 November 2026.
Official documentation · Confirmed on:
Read on 24 October 2026: accessing or offering access to OpenAI services outside the listed countries and territories "may result in your account being blocked or suspended."
Official documentation · Confirmed on:
Read on 24 October 2026: sign in with ChatGPT or with an API key; set CODEX_CA_CERTIFICATE to a PEM bundle before logging in behind a corporate TLS proxy, with SSL_CERT_FILE as the fallback.
Official documentation · Confirmed on:
Source read at commit 39850010 (23 October 2026): HTTPS_PROXY, then ALL_PROXY, is passed to the HTTP client; socks, socks4 and socks5 schemes are marked unsupported, and the HTTP client is built without SOCKS support. On 4 November 2026 codex-rs/Cargo.toml declares reqwest 0.12 with only the "cookies" feature, and codex-rs/Cargo.lock has no tokio-socks crate.
Source code, not user documentation; behaviour can change between versions.
Official documentation · Confirmed on:
Read on 24 October 2026: syntax setx <variable> <value>, with no equals sign.
Product observation · Confirmed on:
Product facts file of the site (values checked against the console, the backend and the price table on 18-19 October 2026): products, prices in US$ (1 PTC = US$1), lease terms, protocols and ports, countries, quantity limits, no free trial.
Official documentation · Confirmed on:
Read on 4 November 2026: codex mcp add <name> --env VAR=VALUE -- <command>, and the [mcp_servers.<name>] table in ~/.codex/config.toml with command, args and env.
Product observation · Confirmed on:
README of the official Proxy302 MCP server: install commands, environment variables, the seven tools, the read-only, spend-free scope and the hosted endpoint https://proxy302.com/v1/mcp.
Product observation · Confirmed on:
Public JSON at proxy302.com/v1/proxy/ai-isp/catalog, read 4 November 2026: three tiers (Claude, GPT / Grok, Gemini), price per 30 days in PTC, 50% off the first order in a tier, cities by country.
Create an account, top up once, then pick rotating residential, static ISP or datacenter IPs and have one running in your browser within minutes.