Provide request timeout option #245

Closed
opened 2026-02-15 16:29:09 -05:00 by yindo · 1 comment
Owner

Originally created by @Saya47 on GitHub (Mar 25, 2025).

Hello I found out that my generate request was hanging for 4 hours until I had to Ctrl+C it:

Mar 25 13:01:56 DESKTOP-SHX ollama[247]: [GIN] 2025/03/25 - 13:01:56 | 200 | 24.853512474s |       127.0.0.1 | POST     "/api/generate"
Mar 25 13:02:15 DESKTOP-SHX ollama[247]: [GIN] 2025/03/25 - 13:02:15 | 200 | 19.460779574s |       127.0.0.1 | POST     "/api/generate"
Mar 25 17:17:55 DESKTOP-SHX ollama[247]: [GIN] 2025/03/25 - 17:17:55 | 500 |      4h15m37s |       127.0.0.1 | POST     "/api/generate"

I presume Ollama uses the python Requests library and it is not possible to set a global timeout, so it would be really nice to have an option to set timeout in the generate function as an argument. Thanks a lot.

Originally created by @Saya47 on GitHub (Mar 25, 2025). Hello I found out that my generate request was hanging for 4 hours until I had to Ctrl+C it: ```log Mar 25 13:01:56 DESKTOP-SHX ollama[247]: [GIN] 2025/03/25 - 13:01:56 | 200 | 24.853512474s | 127.0.0.1 | POST "/api/generate" Mar 25 13:02:15 DESKTOP-SHX ollama[247]: [GIN] 2025/03/25 - 13:02:15 | 200 | 19.460779574s | 127.0.0.1 | POST "/api/generate" Mar 25 17:17:55 DESKTOP-SHX ollama[247]: [GIN] 2025/03/25 - 17:17:55 | 500 | 4h15m37s | 127.0.0.1 | POST "/api/generate" ``` I presume Ollama uses the python Requests library and it is not possible to set a global timeout, so it would be really nice to have an option to set timeout in the generate function as an argument. Thanks a lot.
yindo closed this issue 2026-02-15 16:29:09 -05:00
Author
Owner

@nazariitaran commented on GitHub (Apr 1, 2025):

You can specify the timeout by providing a custom Client object:

from ollama import Client

client = Client(
  host='http://localhost:11434',
  timeout=1 # custom timeout
)

response = client.chat(model='gemma3:27b', messages=[
  {
    'role': 'user',
    'content': 'Why is the sky blue?',
  },
])

print(response.message.content)
@nazariitaran commented on GitHub (Apr 1, 2025): You can specify the timeout by providing a custom `Client` object: ```python from ollama import Client client = Client( host='http://localhost:11434', timeout=1 # custom timeout ) response = client.chat(model='gemma3:27b', messages=[ { 'role': 'user', 'content': 'Why is the sky blue?', }, ]) print(response.message.content) ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#245