> ## Documentation Index
> Fetch the complete documentation index at: https://cerebrium-mintlify-de397217.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Cerebrium's documentation MCP server is available at https://cerebrium.ai/docs/mcp for searching and querying these docs directly. Install the Cerebrium agent skill with `npx skills add https://cerebrium.ai/docs`. Append .md to any docs page URL to fetch that page as plain Markdown. API keys and authentication tokens are created in the Cerebrium dashboard at https://dashboard.cerebrium.ai.

# Using Secrets

> Store API keys and credentials as encrypted secrets in Cerebrium, expose them as environment variables, and manage them at project or app level.

Secrets store API keys, passwords, and other sensitive information outside of code. Secrets are encrypted at rest (256-bit AES) and decrypted only at runtime.

You can manage secrets at both project and app levels. Project-level secrets are shared across all apps in your project, while app-level secrets are specific to an individual app. App secrets take precedence over project-wide secrets.

Each secret is exposed to the app as an environment variable.

Secrets are available in every region an app runs in. Apps deployed to [multiple regions](/deployments/multi-region-deployment) require no per-region secret setup.

Secrets are loaded on container startup. If you update a secret, you must restart your app container for the changes to take effect.

```python theme={null}
def predict(run_id):
    print(f"Run ID: {run_id}")

    hf_token = os.environ.get("HF_TOKEN")
    logger.info(f"HF_TOKEN: {hf_token}")

    return {"result": f"Your HF_TOKEN is {hf_token}"}
```

<Note>
  Secrets are stored as strings. If your secret is a JSON payload or similar,
  remember to convert it to the correct format using
  `json.loads(os.environ.get("MY_JSON_SECRET"))`.
</Note>

### Managing Secrets

You create, update, and delete secrets in your dashboard.

<img src="https://mintcdn.com/cerebrium-mintlify-de397217/vEKaxWNymFxMWbTF/images/secrets_dashboard.png?fit=max&auto=format&n=vEKaxWNymFxMWbTF&q=85&s=9ca5b99bd35ed8c17128f941393f71c5" alt="Secrets" width="2824" height="1018" data-path="images/secrets_dashboard.png" />

<Note>
  Secrets are loaded on model start. You will need to wait for your app
  container to restart or deploy your app before the new secret is available.
</Note>

### Automatic Environment Variables

Cerebrium automatically sets the following environment variables for your app:

* APP\_NAME: The name of your application
* HF\_HOME: Set to '/persistent-storage/.cache/huggingface' for caching HuggingFace models
* PROJECT\_ID: The ID of your Cerebrium project
* BUILD\_ID: The unique identifier for the current build

<Note>The app\_id is a composite of PROJECT\_ID + '\_' + APP\_NAME.</Note>

### Local Development

For local development, use an `.env` file. Add the same secrets to the dashboard before deploying.

```python theme={null}
import os
from dotenv import load_dotenv

load_dotenv()

hf_token = os.environ.get("HF_TOKEN")
```
