> For the complete documentation index, see [llms.txt](https://docs.tryterra.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tryterra.co/faq/help-topics/connecting/connection-errors-and-api-responses/env-credential-mismatch-401-invalid-token.md).

# Why do my requests return 401 in production?

`401` / invalid-token errors almost always mean **credentials are mismatched across environments**.

**A blanket `401`** means the `dev-id` and `x-api-key` pair don't match a valid account. When moving from testing to production:

* Update both headers.
* Ensure both come from the same dashboard account.
* Confirm the production `dev-id` matches what's under your [dashboard API settings](https://github.com/tryterra/api-faqs/blob/main/dashboard/README.md).

**An invalid-token error on SDK connection** means the auth token was generated for a different environment than the `dev-id` used at SDK init. Generate the token with the **same `dev-id`** (e.g. staging) you pass when initialising the SDK.

See [understanding Terra environments](https://docs.tryterra.co/health-and-fitness-api/integration-setup/understanding-terra-environments) for more.
