MCPcopy
hub / github.com/openai/openai-python / OpenAI

Class OpenAI

src/openai/_client.py:105–698  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103
104
105class OpenAI(SyncAPIClient):
106 # client options
107 api_key: str
108 admin_api_key: str | None
109 workload_identity: WorkloadIdentity | None
110 organization: str | None
111 project: str | None
112 webhook_secret: str | None
113 _workload_identity_auth: WorkloadIdentityAuth | None
114 _provider: _Provider | None
115 _provider_runtime: _ProviderRuntime | None
116
117 websocket_base_url: str | httpx.URL | None
118 """Base URL for WebSocket connections.
119
120 If not specified, the default base URL will be used, with 'wss://' replacing the
121 'http://' or 'https://' scheme. For example: 'http://example.com' becomes
122 'wss://example.com'
123 """
124
125 def __init__(
126 self,
127 *,
128 api_key: str | Callable[[], str] | None = None,
129 admin_api_key: str | None = None,
130 workload_identity: WorkloadIdentity | None = None,
131 organization: str | None = None,
132 project: str | None = None,
133 webhook_secret: str | None = None,
134 provider: _Provider | None = None,
135 base_url: str | httpx.URL | None = None,
136 websocket_base_url: str | httpx.URL | None = None,
137 timeout: float | Timeout | None | NotGiven = not_given,
138 max_retries: int = DEFAULT_MAX_RETRIES,
139 default_headers: Mapping[str, str] | None = None,
140 default_query: Mapping[str, object] | None = None,
141 # Configure a custom httpx client.
142 # We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
143 # See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
144 http_client: httpx.Client | None = None,
145 # Enable or disable schema validation for data returned by the API.
146 # When enabled an error APIResponseValidationError is raised
147 # if the API responds with invalid data for the expected schema.
148 #
149 # This parameter may be removed or changed in the future.
150 # If you rely on this feature, please open a GitHub issue
151 # outlining your use-case to help us decide if it should be
152 # part of our public interface in the future.
153 _strict_response_validation: bool = False,
154 _enforce_credentials: bool = True,
155 ) -> None:
156 """Construct a new synchronous OpenAI client instance.
157
158 This automatically infers the following arguments from their corresponding environment variables if they are not provided:
159 - `api_key` from `OPENAI_API_KEY`
160 - `admin_api_key` from `OPENAI_ADMIN_KEY`
161 - `organization` from `OPENAI_ORG_ID`
162 - `project` from `OPENAI_PROJECT_ID`

Calls

no outgoing calls