# The Gradio API by curl doesn't work

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fthe-gradio-api-by-curl-doesnt-work%2F166428%3E%5C
**Category:** Beginners\
**Created:** [August 11, 2025, 5:10pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fthe-gradio-api-by-curl-doesnt-work%2F166428 "2025-08-11T17:10:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GoldDany](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@GoldDany](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FGoldDany)%5C
**Post date:** [August 11, 2025, 5:10pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fthe-gradio-api-by-curl-doesnt-work%2F166428%2F1 "2025-08-11T17:10:24Z")

</div>

I try curl from basic guide, but it throws: 405({ “detail”: “Method Not Allowed”}).

Curl: curl -X POST [https://golddany-didefbackend.hf.space/call/predict](https://golddany-didefbackend.hf.space/call/predict) -s -H “Content-Type: application/json” -d ‘{  
“data”: [  
“Hello!!”  
]}’  
| awk -F’"’ ‘{ print $4}’  
| read EVENT\_ID; curl -N [https://golddany-didefbackend.hf.space/call/predict/$EVENT\_ID](https://golddany-didefbackend.hf.space/call/predict/$EVENT_ID)

I can get event\_id from first request, but second(../$EVENT\_ID) always throws: “Connection broken: InvalidChunkLength(got length b’‘, 0 bytes read)”, InvalidChunkLength(got length b’’, 0 bytes read)

---

<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 11, 2025, 11:58pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fthe-gradio-api-by-curl-doesnt-work%2F166428%2F2 "2025-08-11T23:58:55Z")

</div>

Hmm, I think the code is written according to the sample. I don’t know what the problem is…🤔  
I’ll try experimenting a little later.

- [Querying Gradio Apps with Curl](https://www.gradio.app/guides/querying-gradio-apps-with-curl)
- [gradio {“detail”:“Method Not Allowed”}](https://github.com/gradio-app/gradio/issues/4591)
- [Gradio REST API + bash curl always skips the queue](https://github.com/gradio-app/gradio/issues/6350)

---

<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 12, 2025, 12:17am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fthe-gradio-api-by-curl-doesnt-work%2F166428%2F3 "2025-08-12T00:17:27Z")

</div>

It worked for some reason… From the server side, it should be the same thing…

```py
import os, requests

SPACE = "john6666-apitest1.hf.space"
API_NAME = "predict"
HF_TOKEN = os.getenv("HF_TOKEN", None)
base = f"https://{SPACE}"

auth_h = {"Authorization": f"Bearer {HF_TOKEN}", "Content-Type": "application/json"} if HF_TOKEN else {}
r = requests.post(f"{base}/call/{API_NAME}", headers=auth_h, json={"data": ["hi"]}, timeout=30)
r.raise_for_status()
eid = r.json()["event_id"]

with requests.get(f"{base}/call/{API_NAME}/{eid}", headers={"Authorization": f"Bearer {HF_TOKEN}", "Accept": "text/event-stream"}, stream=True, timeout=300) as resp:
    for line in resp.iter_lines(decode_unicode=True):
        if line:
            print(line) # data: [[0.03394877910614014, -0.005614369176328182, -0.0012183655053377151, 0.015974245965480804,...

```

---

<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 12, 2025, 1:32pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fthe-gradio-api-by-curl-doesnt-work%2F166428%2F4 "2025-08-12T13:32:56Z")

</div>

Closed on August 12, 2025, 1:32pm UTC

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