# How to manage user secrets and API Keys?

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-manage-user-secrets-and-api-keys%2F67948%3E%5C
**Category:** Spaces\
**Created:** [January 4, 2024, 9:46am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-manage-user-secrets-and-api-keys%2F67948 "2024-01-04T09:46:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KushwanthK](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@KushwanthK](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FKushwanthK)%5C
**Post date:** [January 4, 2024, 9:46am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-manage-user-secrets-and-api-keys%2F67948%2F1 "2024-01-04T09:46:26Z")

</div>

> **[Spaces Overview](https://huggingface.co/docs/hub/spaces-overview)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

As per the above page I didn’t see the Space repository to add a new variable or secret.  
new variable or secret are deprecated in settings page. How to handle the API Keys and user secrets like Secrets Manager?

 ![Screenshot 2024-01-04 at 1.48.17 AM](https://us1.discourse-cdn.com/hellohellohello/original/3X/6/f/6f3fe8f2d9dc8f30a052200f9645b5d228d474bf.png)

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fradames)%5C
**Post date:** [January 4, 2024, 11:26pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-manage-user-secrets-and-api-keys%2F67948%2F2 "2024-01-04T23:26:50Z")

</div>

hi @KushwanthK , You can access secrets and variables on your Space Settings page

`https://huggingface.co/spaces/` **USER** / **SPACE\_ID** `/settings`

---

<div class="post-metadata">

**Author:** ![Manubrah](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/manubrah/32/24938_2.png) [@Manubrah](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FManubrah)%5C
**Post date:** [March 17, 2024, 3:05pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-manage-user-secrets-and-api-keys%2F67948%2F3 "2024-03-17T15:05:44Z")

</div>

I replied to this question here: [https://huggingface.co/spaces/ysharma/ChatGPT4/discussions/23#65f70560dd3cc437a85d2aea](https://huggingface.co/spaces/ysharma/ChatGPT4/discussions/23#65f70560dd3cc437a85d2aea)

Would be nice if the huggingface’s team adds this little detail to the docs: [Spaces Overview](https://huggingface.co/docs/hub/spaces-overview#managing-secrets)

---

<div class="post-metadata">

**Author:** ![Manubrah](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/manubrah/32/24938_2.png) [@Manubrah](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FManubrah)%5C
**Post date:** [March 17, 2024, 3:07pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-manage-user-secrets-and-api-keys%2F67948%2F4 "2024-03-17T15:07:08Z")

</div>

To use your environment variables in a secure way you need to do this:

1. Go to `https://huggingface.co/spaces/USER/SPACE_ID/settings`

2. Create Private Secret. Let’s say you name it “YOUR SECRET KEY”

3. Go to your app.py script and add these lines:

```auto
import os

api_key = os.getenv("YOUR SECRET KEY")
client = OpenAI(api_key=api_key)

```
