Web Development 6 min read Practical Guide

Next.js Image 400 Bad Request: remotePatterns and Quality Fixes

Ukasha Altaf

Software Developer & Digital Tools Creator

Published: 2026-10-28
A laptop browser image placeholder passing through three precise configuration gates into a clear landscape image tile

At a glance

Check the failed optimiser response, the original image, remotePatterns, query strings and quality settings separately. A 400 response does not automatically mean the hostname is wrong.

When a source image opens normally but the page shows a broken thumbnail, adding another hostname to next.config may not solve the problem. The failing request might be the image optimiser, the source server, or a quality setting introduced during an upgrade.

This guide separates those cases. It covers the built-in Next.js image optimiser and uses fictional example domains. If the source URL itself returns 404, start with the public image path guide instead.

1. Identify which request returned 400

Open the browser's Network panel, reload the page and select the failed image request. Record its status, response body and URL. Do not diagnose from the broken-image icon alone.

A request to /_next/image is different from a request directly to your storage host. The optimiser URL usually carries three useful parameters:

  • url: the original image location, encoded inside the request.
  • w: the requested output width.
  • q: the requested quality.

Copy the complete request into a private debugging note. Signed URLs may contain access tokens; remove those before posting a screenshot or asking for public help.

2. Open the original image, not just the optimiser URL

Decode the url parameter and request that source directly. Check the response body and Content-Type. A successful HTTP status with an HTML login page is still not a usable image response. Also check access without your signed-in browser session: the default optimiser does not simply forward your browser authentication headers to the source.

Imagine the browser requests /_next/image for a customer avatar. The avatar URL redirects to a sign-in page after the session expires. Enlarging your allowlist will not turn that page into an image. Fix the source's access design first.

Vercel's INVALID_IMAGE_OPTIMIZE_REQUEST reference identifies invalid widths, qualities and non-image responses among the causes. Its troubleshooting page is especially useful when that exact error code appears on a Vercel deployment.

3. Match the actual remote URL

For a source such as https://images.example.com/uploads/team/avatar.jpg, a deliberately narrow configuration is:

import type { NextConfig } from 'next';

const nextConfig: NextConfig = {
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'images.example.com',
        port: '',
        pathname: '/uploads/**',
        search: '',
      },
    ],
  },
};

export default nextConfig;

Replace the fictional domain and path with the service you control or intend to trust. Restart the development server after changing configuration, and build a new deployment for production.

The unconfigured-host guide explains the matching fields. Compare the failing URL with the rule character by character. A different subdomain, protocol or path prefix is a different request.

Avoid changing the hostname to a catch-all merely to make the error disappear. You need to know which source should be accepted before broadening access.

4. Check the query string you accidentally excluded

The previous rule intentionally allows no query string. It therefore does not fit a source ending in ?v=2. If your service uses one known query, you can permit that exact search value. If it uses changing signed parameters, you must choose a rule appropriate to that service rather than copying an empty search value.

The important distinction is between an omitted search property and search set to an empty string. They express different policies. The URL-object shorthand can also produce an empty search when its URL contains no query. Check the resulting rule, not only how concise the configuration looks.

Keep the hostname and path narrow when allowing variable queries. Ask whether those query parameters identify a legitimate image, grant temporary access, or let someone request unrelated resources. An allowlist decision should follow that answer.

For local image sources, inspect images.localPatterns too. Next.js 16 requires suitable local query-string configuration: a route such as /api/avatar?id=12 is not the same input as a plain /avatar.jpg. Consult the Image component reference for the matching behaviour supported by your installed version.

5. Check quality and width after an upgrade

Next.js 16 restricts optimisation qualities to an allowlist and uses 75 as the default allowed quality. Distinguish a direct optimiser request from the Image component: a direct request for a disallowed q value returns 400, while the component can select the nearest allowed quality. Inspect the actual generated request before blaming its quality prop. If you intentionally need both 75 and 90, the relevant portion of configuration can be:

images: {
  qualities: [75, 90],
}

Merge that property with your existing image settings; do not replace the whole configuration and lose remotePatterns. See the version 16 upgrade guide for version-specific changes.

When examining a direct optimiser request, compare w with the configured deviceSizes and imageSizes. Do not manufacture arbitrary optimiser URLs as a permanent workaround. Let the Image component generate its requests and investigate why the generated request is being refused.

A useful check is to remove a custom quality temporarily and reproduce the issue. If the source and remote rule remain unchanged but the error disappears, you have narrowed the investigation. Restore only a quality setting that your configuration supports.

6. Explain “works locally” with evidence

Keep the exact local and production inputs beside each other: image source, configuration revision, framework version and response. Common differences include a source URL that contains a production-only query, a configuration file not included in the deployed revision, or an image server that cannot be reached from the deployment.

If all matching fields look correct, inspect the deployment logs and current framework documentation rather than weakening network safeguards. A reachable public hostname and a hostname that resolves to a private network address are different cases.

Using unoptimised delivery can help identify which layer is failing, but it changes the delivery path and has performance implications. It should not be labelled a universal fix for an unexplained error.

A final verification pass

After the change, test the original failing article or avatar with the same source URL. Confirm a successful image response, correct appearance and no recurring console error. Also check that an intentionally disallowed host or path is still rejected.

Try one narrow viewport and a wider viewport so different generated widths are exercised. Repeat against the deployment rather than treating a successful development request as proof of production behaviour.

If the image now loads but a social preview is still missing, continue with the Open Graph image checklist. It addresses metadata and sharing caches, which are a separate path from the image optimiser.

Questions readers often ask

Does a 400 always mean remotePatterns is wrong?

No. Check the failing response and source first. The request may violate a quality or width rule, or the upstream resource may not be an image.

Should I allow every external hostname?

Use a rule for the source your application needs. A broad wildcard hides which boundary was wrong and may permit unrelated image requests.

Why did adding search: '' break my image?

An empty search permits no query string. Compare it with the actual source, especially signed URLs and version parameters.

Is this the same as a missing file in public?

No. A missing source file normally needs a path or deployment fix. Establish whether the source fails directly or only through /_next/image before choosing the next step.

Relevant Free Tool

Try our QR Code Generator

Create clean, scannable QR codes for testing websites, URLs, and client handoffs.

Launch Tool
Ukasha Altaf
Written by

Ukasha Altaf

Software Developer & Digital Tools Creator

Founder of Ukasha Mart. Building free, accessible browser-based utilities and writing in-depth tutorials on modern technology, freelancing, and practical online work.

Chat on WhatsApp
Next.js Image 400 Bad Request: remotePatterns and Quality Fixes | Ukasha Mart