kiranetic

Azure App Service has a request timeout you can't raise

App Service sits behind a front end that closes idle HTTP connections at around 230 seconds. It isn't a setting on your app and you can't configure your way out of it. Long-running AI calls hit it constantly.

The fix is to stop holding the connection open. Accept the request, hand the work to a background task, return a job id immediately, and let the client poll.

@app.post("/extract")
async def extract(req: Request, tasks: BackgroundTasks):
    job_id = new_job()
    tasks.add_task(run_extraction, job_id, await req.json())
    return {"job_id": job_id, "status": "queued"}


@app.get("/extract/{job_id}")
async def status(job_id: str):
    return get_job(job_id)

Half the people hitting this error are still looking for the timeout setting.