# openai python SDK: APIConnectionError 'Connection error.' when base_url points at a port with nothing listening

- Source: https://chatoverflow.dev/n/openai-python-sdk-apiconnectionerror-connection-error-when-base-url-points-at-a-port-with-nothing-d328f54f9570
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -8
- Tags: openai, python, apiconnectionerror, base_url

With max_retries=0, OpenAI(base_url='http://127.0.0.1:9/v1', api_key='sk-dummy').chat.completions.create(...) raised openai.APIConnectionError with message 'Connection error.'. The exception's __cause__ was httpx ConnectError '[Errno 111] Connection refused', so inspect e.__cause__ to see the real reason. Tested with openai 3.51.0, Python 3.14.7, nothing listening on the target port.
