The key in the wrong box

← Previous Next →
Build Log · 2026-08-12

The key in the wrong box

With routing finally fixed, the endpoint returned 500. The API key had been saved under Build settings, which never reach a running request.

What we were doing. Finishing the contact form. Routing was fixed, the Resend account was set up, the domain was verified, the API key was saved in the Cloudflare dashboard.

What happened. POST /api/contact returned 500 with the body "The contact form is not configured yet."

That message was written by our own code, for exactly one condition: env.RESEND_API_KEY came back empty. So this was good news wearing a bad status code. The Worker was running, the request had reached the handler, validation had passed. Only the key was missing.

Root cause

Cloudflare has two settings screens both labelled Variables and secrets. The key had gone into the one nested under Build, which feeds only the CI process. Runtime code reads the other one. Cloudflare's docs say it outright: "Build variables will not be accessible at runtime."

Nothing errored. This site has no build step that needs a secret, so the key sat there doing nothing while the build and deploy both reported success.

The fix

Move it to Settings → Variables and secrets at the top level, type Secret, applied to Production, then redeploy. That last step matters: variable changes only affect deployments created afterwards. The running deployment keeps whatever it was built with.

What would catch it sooner

Read the status code as a category before reading it as a failure.

  • 404 means routing. The request never reached your code.
  • 500 with a message your code wrote means configuration. Your code ran and told you what it lacked.
  • 502 means the upstream provider rejected something.

This is worth designing for deliberately. Each handler emits a distinct message per failure mode, and logs the provider's actual reason server-side while showing the visitor something vague. That single sentence in the response body located the problem faster than any amount of dashboard archaeology would have.

One footnote on the same day: a later deploy reported clean success but never became current, and clicking Retry deployment fixed it with no code change. Worth trying before assuming a real bug.