OpenAI Python SDK stream hangs on base_url switch A developer published a diagnostic guide for debugging OpenAI Python SDK streaming failures that appear after switching base_url, arguing that a working blocking call proves the API contract but not the transport. The guide provides a runnable probe that prints time-to-first-token, chunk count and token usage, plus fixes for three concrete failures: stale OPENAI_BASE_URL environment variables, CDN-buffered apex hostnames versus direct api subdomains, and usage blocks arriving in a separate event with an empty choices array. You repointed the OpenAI Python SDK at a new base url. The blocking call returns fine, so the key and the network are proven. The streaming call hangs, truncates halfway, or dies with IndexError: list index out of range on what looks like the last event. This article is a diagnosis order rather than a list of tips: confirm which host you are actually hitting, prove the transport is not buffering, guard the usage block whether it arrives on the finish chunk or in its own event with an empty choices array, and separate SDK-level retries from your own. It ships one runnable probe that prints time-to-first-token, chunk count and token usage, three concrete failures with exact fixes, and the checks that only apply behind a gateway. Swapping base url changes four things at once, and only one of them is a hostname. The request path stays /v1/chat/completions , but the machinery behind it — TLS terminator, HTTP server, ingress, proxy, the model provider's own edge — is a different stack with different buffering defaults, different idle timeouts and a different error envelope. When the blocking call works and the streaming call does not, you have almost certainly proved the contract and broken the transport . Treat those as separate problems from the first minute, or you will spend an afternoon tuning the SDK for a bug sitting in an nginx config two hops away. Two environment variables bite here more than anything in the code. The Python SDK reads OPENAI API KEY and OPENAI BASE URL from the environment when you do not pass them explicitly. A stale export OPENAI BASE URL=https://api.openai.com/v1 in a shell profile will silently win, your key will be sent to the wrong service, and the 401 will look like a key problem. Print the resolved values before you debug anything else. python import os print "key set:", bool os.environ.get "MODELRY API KEY" print "OPENAI BASE URL env:", os.environ.get "OPENAI BASE URL", "