next/image optimizer has to be swapped for a custom loader before Brandfetch logos will load.
If you would rather install ready-made components, the shadcn/ui registry adds a logo, a company search, a logo wall, and a brand card to your project with one command.
Add your credentials
Put both credentials in.env.local. The client ID carries the NEXT_PUBLIC_ prefix because the browser needs it, while the API key has no prefix, so Next.js keeps it on the server and never ships it in the client bundle:
.env.local
Show a logo with next/image
By default,next/image downloads every remote image on your server, resizes it, and serves the copy from /_next/image. The Logo API treats that server-side download as programmatic access and answers it with an automated_traffic redirect instead of the logo, and serving the resized copy from your own domain would also count as re-hosting, which the caching rules don’t allow.
A custom loader fixes both problems. It tells next/image to build each image URL itself, so the browser requests the logo straight from Brandfetch’s CDN, and the CDN does the resizing through the w and h options. You keep the lazy loading, the srcset, and the layout-shift protection that next/image gives you:
components/company-logo.tsx
app/customers/page.tsx
"use client" because a loader is a function, and Next.js can’t pass a function from a Server Component to next/image. You don’t need to add cdn.brandfetch.io to images.remotePatterns either, since that list only applies to images the optimizer downloads, and with a loader it downloads nothing.
The loader above asks for the square icon with a lettermark when a brand has no icon. To show the full horizontal logo instead, end the URL with /logo instead of /icon, and drop the h option so the logo keeps its proportions. Every option is listed in Logo API parameters.
Or use a plain img tag
If you don’t need responsive sizes, a plain<img> tag works in any component, server or client, with no configuration at all. Ask for twice the display size so the logo stays sharp on high-density screens:
<img> with the @next/next/no-img-element rule, which you can turn off for this line. Setting unoptimized on next/image has the same effect as a plain tag, if you’d rather keep the component.
Whichever you choose, leave the browser’s default referrer policy in place. The Logo API needs the Referer header to know which site is showing the logo, so a Referrer-Policy: no-referrer set in next.config.js or in middleware stops logos from loading. The usage guidelines list the policies that work.
Add a company autocomplete
Users type company names rather than domains, so a company field needs the Brand Search API to turn what they type into a domain. It uses the same public client ID, so the request runs in the browser. Debounce it to stay well inside the rate limits, and keep only the domain the user picks:components/company-search.tsx
brand-search component.
Fetch brand data on the server
Colors, fonts, downloadable logo files, and company details come from the Brand API, which needs the secret API key, so call it only from server code. Keeping the call in one module that importsserver-only makes the build fail if a client component ever imports it by mistake:
lib/brandfetch.ts
revalidate option refreshes each response in the Next.js data cache after seven days, so repeat visits don’t use a credit. It isn’t a hard expiry, though, because Next.js keeps serving the old response while it refreshes, keeps it when a refresh fails, and doesn’t delete entries nobody requests. Since Brand API data can be cached for 30 days at most, store brands in your own database with an expiry or a scheduled cleanup when you need to guarantee that limit. You can install the server-only package with npm install server-only.
A Server Component can then render brand data directly, without any client-side request:
app/brands/[domain]/page.tsx
app/api/brand/[domain]/route.ts
brandfetch.com as the domain, because lookups for it are free on the Brand API. When a request fails, the x-bf-error header names the reason with a stable code, such as quota_exceeded or domain_unresolvable, and errors explains what to do about each one.
Prompt for coding agents
If you build with Cursor, Claude Code, or another coding agent, paste this prompt so it follows the same rules:FAQ
Why don't Brandfetch logos load with next/image?
Why don't Brandfetch logos load with next/image?
The default
next/image optimizer downloads images on your server, and the Logo API redirects server-side requests with automated_traffic instead of returning the logo. Add a custom loader that returns the Brandfetch URL, or set unoptimized, so the browser loads the logo directly from the CDN.Do I need to add cdn.brandfetch.io to remotePatterns?
Do I need to add cdn.brandfetch.io to remotePatterns?
No. The
images.remotePatterns list only applies to images that the Next.js optimizer downloads, and with a custom loader or unoptimized it doesn’t download Brandfetch images at all.Can the API key use the NEXT_PUBLIC_ prefix?
Can the API key use the NEXT_PUBLIC_ prefix?
No. Anything prefixed with
NEXT_PUBLIC_ is bundled into the JavaScript that ships to the browser, where anyone can read it. Only the client ID belongs there, and the API key should stay in a server-only module.Can I cache Brandfetch logos in Next.js?
Can I cache Brandfetch logos in Next.js?
Logo API images must be hotlinked from the CDN, so don’t download or store them, although the browser cache handles repeat views on its own. Brand API responses, including the logo files they link to, can be cached for up to 30 days, which the
revalidate option above already does. See caching.Does this work with the Pages Router?
Does this work with the Pages Router?
Yes. The
CompanyLogo and CompanySearch components work as they are, because the Pages Router simply ignores the "use client" line. Call getBrand from getServerSideProps, getStaticProps, or an API route under pages/api after removing its import "server-only" line, which only works in the App Router, and use revalidate in getStaticProps instead of the fetch option.Related
shadcn/ui components
Ready-made logo, search, logo wall, and brand card components for React.
Company autocomplete
A complete company field, from the first keystroke to the saved domain.
Logo API parameters
Sizes, themes, fallbacks, and logo types for every image URL.
Caching
What you can store from each API, and for how long.