> 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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tryterra.co/faq/help-topics/connecting/connection-errors-and-api-responses/env-credential-mismatch-401-invalid-token.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
