OpenAI API returns 401 ip_not_authorized. Fix the IP allowlist
HTTP 401 ip_not_authorized means a valid key’s egress IP is off the allowlist. Add the IP or CIDR, confirm the list, wait up to 15 minutes, then retest. Short answer: 5 steps. 1) Confirm the error is ip_not_authorized, not a bad key; 2) Find the public egress IP the API actually sees; 3) Add the IP or CIDR on the allowlist that applies; 4) Enable the right scope, then wait before retrying; 5) Retest from allowed and blocked paths.
Last updated: · This page is the decision checklist; the tools list for “Fix OpenAI API 401 ip_not_authorized” is a separate URL.
How do I add the egress IP when OpenAI returns 401 ip_not_authorized?
Confirm the error is ip_not_authorized, not a bad key
Read the response body. HTTP 401 with `ip_not_authorized` means the source IP failed an active IP allowlist check even if the key is valid. That is different from “Incorrect API key provided” or “Invalid Authentication.” Error codes: https://developers.openai.com/api/docs/guides/error-codes
Find the public egress IP the API actually sees
Measure the IP from the same path that sends the request (production host, CI runner, NAT gateway, VPN, or proxy)—not only your laptop. Cloud and container egress often differs from local Wi‑Fi. OpenAI evaluates the public source IP that reaches api.openai.com. IP allowlist guide: https://developers.openai.com/api/docs/guides/ip-allowlist
Add the IP or CIDR on the allowlist that applies
In platform Settings → Security → IP allowlist, add an address (for example `203.0.113.10`) or CIDR (`203.0.113.0/24`). You can list up to 50 entries. Use the Check tool to verify the address is covered. Project-level allowlists override organization allowlists and do not merge—if the project has its own active list, only that list counts.
Enable the right scope, then wait before retrying
Enable the allowlist for the specific project tied to the key, or for the whole organization if that is intentional. Organization enablement affects every project without its own active list, including staging and CI. Changes can take up to 15 minutes to apply—retrying immediately often still fails.
Retest from allowed and blocked paths
From an allowed path: `curl https://api.openai.com/v1/models -H "Authorization: Bearer $OPENAI_API_KEY"` should authenticate normally. From an IP not on the active list, you should still see 401 `ip_not_authorized`. If production still fails, re-check NAT/VPN egress and which org/project the key belongs to. IP allowlisting is not a substitute for key rotation, and Private Link is not compatible with IP allowlist controls.
Which tools are best to fix OpenAI API 401 ip_not_authorized?
IP allowlist guide
Configure project vs organization allowlists, Check tool, and troubleshooting for blocked egress.
Error codes
Distinguishes ip_not_authorized from bad-key and other 401s.
Platform IP allowlist settings
Add IPs/CIDRs and enable allowlisting for a project or the organization.
RBAC / permissions
Org owners need IP allowlist Read/Write to change the list.
Open: 1 spot per week
One labeled sponsor for this topic each week; this week's spot is open. See open weeks →
All tools for “Fix OpenAI API 401 ip_not_authorized” →
Related fixes
- Stop a Cursor agent loopHow to fix a Cursor agent loop (same edit, or work after Stop)Fix →
- Claude Code vs Codex vs Cursor ~$20 plansClaude Code vs Codex vs Cursor $20 plan limits: how to pick without burning the weekFix →
- Scan a vibe-coded app for leaked API keysCheck a vibe-coded app for leaked API keys before you share itFix →
- Add an MCP server to Claude Code, Cursor, or CodexHow to add an MCP server to Claude Code, Cursor, or CodexFix →
See also AI tools launched today on the daily board.
NewAIToolsToday Daily
Top 3 AI launches, one model or news item that matters, and one simple fix. A 5-minute read, every weekday.