API errors
Fix Midjourney API Error Codes (401, 403, 429, 500)
Updated 10/10/2026
Midjourney does not currently offer an official public developer API. Because of this, developers and teams use third-party API wrappers, custom Discord bot integrations, or browser-based SDKs to automate image generation. When these custom setups break, they return standard HTTP status codes like 401, 403, 429, or 500.
If your Midjourney integration is failing to process prompts or returning error payloads, follow these diagnostic and repair steps to restore functionality.
---
Understand the Integration Architecture Most unofficial Midjourney APIs and SDKs work by simulating a Discord user client. They connect to the Discord Gateway via WebSockets, send interaction payloads (representing `/imagine` commands), and listen for message updates to download the generated images. Knowing this helps pinpoint whether an error originates from your code, the proxy provider, Discord's gateway, or Midjourney's backend servers.
---
Step-by-Step Fixes for API Errors
1. Fix 401 Unauthorized and 403 Forbidden Errors These errors mean your request is failing authentication. Because there is no official API key, your integration relies on a Discord user token (often called a `user_token` or `salai_token`) and specific channel parameters.
- Check Token Validity: User tokens expire or change whenever you reset your Discord password, enable or disable Two-Factor Authentication (2FA), or if Discord flags the account for suspicious activity. Manually log into the Discord account via a browser, open DevTools (F12), inspect your Network tab, and grab the authorization token to confirm it matches your code configuration.
- Verify Channel and Server IDs: Ensure the channel_id and guild_id (server ID) in your API request match a channel where the authorized Discord account has explicit read, write, and application command permissions. If the bot account was kicked or lost permissions, you will receive a 403 Forbidden status.
- Accept Midjourney Terms: If you are using a new Discord account, manually log in and generate at least one image in the official Midjourney Discord server to accept the latest Terms of Service. Unaccepted terms block automated API calls.
2. Resolve 429 Rate Limit Exceeded Errors A 429 status code indicates your application is sending commands faster than Discord or Midjourney allows.
- Implement Exponential Backoff: Update your API request logic to respect the Retry-After header returned in the 429 response. If the header is missing, implement an exponential backoff algorithm (e.g., wait 2 seconds, then 4, then 8, then 16) before retrying.
- Track Active Jobs: Midjourney limits the number of concurrent active jobs per subscription tier (usually 3 fast jobs or up to 15 queued jobs). If your script floods the queue, the integration will fail. Implement a local database or queuing system (like Redis) to limit active jobs to 2 or 3 concurrently per token.
- Introduce Random Jitter: To prevent your automated scripts from triggering Discord's anti-bot detection, introduce a random delay (jitter) of 1 to 3 seconds between actions like button clicks, upscale requests, or prompt submissions.
3. Troubleshoot 500 Internal Server Errors and Timeouts A 500 error or gateway timeout (504) means the server processing the request crashed or took too long to respond.
- Decouple HTTP Requests from Generation Times: Midjourney image generation can take anywhere from 30 seconds to several minutes depending on the server load and whether you are using Fast or Relax mode. Never keep an HTTP request open waiting for the final image. Instead, use an asynchronous webhook architecture. Your API should send the prompt, receive an immediate acknowledgment (e.g., HTTP 202), and then wait for a webhook callback from your SDK when the image is complete.
- Check Discord API Status: Check the official status page for Discord (discordstatus.com). If the Discord gateway or interaction API is degraded, your Midjourney integration will fail with 500 or 504 errors.
4. Resolve SDK Integration and WebSocket Failures If your local library (such as Node.js or Python Midjourney wrappers) fails to connect or drops connection constantly, the issue is likely websocket-related.
- Enable WebSocket Heartbeats: Discord requires active WebSocket connections to send heartbeat packages. Ensure your SDK configuration has heartbeats enabled and that your server environment does not block outbound long-lived TCP/WebSocket connections.
- Update Dependencies: Because unofficial SDKs rely on scraping or mimicking Discord's private API payload formats, any small change by Discord can break the SDK. Run npm update or pip install --upgrade on your Midjourney package to apply the latest community fixes.
---