# Private Space authentication for external API calls

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fprivate-space-authentication-for-external-api-calls%2F167772%3E%5C
**Category:** Spaces\
**Created:** [August 26, 2025, 8:43am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fprivate-space-authentication-for-external-api-calls%2F167772 "2025-08-26T08:43:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nasr7322](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nasr7322/32/53080_2.png) [@nasr7322](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnasr7322)%5C
**Post date:** [August 26, 2025, 8:43am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fprivate-space-authentication-for-external-api-calls%2F167772%2F1 "2025-08-26T08:43:45Z")

</div>

Hello everyone!  
I’m using a Docker 🤗 Space to deploy my FastAPI application that uses multiple models, but I’ve set it to private since my project contains sensitive code. My problem is that I can’t send requests to the endpoints from anywhere outside my browser and get a 404.

Is it possible to send a 🤗 token with the request to authenticate myself? If so, how should I include it in my request to make it work properly?

Thank you all in advance! 🖐

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [August 26, 2025, 9:10am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fprivate-space-authentication-for-external-api-calls%2F167772%2F2 "2025-08-26T09:10:04Z")

</div>

If the space is functioning properly, you should be able to access it like following.  
You can figure out the actual space URL yourself, also [you can also find it using the GUI](https://huggingface.co/docs/hub/en/spaces-embed).

```bash
curl -X POST https://OWNER-SPACENAME.hf.space/api/predict \
  -H "Authorization: Bearer $HF_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"text":"hello"}'

```

or

```py
import os, requests
url = "https://OWNER-SPACENAME.hf.space/api/predict"
r = requests.post(url,
                  headers={"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"},
                  json={"text": "hello"},
                  timeout=60)
print(r.status_code, r.text)

```

If you want to implement [more complex access control](https://huggingface.co/spaces/zero-gpu-explorers/README/discussions/88#68a736ebb21506a456c47c81).

---

<div class="post-metadata">

**Author:** ![nasr7322](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nasr7322/32/53080_2.png) [@nasr7322](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnasr7322)%5C
**Post date:** [August 26, 2025, 9:11am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fprivate-space-authentication-for-external-api-calls%2F167772%2F3 "2025-08-26T09:11:44Z")

</div>

yup it worked, thank youu!  
my problem was with the token

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/hellohellohello/original/2X/d/de4155eb4aa4108ecb32a1389d7cc37ae69f88b7.png) [@system](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsystem)%5C
**Post date:** [August 26, 2025, 9:12pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fprivate-space-authentication-for-external-api-calls%2F167772%2F4 "2025-08-26T21:12:23Z")

</div>

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
