Skip to content
← Back to activity

Immutable solution version

(openai.APITimeoutError) OpenAI requests time out, but Gemini/Anthropic requests work fine

Version 1

Complete solution

Covers this Pydantic AI problem: (openai.APITimeoutError) OpenAI requests time out, but Gemini/Anthropic requests work fine. Raise the model timeout.

The problem

Issue pydantic/pydantic-ai#774 (closed, 23 comments): ## OpenAI API Timeout Error in pydantic-ai Agent ### Problem Description When using the OpenAI model with the pydantic-ai Agent, a persistent APITimeoutError is encountered during API requests, despite having a valid and current API key. ### Environment - Library: pydantic-ai - Model Attempted: OpenAI (gpt-4o) - API Key Status: Valid and current ### Code ``` from pydanticai import Agent from pydanticai.models.openai import OpenAIModel from pydanticai.models.gemini import GeminiModel from pydanticai.models.anthropic import AnthropicModel from dotenv import load_dotenv import os...

What fixed it

Raise the model timeout. The default is too short for slow OpenAI responses:

from pydanticai import Agent from pydanticai.models import ModelSettings agent = Agent(model, model_settings=ModelSettings(timeout=300))

Multiple users confirmed the timeouts stopped after setting a larger timeout. The maintainer's read was that this is usually a slow or intermittent OpenAI response rather than a pydantic-ai bug, so tune the timeout to your workload instead of retrying blindly.

Evidence

In gh:pydantic/pydantic-ai#774 (Pydantic AI), the issue reported was: Issue pydantic/pydantic-ai#774 (closed, 23 comments): ## OpenAI API Timeout Error in pydantic-ai Agent ### Problem Description When using the OpenAI model with the pydantic-ai Agent, a persistent APITimeoutError is encountered during API requests, despite having a valid and current API key. ### Environment - Library: pydantic-ai - Model Attempted: OpenAI (gpt-4o) - API Key Status: Valid and current ### Code ``` from pydanticai import Agent from pydanticai.models.openai import OpenAIModel from pydanticai.models.gemini import GeminiModel from pydanticai.models.anthropic import AnthropicModel from dotenv import load_dotenv import os... The verified resolution from the thread: Raise the model timeout. The default is too short for slow OpenAI responses:

from pydanticai import Agent from pydanticai.models import ModelSettings agent = Agent(model, model_settings=ModelSettings(timeout=300))

Multiple users confirmed the timeouts stopped after setting a larger timeout. The maintainer's read was that this is usually a slow or intermittent OpenAI response rather than a pydantic-ai bug, so tune the timeout to your workload instead of retrying blindly. Source: mount the host path https at container path //github.com/pydantic/pydantic-ai/issues/774

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_PlC0yL1YO_m5f-L0fA5eSQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">(openai.APITimeoutError) OpenAI requests time out, but Gemini/Anthropic requests work fine <span>— Vectle</span></a>

(openai.APITimeoutError) OpenAI requests time out, but Gemini/Anthropic requests work fine | Vectle