# My Roboflow API isn't working how to resolve this problem?

**URL:** <https://discuss.roboflow.com/t/my-roboflow-api-isnt-working-how-to-resolve-this-problem/10855>\
**Category:** 🤝  Community Help\
**Tags:** segmentation\
**Created:** [August 6, 2025, 4:17am UTC](https://discuss.roboflow.com/t/my-roboflow-api-isnt-working-how-to-resolve-this-problem/10855 "2025-08-06T04:17:01Z")\
**Posts on this page:** 4\
**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 6, 2025, 4:17am UTC](https://discuss.roboflow.com/t/my-roboflow-api-isnt-working-how-to-resolve-this-problem/10855/1 "2025-08-06T04:17:01Z")

</div>

I want to use roboflow api on my render server but it kept making errors.  
It’s because of unauthorized error.

There must be a problem with my workspace.

Please check it.

I generated new key and make sure it’s clear and I copied well and it’s my workspace key.

But, it didn’t fixed again and again.

I need help.

I don’t know how to give permission to anyone but I can just tell my workspace/ Project ID

recycling-segmentation-amso6

recycling-segmentation-amso6/34

model version34 is the best performance so I want to use it.

Following is my error code

ERROR HTTPCallErrorError(description='401 Client Error: Unauthorized for url: [https://serverless.roboflow.com/recycling-segmentation-amso6/34?api\_key=I](https://serverless.roboflow.com/recycling-segmentation-amso6/34?api_key=I) filled it&disable\_active\_learning=False[’,](https://serverless.roboflow.com/recycling-segmentation-amso6/28?api_key=MO***QV&disable_active_learning=False%27,) api\_message=‘Unauthorized access to roboflow API - check API key and make sure the key is valid for workspace you use. status\_code=401)

Please help me.  
And This is my fastapi code.

Please check this code.

```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 Roboflow client
CLIENT = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key="I filled it"
)

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

@app.post("/predict")
async def predict(file: UploadFile = File(...)):
    try:
        # Save uploaded file 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:
            # Analyze image with Roboflow API
            result = CLIENT.infer(
                temp_file_path, 
                model_id="recycling-segmentation-amso6/34"  
            )
            return result
            
        except Exception as api_error:
            error_msg = str(api_error)
            if "timeout" in error_msg.lower():
                return {"error": "API server response 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)

```

Thank yor for reading my long article.

I must finish this project.

Please help me.

---

<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 6, 2025, 5:34pm UTC](https://discuss.roboflow.com/t/my-roboflow-api-isnt-working-how-to-resolve-this-problem/10855/2 "2025-08-06T17:34:50Z")

</div>

Have you verified that your API key works outside of the FastAPI environment? Also, are you using your private or publishable key?

---

<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 7, 2025, 2:27am UTC](https://discuss.roboflow.com/t/my-roboflow-api-isnt-working-how-to-resolve-this-problem/10855/3 "2025-08-07T02:27:40Z")

</div>

I’ve tried it but it didn’t work and I’m using private key.

---

<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 28, 2025, 2:28am UTC](https://discuss.roboflow.com/t/my-roboflow-api-isnt-working-how-to-resolve-this-problem/10855/4 "2025-08-28T02:28:02Z")

</div>

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