A Python-based server system for video generation relied on a standardized HTTP client architecture for API calls. However, the introduction of the OpenAI SDK caused servers to crash during startup due to missing dependencies and improper shutdown operations.
Issue
Three critical servers crashed during initialization with errors including:
- Connection failures:
RuntimeError: Client failed to connectdue to missing dependencies. - Missing module errors:
ModuleNotFoundError: No module named 'openai'due to the absence of the OpenAI SDK. - Shutdown I/O errors:
I/O operation on closed fileduring improper shutdown sequences.
The crashes occurred after junior developers introduced the OpenAI SDK instead of using the FastMCP 2.0’s native httpx pattern for API calls, violating architectural guidelines.
Culprit
The root causes included:
- Unnecessary dependency introduction: Use of the OpenAI SDK (
openai>=1.0.0) added significant bloat (50+ MB) and violated the standardizedhttpx-based HTTP client pattern. - Improper shutdown handling: The evaluator server contained
print()statements after closing the HTTP client, causing I/O errors during shutdown. - Overcomplication of async patterns: The orchestrator used
AsyncOpenAI()despite compatibility with standard HTTP POST requests, adding unnecessary complexity.
Solution
Migration to Standardized HTTP Client
All OpenAI SDK calls were replaced with FastMCP-compliant httpx.AsyncClient implementations:
- Standardized HTTP configuration: Used
httpx.AsyncClientwith proper headers and timeouts for all external API calls. - Context management: Implemented proper async context management for HTTP clients, ensuring clean shutdowns.
- Dependency cleanup: Removed the OpenAI SDK entirely, reducing dependency bloat and ensuring consistency with the architecture.
Key Changes
- Removed all OpenAI SDK references and replaced them with direct HTTP client usage.
- Fixed shutdown I/O errors by ensuring no operations were performed after client closure.
- Standardized async patterns to use
httpxexclusively, eliminating unnecessary complexity.
Verification: All servers now initialize successfully without errors, and dependency checks confirm the removal of the OpenAI SDK.