Tickd.ai
API errors

Fix Midjourney API Connection Refused Error

Updated 10/5/2026

Why Are You Getting "Connection Refused"?

When building integrations or using third-party wrapper APIs to interface with Midjourney, running into a Connection Refused (ECONNREFUSED) or a socket hang-up error is a common roadblock. Because Midjourney does not offer an official public REST API, developers rely either on the Discord Gateway API to interact with the Midjourney bot or on downstream third-party API providers.

A connection refused error means your client application attempted to establish a TCP connection to the destination server, but the server rejected it. This guide covers how to diagnose and resolve these network, DNS, and proxy issues.

---

Step 1: Verify the Endpoint and Port Configurations

Incorrect port bindings or outdated protocol prefixes are the most common culprits for immediate connection rejections.

1. Check the Protocol: Ensure you are using https:// for REST requests and wss:// (WebSocket Secure) for Discord Gateway connections. Using http:// or ws:// will result in an immediate drop by modern security firewalls. 2. Check Port Bindings: If you are running an API proxy locally (e.g., via Docker), ensure your container's internal port matches your host port. For example, if your configuration file points to localhost:8080, verify that your local service is actively listening on that port using: `bash netstat -an | grep 8080 ` 3. Ping the Host: Run a traceroute or ping to ensure the target API host is reachable from your current network environment: `bash curl -I https://discord.com/api/v10 `

---

Step 2: Check for Cloudflare and WAF Blocks

Both Discord and third-party Midjourney API providers rely heavily on Cloudflare, Akamai, or similar Web Application Firewalls (WAF) to prevent DDoS attacks and scraping.

  1. Identify the HTTP Status Code: If your connection is refused but returns a headers payload, look for an HTTP 403 Forbidden or a Cloudflare 1020 error page. This indicates your IP address has been flagged or rate-limited.
  2. Switch to a Dedicated IP: Shared hosting environments, public VPNs, and cheap VPS providers (like AWS EC2 or DigitalOcean basic droplets) often use dirty IP ranges that are blocked by default. Route your API traffic through a dedicated residential proxy or a reputable VPN with static IPs.
  3. Configure Custom Headers: Ensure your request headers include a valid User-Agent. Bare-bones HTTP libraries (like raw curl or default node-fetch instances) that do not send a browser-like User-Agent are often blocked automatically.

---

Step 3: Resolve DNS Resolution and IPv6 Issues

Sometimes, your server may attempt to connect to the target API via IPv6, while the target server or your local network interface only supports IPv4 (or vice versa), leading to a silent refusal.

1. Force IPv4 Resolution: If your programming language's HTTP client supports it, force the connection to resolve using IPv4. For example, in Node.js, you can configure the DNS lookup family: `javascript dns.setDefaultResultOrder('ipv4first'); ` 2. Flush Your DNS Cache: Corrupted local DNS records can route your requests to defunct IP addresses. Flush the cache on your deployment server: * Linux (systemd-resolved): sudo resolvectl flush-caches * macOS: sudo killall -HUP mDNSResponder 3. Use Public DNS Resolvers: Switch your server’s /etc/resolv.conf to use Google DNS (8.8.8.8) or Cloudflare DNS (1.1.1.1) instead of your hosting provider's default local resolver.

---

Step 4: Fix Discord Gateway WebSocket Handshake Failures

If you are interacting with Midjourney via a Discord bot library (such as Discord.js or Discord.py), connection refusals often point to a failed WebSocket handshake.

  1. Update Your SDK: Discord frequently deprecates older API and Gateway versions. If your library is attempting to connect to Gateway v6 or v8, Discord will refuse the connection. Update your library to the latest version supporting Gateway v10.
  2. Verify Gateway Intents: Ensure your client bot has enabled the necessary privileged gateway intents (specifically Guild Messages and Message Content) in both your code configuration and the Discord Developer Portal.
  3. Handle Sharding Correctly: If your bot is in more than 2,500 guilds, Discord will refuse non-sharded gateway connections. Ensure your codebase implements proper sharding mechanisms.

---

Step 5: Check Third-Party API Provider Status

If you are utilizing an unofficial, downstream Midjourney API provider, the issue is likely on their side.

  1. Check Status Pages: Visit the external API provider's dedicated status page to see if they are experiencing a partial or full outage.
  2. Verify API Versioning: Some providers deprecate older endpoints without backward compatibility, leading to 404 errors or outright connection drops on deprecated domains.

---

When to Escalate

If you have verified your network routing, confirmed that your IP is not blacklisted, and updated your SDKs, but you still cannot connect: * For Discord-based integrations: Check the [Discord Status Page](https://discordstatus.com/) to see if the API gateway or media delivery networks are experiencing system-wide degradation. * For Third-Party APIs: Contact the specific support channel of your API provider with your server's outbound IP address, request payload, and full console error stack trace.

While you're here

Tickd is more than troubleshooting — these three are free and take seconds.

Agent BuilderDesign your own AI agent and export it to ChatGPT, Claude, Gemini or Grok.Build one free