curl SSL_ERROR_SYSCALL: Fixing TLS Handshake Failures on AI APIs
curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL means the TCP connection was established, but the underlying connection was closed before the TLS handshake finished, and OpenSSL got no TLS-level error to report. By itself it does not point to a specific cause. It only says "the connection dropped during the handshake." To troubleshoot, first confirm the server is healthy, then use the error text to decide whether the culprit is a proxy, MTU, a middlebox, or your local environment.
Below, errors are split into four classes by their message text. Each comes with commands you can run directly and the reasoning for interpreting the results. The scenarios focus on calling AI model APIs.
Spend one minute first: is it the server?
A TLS handshake failure is not necessarily your network. Official API endpoints have occasional problems, and so do CDN nodes. Before changing local configuration, check two places:
- API status page: cdnping probes each vendor's official API endpoint from the Cloudflare edge every 5 minutes, syncs the official status pages of OpenAI, Anthropic, Moonshot, Groq, Cloudflare and others every 15 minutes, and keeps 30 days of history.
- Is it down?: combines official status, API probes and user reports. For Claude, for example, go straight to /en/down/claude.
For example, in cdnping's edge probe snapshot from 2026-10-17 (Cloudflare DEN node, collection had just started, window of about 85 minutes, 242 probes in total), the OpenAI, Claude and Gemini endpoints were all reachable, and the Kimi open platform's availability was recorded as 94.4%. That only means "reachable from an edge node in the US". It does not mean your own network can reach them. Conversely, if the status is already red here, there is no need to change local configuration first.
Check Cloudflare's own status page too. Many AI services sit behind Cloudflare, and when a Cloudflare node has problems, handshake failures show up in clusters. Among the Cloudflare official incidents cdnping syncs, there was one on 2026-10-10 titled "Elevated Errors in China Network Colos" (severity minor) that lasted about 5 days. When you see widespread handshake failures, check the status page for a similar incident.
The reasoning is covered in more detail in Is ChatGPT down? Three steps to tell a service outage from your own network problem.
Which class does my error belong to?
Copy the full error text and match it against this table:
| Error text (common forms) | Class | Meaning |
|---|---|---|
SSL_ERROR_SYSCALL, Connection reset by peer, unexpected eof while reading | A. Connection closed mid-handshake | The peer or a middlebox closed the connection halfway through the handshake |
SSL connection timeout, TLS handshake timeout, Operation timed out stuck after Client Hello | B. Handshake packets never came back | Packets went out, and the reply was lost on the way |
certificate has expired, certificate is not yet valid, unable to get local issuer certificate, no alternative certificate subject name matches | C. Certificate validation failed | The handshake completed, but your machine does not trust the peer's certificate |
wrong version number, unsupported protocol, tlsv1 alert protocol version, ERR_SSL_PROTOCOL_ERROR in the browser | D. Protocol or format mismatch | The two sides are not speaking the same "language" |
Classes A and B are the hardest to debug because the error message carries almost no clues. For C and D, the message already explains most of the cause.
Step 1: use curl -v to see where it gets stuck
curl -v https://api.openai.com/v1/models -o /dev/null
Read the -v output in order:
Connected toafterTrying x.x.x.x:443...: DNS and TCP both worked.TLSv1.3 (OUT), TLS handshake, Client hello (1): the client sent its Client Hello.TLSv1.3 (IN), TLS handshake, Server hello (2): the server responded.- After that come the certificate,
SSL connection using TLSv1.3, and the HTTP request.
The line where it stops tells you which direction to investigate:
- Stuck at
Trying: you have not reached TLS yet. This is a DNS or TCP layer problem. See How to tell DNS pollution from DNS hijacking. SSL_ERROR_SYSCALLright after the Client Hello goes out: class A.- No response for a long time after the Client Hello, then a timeout: class B.
- Error after the Server Hello and certificate: class C or D.
Also look at the address after Connected to. If it is a local port such as 127.0.0.1:7890, the request went through a proxy, and the thing to troubleshoot is the proxy, not the target server.
Step 2: test the handshake on its own with openssl s_client
curl, Python's requests and Node's fetch each read their own proxy variables and certificate settings. openssl s_client reads none of those, so you can use it to test a "bare" handshake:
openssl s_client -connect api.anthropic.com:443 -servername api.anthropic.com -brief </dev/null
-servername is required. Most API endpoints today sit behind a CDN, with many domains on the same IP. Without SNI, the server does not know which certificate to present, and some simply drop the connection, which looks exactly like SSL_ERROR_SYSCALL.
On success it prints the protocol version, the cipher suite and the certificate subject. Then pin the protocol version explicitly:
openssl s_client -connect api.anthropic.com:443 -servername api.anthropic.com -tls1_2 -brief </dev/null
openssl s_client -connect api.anthropic.com:443 -servername api.anthropic.com -tls1_3 -brief </dev/null
The equivalent curl commands:
curl -v --tlsv1.2 --tls-max 1.2 https://api.anthropic.com -o /dev/null
curl -v --tlsv1.3 https://api.anthropic.com -o /dev/null
How to read the results:
- s_client works but curl does not: the problem is in application-level configuration, most likely proxy variables or certificate variables.
- Neither works, but another network (a phone hotspot, say) does: the problem is on the network path you are on.
- Only TLS 1.3 fails while TLS 1.2 works: a device on the path does not understand TLS 1.3 or its extensions, which is common with old corporate firewalls.
- Neither works, even on another network: go back to /en/status and check the server side.
Class A: SSL_ERROR_SYSCALL and unexpected eof
OpenSSL 3.x reports a peer that disconnects without sending close_notify as unexpected eof while reading. Older versions report SSL_ERROR_SYSCALL, sometimes with errno 104 (Connection reset) or errno 0. They are essentially the same thing.
Is the proxy misconfigured?
When calling AI APIs, proxy configuration is a common source. Check the environment variables first:
env | grep -i -E '^(https?|all|no)_proxy='
Common problems:
- The proxy client is not running or its port changed, but
HTTPS_PROXYstill points to the old port. - When handling CONNECT, the proxy software rejects or drops a given domain according to its rules.
- The proxy node's own connection to the target site is unstable.
To verify, temporarily bypass the proxy and try again (for locating the problem only):
curl -v --noproxy '*' https://api.openai.com -o /dev/null
If the result changes, investigate the proxy. Tools read proxy variables in different ways. For Claude Code, see Claude Code proxy settings not taking effect: checking HTTPS_PROXY, NO_PROXY and certificate variables one by one.
Is a middlebox actively resetting the connection?
The SNI in the handshake is plaintext, so a device on the path can send an RST based on the domain name alone. The symptoms: Connected to appears quickly, the connection drops almost immediately after the Client Hello, s_client gives the same result, and testing a different domain on the same IP works fine. In this situation, what you can do is confirm the behavior, compare against another network path, and comply with the terms of the service you use and local regulations.
Was an idle connection reclaimed?
If the error does not appear on the first request but after the program has been running for a while, a long-lived connection in the pool may have been reclaimed by NAT or a proxy, so the next reuse fails during the handshake or on read/write. Set a shorter idle timeout on the client, or retry these errors a limited number of times. For how to write retries, see How to write LLM API retries: exponential backoff with jitter, retry budgets, and which errors must never be retried. If a Codex stream is cut off midway, see Codex "stream disconnected before completion", which separates proxy, certificate and WSL causes.
Class B: TLS handshake timeout, handshake packets never came back
The pattern here: the TCP three-way handshake succeeds, the small Client Hello goes out, but the server's reply (Server Hello plus the certificate chain) is several KB, gets split into full-size packets, and those are dropped along the way.
Is it an MTU black hole?
Tunnels, PPPoE and virtual NICs all reduce the path MTU. If a hop in the middle drops large packets without returning ICMP, the large packets vanish and the handshake can only wait until it times out. How to check (Linux):
# 1472 + 28 bytes of headers = 1500; reduce step by step until it passes
ping -M do -s 1472 api.openai.com
ping -M do -s 1400 api.openai.com
On macOS use ping -D -s 1472, on Windows ping -f -l 1472. Note that many API endpoints do not answer ICMP, so you can first measure the path MTU against another pingable host on the same network.
If 1472 fails and 1400 works, temporarily lower the MTU of the local or tunnel interface and retry curl (it resets on reboot; replace the interface name with yours):
sudo ip link set dev eth0 mtu 1400
For the full diagnosis and fix, see What MTU should I use? Troubleshooting large-packet black holes that hang HTTPS and time out API requests.
Is the IPv6 path broken?
In a dual-stack environment the client may prefer IPv6, and IPv6 path problems differ from IPv4 ones. Force each one separately:
curl -4 -v https://api.openai.com -o /dev/null
curl -6 -v https://api.openai.com -o /dev/null
If only one side times out, you know where to look. You can see your current IPv4 and IPv6 egress addresses together in IP & environment check. For problems caused by mismatched egress addresses, see IPv6 proxy not working: why IPv4 and IPv6 egress differ on dual-stack networks, and how to troubleshoot.
Class C: certificate errors
The text of a certificate error usually already states the cause. Match it against this table:
| Error | What to check first | Command |
|---|---|---|
certificate is not yet valid or has expired (while the peer's certificate has not actually expired) | System time | date -u, compare with the real UTC time |
unable to get local issuer certificate | The CA bundle, or a proxy doing HTTPS decryption | openssl s_client ... -showcerts to see the issuer |
no alternative certificate subject name matches | SNI, or DNS resolving to the wrong IP | dig +short <domain> to compare, and check the hosts file |
self signed certificate in certificate chain | A corporate gateway or security software replaced the certificate | Check whether the issuer is a company or software name |
If the issuer is a corporate gateway or local security software, the right fix is to add that root certificate to the tool's trust list (for Node, NODE_EXTRA_CA_CERTS), not to disable certificate verification. curl -k is only for temporarily confirming the problem and must never go into a script.
Clock problems are easy to overlook: resuming a suspended VM, WSL clock drift, or a dead motherboard battery can push the system time off, and suddenly certificates are "not yet valid" or "expired".
Class D: protocol version and format mismatches
wrong version number
The most common cause: you are speaking TLS to a port that expects plaintext HTTP. For example:
HTTPS_PROXYis set tohttps://127.0.0.1:7890, while the local proxy port only accepts the plaintext HTTP proxy protocol. It should normally behttp://127.0.0.1:7890; the traffic inside the CONNECT tunnel is still encrypted.- The API address is written as
https://host:80, or TLS is not enabled on that port of a self-hosted gateway.
unsupported protocol / protocol version alert
The client and server share no supported TLS version. Check your local OpenSSL versions first:
openssl version
curl -V | head -1
python3 -c "import ssl; print(ssl.OPENSSL_VERSION)"
Mainstream API endpoints require TLS 1.2 or higher. Very old OpenSSL or Python, and the curl bundled with old operating systems, can hit this problem. The three commands may disagree because they may link against different libraries.
ERR_SSL_PROTOCOL_ERROR in the browser
This browser error corresponds to situations similar to the ones above. Rule out browser extensions and the system proxy first, then reproduce it on the command line with the curl commands above. If, in the online speed test, the "first connection" for one API keeps failing while other targets are fine, that result can serve as a comparison: the first-connection metric itself includes DNS and the TLS handshake.
A troubleshooting order you can follow
- Open /en/status and /en/down and confirm there are no ongoing incidents on the server side or at Cloudflare.
- Run
curl -vand note which line it stops at, and whether it connected to the target IP or a local proxy port. - Run
env | grep -i proxyand confirm the proxy variables point to the right place and use thehttp://scheme. - Test the bare handshake with
openssl s_client -connect <domain>:443 -servername <domain>and compare with the curl result. - Add
-tls1_2and-tls1_3, and curl's-4and-6, to narrow it down. - For handshake timeouts, test MTU; for certificate errors, check
date -uand the certificate issuer. - Repeat step 2 on a different network (a phone hotspot) to decide whether the problem is on the network path or on your machine.
Record the command and output of each step so you can attach them when you contact a network administrator or the service provider. For the full four-layer network checking approach, see How to troubleshoot Claude Code connection timeouts and errors: a four-layer network checklist.