Construct a new synchronous OpenAI client instance. This automatically infers the following arguments from their corresponding environment variables if they are not provided: - `api_key` from `OPENAI_API_KEY` - `admin_api_key` from `OPENAI_ADMIN_KEY` - `organization`
(
self,
*,
api_key: str | Callable[[], str] | None = None,
admin_api_key: str | None = None,
workload_identity: WorkloadIdentity | None = None,
organization: str | None = None,
project: str | None = None,
webhook_secret: str | None = None,
provider: _Provider | None = None,
base_url: str | httpx.URL | None = None,
websocket_base_url: str | httpx.URL | None = None,
timeout: float | Timeout | None | NotGiven = not_given,
max_retries: int = DEFAULT_MAX_RETRIES,
default_headers: Mapping[str, str] | None = None,
default_query: Mapping[str, object] | None = None,
# Configure a custom httpx client.
# We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
# See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
http_client: httpx.Client | None = None,
# Enable or disable schema validation for data returned by the API.
# When enabled an error APIResponseValidationError is raised
# if the API responds with invalid data for the expected schema.
#
# This parameter may be removed or changed in the future.
# If you rely on this feature, please open a GitHub issue
# outlining your use-case to help us decide if it should be
# part of our public interface in the future.
_strict_response_validation: bool = False,
_enforce_credentials: bool = True,
)
| 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` |
| 163 | - `webhook_secret` from `OPENAI_WEBHOOK_SECRET` |
| 164 | |
| 165 | When `provider` is supplied, authentication and the base URL are configured by that provider instead. |
| 166 | """ |
| 167 | provider_runtime: _ProviderRuntime | None = None |
| 168 | if provider is not None: |
| 169 | provider_name = _provider_name(provider) |
| 170 | conflicts = [ |
| 171 | name |
| 172 | for name, value in ( |
| 173 | ("api_key", api_key), |
| 174 | ("admin_api_key", admin_api_key), |
| 175 | ("workload_identity", workload_identity), |
| 176 | ("base_url", base_url), |
| 177 | ) |
| 178 | if value is not None |
| 179 | ] |
| 180 | if conflicts: |
| 181 | formatted = ", ".join(f"`{name}`" for name in conflicts) |
| 182 | raise OpenAIError( |
no test coverage detected