gpt-oss20b is timing out for a content generation usecase locally on an M3 pro with 18GB - Specifically content generation and tool call using AgentSDK doesn’t work with gpt oss - simple example - email marketing assistant - generate and send email content.
meanwhile, chatCompletions for content generation worked great for the same use case.
Timeout Errors
litellm.exceptions.APIConnectionError: litellm.APIConnectionError: OllamaException - litellm.Timeout: Connection timed out. Timeout passed=600.0, time taken=600.129 seconds
Cookbook Reference : How to run gpt-oss locally with Ollama
Since it is running locally, if it takes too long it will timeout.
Here is an example using stream, that should solve the issue.
from openai import OpenAI
import time
client = OpenAI(
base_url="http://localhost:11434/v1", # Local Ollama API
api_key="ollama" # Dummy key
)
start_time = time.time()
response = client.chat.completions.create(
model="gpt-oss:20b",
reasoning_effort="low",
messages=[
{'role': 'user', 'content': 'Hi'}
],
stream=True,
)
collected_messages = []
for chunk in response:
chunk_time = time.time() - start_time # calculate the time delay of the chunk
# print(chunk)
if chunk.choices:
chunk_message = chunk.choices[0].delta.content
chunk_reasoning = chunk.choices[0].delta.dict().get('reasoning','')
collected_messages.append(chunk_message) # save the message
if chunk_message:
print(chunk_message, end='')
if chunk_reasoning:
print(chunk_reasoning, end='')
print(f"\nFull response received {chunk_time:.2f} seconds after request")
collected_messages = [m for m in collected_messages if m is not None]
full_reply_content = ''.join(collected_messages)
print(f"Full conversation received: {full_reply_content}")
Or, increase the timeout parameter in OpenAI(…, timeout=xxx)
ps: On agents sdk, it seems litellm doesn’t support streaming for gpt-oss yet. Hopefully they will update it soon.
Meanwhile, this should allow the increase in the timeout value for gpt-oss in agents:
agent = Agent(
name="Assistant",
model=LitellmModel( model="ollama/gpt-oss:20b",
api_key="ollama",),
model_settings=ModelSettings(
extra_args={
"request_timeout": 1000, #seconds
}
)
)
result = await Runner.run(agent, "Hi")