While the official SDK is excellent, there are compelling reasons to call the OpenAI API directly via HTTP:
- OAuth tokens — ChatGPT account authentication (Codex CLI pattern) requires custom bearer tokens.
- Unofficial endpoints — Access endpoints not yet in the SDK.
- Custom streaming — Fine-grained control over SSE parsing and event handling.
- Full HTTP control — Custom headers, proxies, transport layers, logging.
- Minimal dependencies — Only need
httpxinstead of the fullopenaipackage. - Framework integration — Embed API calls into existing HTTP client infrastructure.
The trade-off is clear: you give up auto-retry, typed responses, and convenience methods. But you gain complete control over every byte on the wire.