mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 09:05:23 -04:00
504 Gateway Timeout - The server didn't respond in time #160
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @devilteo911 on GitHub (Nov 7, 2024).
Originally assigned to: @ParthSareen on GitHub.
I don't know why but I'm encountering this problem with the library. Here I show my simple script:
Where
llm_config["base_url"]is the ollama url server (it's a serverless gpu) that I can reach successfully from open-webui and even query the model without issues. The model I'm using is:qwen2.5:32b-instruct-q4_K_Mand the GPU is a RTX A6000.The traceback (client-side) is the following:
and this is what I see on the server side:
It happens everytime after 50 seconds even if the timeout is 600 seconds. Am I missing something?
@MatteoSid commented on GitHub (Nov 7, 2024):
I have the same issue
@ParthSareen commented on GitHub (Nov 15, 2024):
Hey @devilteo911 - have you tried not setting a timeout and seeing if there's an issue on the server side regardless? Trying to narrow down if some information is not passing all the way through to the server or if there is an error on the server side.
Thanks!
@devilteo911 commented on GitHub (Nov 19, 2024):
Hey @ParthSareen,
The issue seems to occur only on the first call, which consistently results in a 504 error. Subsequent calls with the same input perform the generation without any problems.
I believe the problem is related to the time it takes to generate the first token, particularly during a cold start of my service. During a cold start, the model needs to be downloaded from Hugging Face, as my serverless GPU provider lacks permanent storage to keep the model locally.
I hope this clarifies the issue.
@felixmarch commented on GitHub (Jan 16, 2025):
I experienced the issue intermittently when I looped it like this:
Is there a way to increase the timeout?
Had tried to start it like this but also still intermittently timed out 😕
# OLLAMA_LOAD_TIMEOUT=30m0s /bin/ollama serve@meidaid commented on GitHub (Feb 3, 2025):
FYI: I tried to use
"keep_alive": "0"but got an error. When I changed it to"keep_alive": 0(notice that I removed the quotes from around the0, the immediate errors ended, but I still got the 504. I even tried increasing the value to360000(I assumed thtat these are milliseconds) and I still got a 504. Is there something that we are missing here? 🤔@meidaid commented on GitHub (Feb 3, 2025):
🤗 For anybody using
nginxas their reverse proxy I found the following solution from https://stackoverflow.com/questions/43832389/what-can-i-do-to-fix-a-504-gateway-timeout-error actually solved my problem when combined with the above advice on including the"keep_alive"seemed to make the 504 vanish for me. 🤗The following is from the Stack Overflow post:
@mattjwarren commented on GitHub (Jun 9, 2025):
I have arrived here after already changing nginx timeouts. Using a containerised app in k8s, I have increased ingress timouts, gunicorn worker timeouts, and the gninx proxy timeouts all to 600 seconds. I still see error 504 gateway timeout , and ollama appears to be the only place left.
Is there any value controlling timeout on ollama serve API calls?