# PrismicError: An invalid API response was returned

**URL:** <https://community.prismic.io/t/prismicerror-an-invalid-api-response-was-returned/13563>\
**Category:** Developing with Prismic\
**Tags:** nextjs\
**Created:** [July 3, 2023, 4:30pm UTC](https://community.prismic.io/t/prismicerror-an-invalid-api-response-was-returned/13563 "2023-07-03T16:30:32Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![nunopereirasousa00](https://avatars.discourse-cdn.com/v4/letter/n/9dc877/32.png) [@nunopereirasousa00](https://community.prismic.io/u/nunopereirasousa00)\
**Post date:** [July 3, 2023, 4:30pm UTC](https://community.prismic.io/t/prismicerror-an-invalid-api-response-was-returned/13563/1 "2023-07-03T16:30:32Z")

</div>

Hello! Since Friday from last week I have been getting an error due to "An invalid API response was returned".  
With this error it is not possible to build the website.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/2X/b/bfc6c2fca5a067ca7718802543f2ba5b7713ddf2.png)

I also saw that the slice-machine version for this project was old so I updated it. The "sm.json" file was deprecated so when I updated the slice-machine package to the latest version the "slicemachine.config.json" file was created successfully, but as a consequence of this update I lost a good amount of slices... The slice-machine localhost does not detect some slices after this update, even though, I can still see them and their corresponding "model.json" file in my code base.

Any further help with this problems would be greatly appreciated.

Thank you in advance,  
Nuno

---

<div class="post-metadata">

**Author:** ![nf\_mastroianni](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/nf_mastroianni/32/7071_2.png) [@nf\_mastroianni](https://community.prismic.io/u/nf_mastroianni)\
**Post date:** [July 4, 2023, 1:13am UTC](https://community.prismic.io/t/prismicerror-an-invalid-api-response-was-returned/13563/2 "2023-07-04T01:13:23Z")

</div>

@nunopereirasousa00,  
It has been my experience that when you upgrade your packages and then run dev, their script does create the appropriate slicemachine.config.json file as you mentioned, but it does not then adjust your prismicio.js

Check that your prismicio looks similar to the following:

```auto
import * as prismic from '@prismicio/client'
import * as prismicNext from '@prismicio/next'
import config from './slicemachine.config.json'

/**
 * The project's Prismic repository name.
 */
export const repositoryName = config.repositoryName
//
// your route stuff goes here...
//
export const createClient = (config = {}) => {
  const client = prismic.createClient(repositoryName, {
    routes,
    ...config,
  })

  prismicNext.enableAutoPreviews({
    client,
    previewData: config.previewData,
    req: config.req,
  })

  return client
}

```

Your slicemachine.config.json should be similar to this:

```auto
{
  "apiEndpoint": "https://your-repo-here.cdn.prismic.io/api/v2",
  "repositoryName": "your-repo-here",
  "adapter": "@slicemachine/adapter-next",
  "libraries": ["./slices"],
  "localSliceSimulatorURL": "http://localhost:3000/slice-simulator"
}

```

Does that help in any way?

---

<div class="post-metadata">

**Author:** ![nunopereirasousa00](https://avatars.discourse-cdn.com/v4/letter/n/9dc877/32.png) [@nunopereirasousa00](https://community.prismic.io/u/nunopereirasousa00)\
**Post date:** [July 4, 2023, 1:35pm UTC](https://community.prismic.io/t/prismicerror-an-invalid-api-response-was-returned/13563/3 "2023-07-04T13:35:09Z")

</div>

@nf_mastroianni thank you for the response! Seems like in the code I had "config.apiEndpoint" and not "config.repositoryName". I can't really check atm if the "An invalid API response was returned" error is fixed with this change because I still have a lot of slices missing. Meaning if I build the website again, if the error no longer exists, the website will be deployed without the missing slices.  
Regarding this issue, when I am at the "Changes" tab in [http://localhost:9999/slices](http://localhost:9999/slices), sometimes one of the missing slices appears and then suddenly disappears. Is there any way to get these back? As I said before, I can still see the missing slices in the "slices" folder in my code base, just not at [http://localhost:9999/slices](http://localhost:9999/slices). I don't know if this might be connected, but right after I updated the slice machine in this project, the localhost loses connection with the Prismic authentication quite often.

---

<div class="post-metadata">

**Author:** ![nf\_mastroianni](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/nf_mastroianni/32/7071_2.png) [@nf\_mastroianni](https://community.prismic.io/u/nf_mastroianni)\
**Post date:** [July 4, 2023, 3:04pm UTC](https://community.prismic.io/t/prismicerror-an-invalid-api-response-was-returned/13563/4 "2023-07-04T15:04:04Z")

</div>

Wow, that seems very strange about how they appear and disappear like that. It is my understanding that if the data are present in your models files, you should be safe. Could this be a browser/caching issue? If you cleared your cache or tried another browser? Also, when strange things like this happen, I've found that deleting the .next directory and then running dev again helps.

---

<div class="post-metadata">

**Author:** ![nunopereirasousa00](https://avatars.discourse-cdn.com/v4/letter/n/9dc877/32.png) [@nunopereirasousa00](https://community.prismic.io/u/nunopereirasousa00)\
**Post date:** [July 4, 2023, 10:59pm UTC](https://community.prismic.io/t/prismicerror-an-invalid-api-response-was-returned/13563/5 "2023-07-04T22:59:51Z")

</div>

Already cleared cache and deleted the .next folder and still the same.  
Yes it is super weird... basically when I click for the first time in the "Changes" tab sometimes it shows me either a slice with the "New" tag, which was created and published months ago, or the missing slices. If I click refresh they disappear from the "changes" tab right away.

---

<div class="post-metadata">

**Author:** ![nf\_mastroianni](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/nf_mastroianni/32/7071_2.png) [@nf\_mastroianni](https://community.prismic.io/u/nf_mastroianni)\
**Post date:** [July 4, 2023, 11:11pm UTC](https://community.prismic.io/t/prismicerror-an-invalid-api-response-was-returned/13563/6 "2023-07-04T23:11:11Z")

</div>

Have you tried spinning up a new prismic repo and project using

```auto
prismic theme --theme-url https://github.com/yourGitHubUserName/YourGitHubRepoName

```

Might be worth it to see if the slices/types are all faithfully recreated

---

<div class="post-metadata">

**Author:** ![nunopereirasousa00](https://avatars.discourse-cdn.com/v4/letter/n/9dc877/32.png) [@nunopereirasousa00](https://community.prismic.io/u/nunopereirasousa00)\
**Post date:** [July 5, 2023, 4:58pm UTC](https://community.prismic.io/t/prismicerror-an-invalid-api-response-was-returned/13563/8 "2023-07-05T16:58:11Z")

</div>

I was able to get the slices back. I installed again the slice-machine version I had initially - 0.5.2 - and the slices missing appeared, but I still see "An invalid API response was returned" when building the website. Could this be related to the 'Your request count (151) is over the allowed limit of 150.'? (as it shown on the first image I uploaded). I already have the prismicio.js file as you have it above.

---

<div class="post-metadata">

**Author:** ![nf\_mastroianni](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/nf_mastroianni/32/7071_2.png) [@nf\_mastroianni](https://community.prismic.io/u/nf_mastroianni)\
**Post date:** [July 5, 2023, 8:53pm UTC](https://community.prismic.io/t/prismicerror-an-invalid-api-response-was-returned/13563/9 "2023-07-05T20:53:22Z")

</div>

@nunopereirasousa00,  
I'm happy to see you were able to resolve the missing slices issue. I've not seen a error message like you describe.

Is the error related just to your sitemap? I feel like it's really hard to figure this out with the info that I have.

---

<div class="post-metadata">

**Author:** ![nunopereirasousa00](https://avatars.discourse-cdn.com/v4/letter/n/9dc877/32.png) [@nunopereirasousa00](https://community.prismic.io/u/nunopereirasousa00)\
**Post date:** [July 6, 2023, 12:23am UTC](https://community.prismic.io/t/prismicerror-an-invalid-api-response-was-returned/13563/10 "2023-07-06T00:23:26Z")

</div>

Yes it was the sitemap file. For some reason there was "config.apiEndpoint" instead of "config.repositoryName" in this file. Not sure why this error appeared after successfully building the website so many times for so long with "config.apiEndpoint".  
Anyway, thank you so much @nf_mastroianni!

---

<div class="post-metadata">

**Author:** ![carlo2](https://avatars.discourse-cdn.com/v4/letter/c/eb8c5e/32.png) [@carlo2](https://community.prismic.io/u/carlo2)\
**Post date:** [January 25, 2024, 3:01pm UTC](https://community.prismic.io/t/prismicerror-an-invalid-api-response-was-returned/13563/11 "2024-01-25T15:01:30Z")

</div>

Hey there,  
I have a pretty weird Error, this error started, after creating a new Page Type. So I removed the Page Type again in the Sliceeditor and pushed it to the Server.  
I also removed all the Code I created (just went one commit back)...

Now I get this Error:

```auto
PrismicError: An invalid API response was returned
    at Client.fetch (webpack-internal:///(rsc)/./node_modules/@prismicio/client/dist/createClient.js:1163:19)       
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Client.getFirst (webpack-internal:///(rsc)/./node_modules/@prismicio/client/dist/createClient.js:277:24)
    at async Client.getSingle (webpack-internal:///(rsc)/./node_modules/@prismicio/client/dist/createClient.js:533:16)
    at async Module.generateMetadata (webpack-internal:///(rsc)/./src/app/page.tsx:29:18) {
  url: 'https://myproject.cdn.prismic.io/api/v2/documents/search?q=%5B%5Bat%28document.type%2C+%22home%22%29%5D%5D&pageSize=1&ref=ZbJl-xEAAB8A-iZe&routes=%5B%7B%22type%22%3A%22home%22%2C%22path%22%3A%22%2F%22%7D%2C%7B%22type%22%3A%22page%22%2C%22path%22%3A%22%2F%3Auid%22%7D%2C%7B%22type%22%3A%22neuigkeiten_post%22%2C%22path%22%3A%22%2Fneuigkeiten%2F%3Auid%22%7D%2C%7B%22type%22%3A%22neuigkeiten%22%2C%22path%22%3A%22%2Fneuigkeiten%2Fpage.tsx%22%7D%5D',
  response: undefined
}

```

I use Next Js:  
my Configuration Files are all right.  
I tried:

- Updating all Packeges
- Restarting my PC
- Updated Node js
- Connecting my Project again with the Prismic project (npx @slicemachine/init@latest --repository my-project)

Here are the other files:

```auto
{
  "repositoryName": "my-project",
  "adapter": "@slicemachine/adapter-next",
  "libraries": ["./src/slices"],
  "localSliceSimulatorURL": "http://localhost:3000/slice-simulator"
}

```

```auto
import * as prismic from "@prismicio/client";
import * as prismicNext from "@prismicio/next";
import config from "../slicemachine.config.json";

/**
 * The project's Prismic repository name.
 */
export const repositoryName =
  process.env.NEXT_PUBLIC_PRISMIC_ENVIRONMENT || config.repositoryName;

/**
 * A list of Route Resolver objects that define how a document's `url` field is resolved.
 *
 * {@link https://prismic.io/docs/route-resolver#route-resolver}
 */
// TODO: Update the routes array to match your project's route structure.
const routes: prismic.ClientConfig["routes"] = [
  {
    type: "home",
    path: "/",
  },
  {
    type: "page",
    path: "/:uid",
  },
  {
    type: "neuigkeiten_post",
    path: "/neuigkeiten/:uid",
  },
  {
    type: "neuigkeiten",
    path: "/neuigkeiten/page.tsx",
  },
];

/**
 * Creates a Prismic client for the project's repository. The client is used to
 * query content from the Prismic API.
 *
 * @param config - Configuration for the Prismic client.
 */
export const createClient = (config: prismicNext.CreateClientConfig = {}) => {
  const client = prismic.createClient(repositoryName, {
    routes,
    fetchOptions:
      process.env.NODE_ENV === "production"
        ? { next: { tags: ["prismic"] }, cache: "force-cache" }
        : { next: { revalidate: 5 } },
    ...config,
  });

  prismicNext.enableAutoPreviews({
    client,
    previewData: config.previewData,
    req: config.req,
  });

  return client;
};

```

---

<div class="post-metadata">

**Author:** ![gijs](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/gijs/32/4212_2.png) [@gijs](https://community.prismic.io/u/gijs)\
**Post date:** [January 25, 2024, 3:10pm UTC](https://community.prismic.io/t/prismicerror-an-invalid-api-response-was-returned/13563/12 "2024-01-25T15:10:54Z")

</div>

@carlo2 The error is caused by the content API being down. The Prismic team says they are in contact with AWS about resolving the downtime. Keep an eye on the [status page](https://status.prismic.io/) and this thread:

> [@Error: An invalid API response was returned](https://community.prismic.io/t/error-an-invalid-api-response-was-returned/15050/26):
>
> We have identified a network issue related a service managed by our infrastructure provider. We are in contact with our service provider who are observing and investigating a drop in connections to our storage system. In parallel, we are actively working on a backup plan to bypass this issue by utilizing different infrastructure.

---

<div class="post-metadata">

**Author:** ![janisgaudreault.jg](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/janisgaudreault.jg/32/6889_2.png) [@janisgaudreault.jg](https://community.prismic.io/u/janisgaudreault.jg)\
**Post date:** [January 25, 2024, 3:18pm UTC](https://community.prismic.io/t/prismicerror-an-invalid-api-response-was-returned/13563/13 "2024-01-25T15:18:09Z")

</div>

Oh, so it's about the server! haha good to know I was looking everywhere to figure out what is going on...

---

<div class="post-metadata">

**Author:** ![carlo2](https://avatars.discourse-cdn.com/v4/letter/c/eb8c5e/32.png) [@carlo2](https://community.prismic.io/u/carlo2)\
**Post date:** [January 25, 2024, 3:25pm UTC](https://community.prismic.io/t/prismicerror-an-invalid-api-response-was-returned/13563/14 "2024-01-25T15:25:21Z")

</div>

Oh, thanks for the heads up! I've been searching high and low for a solution, even asking ChatGPT for help, haha! 😅

For anyone reading this thread in the future and encountering a similar error, here is the Statuspage ;-)

[Prismic Status Page](https://status.prismic.io/)

It's a bit of a relief to know it's an external issue, although it's still frustrating to hit a snag like this. Good to have a community to share these updates with. 😄

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [January 25, 2024, 3:47pm UTC](https://community.prismic.io/t/prismicerror-an-invalid-api-response-was-returned/13563/15 "2024-01-25T15:47:00Z")

</div>

Main thread updated.

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [January 25, 2024, 3:47pm UTC](https://community.prismic.io/t/prismicerror-an-invalid-api-response-was-returned/13563/16 "2024-01-25T15:47:02Z")

</div>

closed on January 25, 2024, 3:47pm UTC, flag & select 'Something Else' to reopen.


