> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blobrouter.com/llms.txt
> Use this file to discover all available pages before exploring further.

# FastAPI

> Upload files with FastAPI and the BlobRouter Python SDK.

<Info>
  **BlobRouter v0.1** · Last updated: August 2026 · Architecture version: **2.0**
</Info>

```bash theme={null}
pip install fastapi uvicorn python-multipart blobrouter
```

```python theme={null}
import os
from fastapi import FastAPI, File, UploadFile, HTTPException
from blobrouter import BlobRouter, BlobRouterError

app = FastAPI()
storage = BlobRouter(api_key=os.environ["BLOBROUTER_API_KEY"])


@app.post("/upload")
async def upload(file: UploadFile = File(...)):
    data = await file.read()
    try:
        result = storage.upload(
            file=data,
            file_name=file.filename or "upload.bin",
            content_type=file.content_type or "application/octet-stream",
            file_size_bytes=len(data),
            priority="cold",
        )
    except BlobRouterError as err:
        raise HTTPException(
            status_code=err.status_code or 500,
            detail={"error": str(err), "code": err.code},
        ) from err
    return result
```

```bash theme={null}
uvicorn main:app --reload
```
