Connection error

Hi! I want to get the base image for Ubuntu, but I’m running into a problem when trying to send a request through the AI ​​agent node I get exception.
FROM ubuntu:26.10
RUN apt update &&
apt upgrade -y &&
DEBIAN_FRONTEND=noninteractive apt install -y nodejs npm wget curl jq zip p7zip git &&
useradd node --home-dir /home/node &&
mkdir -p /home/node
WORKDIR /home/node
COPY . .
RUN npm install -g n8n@stable pm2 &&
RUN chown -R node: /home/node
USER node
ENTRYPOINT [“pm2”, “start”, “n8n”, “–no-daemon”]

Describe the problem/error/question

Connection error.
Error details
Other info
Node type
@n8n/n8n-nodes-langchain.agent
Node version
3.1 (Latest)
n8n version
2.31.6 (Self Hosted)
Time
26.07.2026, 00:55:05
Stack trace
NodeOperationError: Connection error. at /usr/local/lib/node_modules/n8n/node_modules/@n8n/n8n-nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/executeBatch.ts:118:11 at Array.forEach () at executeBatch (/usr/local/lib/node_modules/n8n/node_modules/@n8n/n8n-nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/executeBatch.ts:107:15) at ExecuteContext.toolsAgentExecute (/usr/local/lib/node_modules/n8n/node_modules/@n8n/n8n-nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/V3/execute.ts:93:8) at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/@n8n/n8n-nodes-langchain/nodes/agents/Agent/V3/AgentV3.node.ts:155:10) at WorkflowExecute.executeNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1081:8) at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1381:11) at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1854:27 at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2546:11
My litellm working fine, downgrade n8n not help me, downgrade node version from 3.1 to 2.2 not help me

Hi @Sergey_Smirnov Welcome!
“Connection error.” is the OpenAI client failing at the transport layer, so the request never reached litellm. That points at the Base URL in your chat model credential not being routable from inside the container: localhost and 127.0.0.1 there resolve to the n8n container itself, not to the host. Test the URL you set, from inside the container:

wget -qO- http://127.0.0.1:4000/v1/models

If that fails while litellm answers everywhere else, change the Base URL to something the container can reach. For litellm on the host, start the container with --add-host=host.docker.internal:host-gateway and use http://host.docker.internal:4000/v1. For litellm in another container, use its service name, http://litellm:4000/v1.

Hi @Anshul_Namdev !

N8n validate credentional on OpenAI Chat Model subnode. It is difficul to save wrong endpoint address. I undestend what any container have own loopback interface and check connectivity from container with curl before create this topic.

My pipline broken after migrate from alpine.

Original container

docker pull n8nio/n8n:stable
docker run --entrypoint=npm -it n8nio/n8n:stable list -g

/usr/local/lib
`-- n8n@2.31.6

Custom container

docker run --entrypoint=npm -it n8n list -g

(node:1) [DEP0169] DeprecationWarning: `url.parse()` behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.
(Use `node --trace-deprecation ...` to show where the warning was created)
/usr/local/lib
+-- n8n@2.31.6
`-- pm2@7.0.3

When I modify docker compose from CUSTOM image to ORIGINAL image + docker compose up n8n --force-recreate my pipline working fine without modification

  1. require use official nodejs setup `curl -fsSL https://deb.nodesource.com/setup_22.x | bash -`
  2. npm install -g n8n@stable pm2 --build-from-source (add -build-from-source)

An extra check that can narrow this down quickly: test the exact OpenAI-compatible calls from inside the n8n container, not only whether LiteLLM is reachable.

  1. Call <base-url>/v1/models with the same API key used by the chat-model credential.
  2. Call <base-url>/v1/chat/completions with a minimal request and the same model name.

If DNS/TCP fails, it is the Docker network or Base URL. A 404 usually means the Base URL/path is wrong; 401/403 points to the key; a TLS error points to the proxy/CA. If both calls work inside the container, enable LiteLLM request logging and compare whether n8n sends the expected model name and path.

The Base URL in n8n must be reachable from that container and match LiteLLM’s OpenAI-compatible /v1 endpoint; localhost only works if LiteLLM is in the same container.