RapidAPI key not being recognized in JavaScript fetch request

I’m working with RapidAPI for the first time and running into an issue with API authentication. I’m trying to fetch data from a movie quotes API using JavaScript but keep getting an error about missing application key.

async function loadQuotes() {
    await fetch("https://movie-quotes-api.p.rapidapi.com/?limit=5&genre=comedy", {
        "method": "GET",
        "headers": {
            "x-rapidapi-host": "movie-quotes-api.p.rapidapi.com",
            "x-rapidapi-key": "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz",
            "content-type": "application/json"
        }
    })
    .then(data => {
        console.log(data);
    })
    .catch(error => {
        console.log(error);
    });
}

The fetch seems to work and returns status 200, but when I check the actual response, I get an error message saying the RapidAPI application key is missing. I’ve double checked that I’m including the key in the headers correctly. The response shows all the typical fetch properties like body, headers, ok: true, etc.

However, the API endpoint itself returns an authentication error. I can see my API key is there in the headers, so I’m not sure what’s going wrong. Could this be a formatting issue or am I missing something else in my request setup?

Check if your API key is actually valid and has the correct permissions for that specific endpoint. I had a similar situation where the key looked correct but I was using a trial key that had expired without realizing it. Go back to your RapidAPI dashboard and verify the key status and subscription details. Sometimes the API returns 200 status even when authentication fails at the application level. Another thing to try is testing the same request in RapidAPI’s built-in test console first to confirm everything works there before moving to your JavaScript code. If it fails in their console too, then the issue is definitely with the key or subscription rather than your implementation.

I encountered this exact problem when I started using RapidAPI. The issue is that you’re not actually reading the response body. Your fetch returns a Response object with status 200, but you need to call .json() or .text() on it to get the actual API response. The authentication error is in the response body, not the HTTP status. Try changing your code to fetch(...).then(response => response.json()).then(data => console.log(data)). Also, make sure you’re using your actual API key from the RapidAPI dashboard, not a placeholder. The content-type header isn’t necessary for GET requests either.

Had same headache with rapidapi few weeks ago. turns out i was copy/pasting the key wrong from dashboard - there were hidden spaces at the end that i didnt notice. try recreating a new key or copy it again carefully. also some endpoints need specific user-agent header even tho its not mentioned in docs.