How openai/openai-python works
OpenAI Python API library is a typed sync/async SDK: an application configures a client, calls a resource method, and receives parsed or streamed API results. The graph preserves documented Responses, Chat Completions, vision, audio, realtime, administration, and webhook capabilities, plus client transport, authentication, and response handling. Some feature implementations are represented by their exact resource directories because their individual source files were not sampled; edges are limited to README or source-index evidence.
Main entry points: _client.py Sync and async clients · _base_client.py HTTP request engine · resources Other API resources · _legacy_response.py Legacy response wrappers
Components 19
Client and transport
- Sync and async clients
src/openai/_client.py - Authentication hooks
src/openai/lib/_client_auth.py - HTTP request engine
src/openai/_base_client.py - HTTPX2 client
src/openai/_httpx2.py
API resources
- Responses API
src/openai/resources/responses - Chat Completions
src/openai/resources/chat - Other API resources
src/openai/resources - Administration API
src/openai/resources/admin
Specialized capabilities
- Audio API
src/openai/resources/audio - Realtime API
src/openai/resources/realtime - Beta agents and tools
src/openai/resources/beta - Webhook operations
src/openai/resources/webhooks/webhooks.py
Responses and types
- Pagination
src/openai/pagination.py - Parsed and raw responses
src/openai/_response.py - Legacy response wrappers
src/openai/_legacy_response.py - Server-sent streaming
src/openai/_streaming.py - Typed models
src/openai/_models.py - API exceptions
src/openai/_exceptions.py
Other components
- Python application
Connections 22
- Python application → Sync and async clients: configures and calls
- Sync and async clients → Authentication hooks: configures authentication
src/openai/_client.py - Sync and async clients → HTTP request engine: uses request engine
src/openai/_client.py - HTTP request engine → HTTPX2 client: sends HTTP
src/openai/_base_client.py - Python application → Responses API: calls Responses API
- Python application → Chat Completions: calls Chat API
- Sync and async clients → Responses API: exposes resource
src/openai/_client.py - Sync and async clients → Chat Completions: exposes resource
src/openai/_client.py - Sync and async clients → Other API resources: exposes resources
src/openai/_client.py - Sync and async clients → Administration API: exposes resources
src/openai/_client.py - Sync and async clients → Audio API: exposes resources
src/openai/_client.py - Sync and async clients → Realtime API: exposes resources
src/openai/_client.py - Sync and async clients → Beta agents and tools: exposes resources
src/openai/_client.py - Sync and async clients → Webhook operations: exposes resources
src/openai/_client.py - Other API resources → Pagination: uses pagination
src/openai/resources/admin/organization/external_storage.py - Other API resources → Legacy response wrappers: wraps raw results
src/openai/resources/admin/organization/external_storage.py - HTTP request engine → Legacy response wrappers: builds legacy result
src/openai/_base_client.py - Parsed and raw responses → Typed models: parses results
src/openai/_response.py - Legacy response wrappers → Typed models: parses results
src/openai/_legacy_response.py - HTTP request engine → Server-sent streaming: creates streams
src/openai/_base_client.py - Server-sent streaming → API exceptions: raises API errors
src/openai/_streaming.py - Sync and async clients → API exceptions: maps status errors
src/openai/_client.py