My GitHub Actions build for Azure Static Web Apps completes and uploads, but the deploy step fails with ‘Invalid API key’ even though AZURE_STATIC_WEB_APPS_API_TOKEN is set?

Priyanka Kugapriya 20 Reputation points
2025-08-29T05:21:02.1166667+00:00

Error code - Deployment Failed :( Deployment Failure Reason: Invalid API key

Azure Static Web Apps
Azure Static Web Apps

An Azure service that provides streamlined full-stack web app development.


Answer accepted by question author
Anonymous
2025-09-01T08:32:49.71+00:00

Hi @Priyanka Kugapriya

I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this!

Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

Issue:

My GitHub Actions build for Azure Static Web Apps completes and uploads, but the deploy step fails with ‘Invalid API key’ even though AZURE_STATIC_WEB_APPS_API_TOKEN is set?

Error code - Deployment Failed :( Deployment Failure Reason: Invalid API key

Solution Provided by Priyanka Kugapriya:

Part 1: The "Invalid API Key" Error

The Invalid API key error was not caused by a bad or expired token. The issue was with the initial setup of the Azure Static Web App itself.

  • The Fix: When creating the new Static Web App, instead of linking it directly to GitHub, I chose the Deployment token option. This created a new token that, when used in the GitHub Actions workflow file, allowed the deployment to proceed without any token errors.

Part 2: The "Web app warm up timed out" Error

After fixing the token issue, I encountered a new error: Deployment Failure Reason: Web app warm up timed out. This was also a common issue with Next.js projects on Azure.

Root Cause: My Next.js app was configured for server-side rendering (SSR) using rewrites and an output location of .next. Azure Static Web Apps is a static hosting service, and it couldn't properly start the server-side part of the app.

The Fixes: To solve this, I had to make three key changes to convert my app into a fully static site:

Change next.config.ts: Added output: 'export' and removed the rewrites to tell Next.js to generate a static site.

Update GitHub Actions: Changed the `output_location` in the workflow YAML file from `.next` to `out`.

Change API Calls: Updated my frontend code to use an environment variable (`NEXT_PUBLIC_API_URL`) to directly call my live Azure App Service backend, as `rewrites` no longer work.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.