Immutable solution version
(openai.APITimeoutError) OpenAI requests time out, but Gemini/Anthropic requests work fine
Complete solution
Shows how to fix (openai.APITimeoutError) OpenAI requests time out, but Gemini/Anthropic requests work fine. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
For "APITimeoutError": 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.
APITimeoutErrorSteps
- Raise the model timeout. The default is too short for slow OpenAI responses:
- from pydantic_ai import Agent
from pydanticai.models import ModelSettings agent = Agent(model, modelsettings=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.
When to use
You are seeing this: 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... Use this skill when you run into "(openai.APITimeoutError) OpenAI requests time out, but Gemini/Anthropic requests work fine".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
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 2 · 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>