# Error: Some(api) is not a valid language code

**URL:** <https://community.prismic.io/t/error-some-api-is-not-a-valid-language-code/17803>\
**Category:** Developing with Prismic\
**Tags:** nextjs, localization\
**Created:** [October 12, 2024, 3:59pm UTC](https://community.prismic.io/t/error-some-api-is-not-a-valid-language-code/17803 "2024-10-12T15:59:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anasr](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@anasr](https://community.prismic.io/u/anasr)\
**Post date:** [October 12, 2024, 3:59pm UTC](https://community.prismic.io/t/error-some-api-is-not-a-valid-language-code/17803/1 "2024-10-12T15:59:40Z")

</div>

## Describe your question/issue in detail

I implemented internationalization in Prismic following [this](https://prismic.io/blog/nextjs-i18n) guide, and everything is working fine except for one issue. When I navigate to any route that starts with a prefix listed in the matcher array, I encounter an application error in production, and in development, I'm seeing the following error:

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/2X/1/11b70bdf2e7cedf5bef994c162d5fac8f320b6f1.jpeg)

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/2X/1/11f2cac92de85b29cee7af24c7bc2fae315b11bd.jpeg)

### middleware.ts file

```auto
import { NextRequest, NextResponse } from "next/server";
import { prismicClient } from "@/lib/prismic";

export async function middleware(request: NextRequest) {
  const repository = await prismicClient.getRepository();
  const locales = repository.languages.map((lang) => lang.id);
  const defaultLocale = repository.languages.find((lang) => lang.is_master);

  // Check if there is any supported locale in the pathname
  const { pathname } = request.nextUrl;

  const pathnameIsMissingLocale = locales.every(
    (locale) => !pathname.startsWith(`/${locale}/`) && pathname !== `/${locale}`
  );

  // Redirect to default locale if there is no supported locale prefix
  if (pathnameIsMissingLocale) {
    return NextResponse.rewrite(
      new URL(`/${defaultLocale.id}${pathname}`, request.url)
    );
  }
}

export const config = {
  matcher: [
    /*
     * Match all request paths except for the ones starting with:
     * - api (API routes)
     * - _next/static (static files)
     * - _next/image (image optimization files)
     * - favicon.ico (favicon file)
     * - robots.txt (robots file)
     */
    "/((?!api|_next/static|_next/image|favicon.ico|slice-simulator|icon.svg|robots.txt|sitemap.xml).*)",
  ],
};

```

### Prismic project

[https://adamdotai-website-v4.prismic.io/masks/](https://adamdotai-website-v4.prismic.io/masks/)

### Working website

> **[Home | adam.ai](https://adamdotai.vercel.app/)**
>
> adam.ai is an intelligent all-in-one meeting management platform to capture, manage, and share knowledge before, during, and after meetings, transform content into valuable assets, and drive successful business outcomes.

### Steps to reproduce

Enter any URL like the following examples:

[https://adamdotai.vercel.app/api-sdfsdfsd](https://adamdotai.vercel.app/api-sdfsdfsd)  
[https://adamdotai.vercel.app/apisdfsdfsd](https://adamdotai.vercel.app/apisdfsdfsd)

[https://adamdotai.vercel.app/sitemap.xml](https://adamdotai.vercel.app/sitemap.xml)  
[https://adamdotai.vercel.app/robots.txt](https://adamdotai.vercel.app/robots.txt)

[https://adamdotai.vercel.app/favicon.ico](https://adamdotai.vercel.app/favicon.ico)  
[https://adamdotai.vercel.app/favicon.icosfsg](https://adamdotai.vercel.app/favicon.icosfsg)

---

<div class="post-metadata">

**Author:** ![Ezekiel](https://avatars.discourse-cdn.com/v4/letter/e/848f3c/32.png) [@Ezekiel](https://community.prismic.io/u/Ezekiel)\
**Post date:** [October 14, 2024, 8:45am UTC](https://community.prismic.io/t/error-some-api-is-not-a-valid-language-code/17803/3 "2024-10-14T08:45:28Z")

</div>

Hi @anasr,

Welcome to the community!

Thank you for the details of your code.

I think your matcher may not be working the way you intend it to - as is, the pages/routes that will be excluded have to match exactly what you've included here: `"/((?!api|_next/static|_next/image|favicon.ico|slice-simulator|icon.svg|robots.txt|sitemap.xml).*)"`, which would explain why `/apidf`, or `/favicon.icosfsg` (or anything else that starts with what you've put in the matcher and continues) returns an error.

To fix it, you'd have to add `[^/]*` in your regular expression to include the paths that start with these patterns and are followed by additional segments. Like this: `/((?!api[^/]*|_next/static|_next/image|favicon[^/]*|slice-simulator|icon.svg|robots.txt|sitemap.xml).*)`

`/robots.txt` works as intended for me. Can you confirm this?

`/api` and `/sitemap.xml` seem to have different issues.  
For `sitemap.xml`, make sure this file actually exists and is accessible in the expected location. Are you using a specific tool or plugin to generate it?  
For `/api`, do you have a route that matches this? What does your file structure look like?

Let me know how this goes and if you have any updates after trying this 🙂
