# HTTPCallErrorError(description='401 Client Error: Unauthorized

**URL:** <https://discuss.roboflow.com/t/httpcallerrorerror-description-401-client-error-unauthorized/10811>\
**Category:** 🤝  Community Help\
**Created:** [August 1, 2025, 2:58am UTC](https://discuss.roboflow.com/t/httpcallerrorerror-description-401-client-error-unauthorized/10811 "2025-08-01T02:58:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Minyst](https://avatars.discourse-cdn.com/v4/letter/m/5f8ce5/32.png) [@Minyst](https://discuss.roboflow.com/u/Minyst)\
**Post date:** [August 1, 2025, 2:58am UTC](https://discuss.roboflow.com/t/httpcallerrorerror-description-401-client-error-unauthorized/10811/1 "2025-08-01T02:58:20Z")

</div>

**Project Type: Semantic Segmentation**

**Operating System & Browser: Windows/ Chrome**

**Project ID: Recycling Segmentation**

**Model ID: recycling-segmentation-amso6/28**

**This error message occurs every single time when I run android studio code which is written by flutter.**

**HTTPCallErrorError(description='401 Client Error: Unauthorized.**

**I revoke my api key and I also refresh my render server which is model server website connected by github**

**I followed the instruction and copied the Hosted Image Inference code but it didn’t work**

**I don’t know why my gmail account is flagged.**

**I just wanted to tell my problem.**

**Admin asked me to give answer so I don’t know how to give grant to admin and I gave team member code but suddenly my account flagged.**

**I was so frustrated.**

**I didn’t realized the regulation but it wasn’t intentional.**

**I sent messages twice time to moderators.**

**There wasn’t any answer.**

**I couldn’t replied to admin because I’m already flagged because of my roboflow team member link.**

**I think admin didn’t realized that I’m flagged.**

**My workspace email address is different from this account but I’m afraid to tell my email address because I could be flagged again.**

**I’m the university student and I have to finish this project until this month I mean in summer vacation.**

**Please help me to find out and solve the problem**.

---

<div class="post-metadata">

**Author:** ![Ford](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/ford/32/7747_2.png) [@Ford](https://discuss.roboflow.com/u/Ford)\
**Post date:** [August 1, 2025, 8:04pm UTC](https://discuss.roboflow.com/t/httpcallerrorerror-description-401-client-error-unauthorized/10811/2 "2025-08-01T20:04:07Z")

</div>

Hi @Minyst!  
I deeply apologize for this! To help me troubleshoot, do you mind sharing a code snippet or any further context to help me troubleshoot!

Apologies again for the inconvenience.

---

<div class="post-metadata">

**Author:** ![Minyst](https://avatars.discourse-cdn.com/v4/letter/m/5f8ce5/32.png) [@Minyst](https://discuss.roboflow.com/u/Minyst)\
**Post date:** [August 1, 2025, 11:29pm UTC](https://discuss.roboflow.com/t/httpcallerrorerror-description-401-client-error-unauthorized/10811/3 "2025-08-01T23:29:24Z")

</div>

```auto
from fastapi import FastAPI, UploadFile, File
from fastapi.middleware.cors import CORSMiddleware
from inference_sdk import InferenceHTTPClient
import uvicorn
import os
import tempfile

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["GET", "POST"],
    allow_headers=["*"],
)

# initialize the client
CLIENT = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key="My own api key"
)

@app.get("/")
async def root():
    return {"message": "Roboflow API Server", "status": "running"}

@app.post("/predict")
async def predict(file: UploadFile = File(...)):
    try:
        # Save uploaded image as temporary file
        with tempfile.NamedTemporaryFile(delete=False, suffix=f".{file.filename.split('.')[-1]}") as temp_file:
            content = await file.read()
            temp_file.write(content)
            temp_file_path = temp_file.name
        
        try:
            # Inference on local image
            result = CLIENT.infer(
                temp_file_path, 
                model_id="recycling-segmentation-amso6/28"  
            )
            return result
            
        except Exception as api_error:
            error_msg = str(api_error)
            if "timeout" in error_msg.lower():
                return {"error": "API server timeout", "status": "failed"}
            elif "connection" in error_msg.lower():
                return {"error": "Network connection failed", "status": "failed"}
            elif "401" in error_msg or "unauthorized" in error_msg.lower():
                return {"error": "API key authentication failed", "status": "failed"}
            elif "404" in error_msg:
                return {"error": "Model not found", "status": "failed"}
            else:
                return {"error": str(api_error), "status": "failed"}
                
        finally:
            # Delete temporary file
            if os.path.exists(temp_file_path):
                os.unlink(temp_file_path)
            
    except Exception as e:
        return {"error": str(e), "status": "failed"}

@app.post("/predict-raw")
async def predict_raw(file: UploadFile = File(...)):
    return await predict(file)

if __name__ == " __main__":
    port = int(os.environ.get("PORT", 8000))
    uvicorn.run("main:app", host="0.0.0.0", port=port, reload=False)

```

---

<div class="post-metadata">

**Author:** ![Minyst](https://avatars.discourse-cdn.com/v4/letter/m/5f8ce5/32.png) [@Minyst](https://discuss.roboflow.com/u/Minyst)\
**Post date:** [August 4, 2025, 10:46pm UTC](https://discuss.roboflow.com/t/httpcallerrorerror-description-401-client-error-unauthorized/10811/4 "2025-08-04T22:46:20Z")

</div>

I think you forgot to reply my answer.  
Following code is my code snippet.

```auto
from fastapi import FastAPI, UploadFile, File
from fastapi.middleware.cors import CORSMiddleware
from inference_sdk import InferenceHTTPClient
import uvicorn
import os
import tempfile

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["GET", "POST"],
    allow_headers=["*"],
)

# initialize the client
CLIENT = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key="My own api key"
)

@app.get("/")
async def root():
    return {"message": "Roboflow API Server", "status": "running"}

@app.post("/predict")
async def predict(file: UploadFile = File(...)):
    try:
        # Save uploaded image as temporary file
        with tempfile.NamedTemporaryFile(delete=False, suffix=f".{file.filename.split('.')[-1]}") as temp_file:
            content = await file.read()
            temp_file.write(content)
            temp_file_path = temp_file.name
        
        try:
            # Inference on local image
            result = CLIENT.infer(
                temp_file_path, 
                model_id="recycling-segmentation-amso6/28"  
            )
            return result
            
        except Exception as api_error:
            error_msg = str(api_error)
            if "timeout" in error_msg.lower():
                return {"error": "API server timeout", "status": "failed"}
            elif "connection" in error_msg.lower():
                return {"error": "Network connection failed", "status": "failed"}
            elif "401" in error_msg or "unauthorized" in error_msg.lower():
                return {"error": "API key authentication failed", "status": "failed"}
            elif "404" in error_msg:
                return {"error": "Model not found", "status": "failed"}
            else:
                return {"error": str(api_error), "status": "failed"}
                
        finally:
            # Delete temporary file
            if os.path.exists(temp_file_path):
                os.unlink(temp_file_path)
            
    except Exception as e:
        return {"error": str(e), "status": "failed"}

@app.post("/predict-raw")
async def predict_raw(file: UploadFile = File(...)):
    return await predict(file)

if __name__ == " __main__":
    port = int(os.environ.get("PORT", 8000))
    uvicorn.run("main:app", host="0.0.0.0", port=port, reload=False)

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/1X/bb6edbfa56d0cf2ee603f061e9e09103502cc8cc.png) [@system](https://discuss.roboflow.com/u/system)\
**Post date:** [August 25, 2025, 10:47pm UTC](https://discuss.roboflow.com/t/httpcallerrorerror-description-401-client-error-unauthorized/10811/5 "2025-08-25T22:47:06Z")

</div>

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