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

Method __init__

src/openai/_client.py:721–871  ·  view source on GitHub ↗

Construct a new async AsyncOpenAI 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[[], Awaitable[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 `DefaultAsyncHttpxClient` 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/#asyncclient) for more details.
        http_client: httpx.AsyncClient | 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,
    )

Source from the content-addressed store, hash-verified

719 """
720
721 def __init__(
722 self,
723 *,
724 api_key: str | Callable[[], Awaitable[str]] | None = None,
725 admin_api_key: str | None = None,
726 workload_identity: WorkloadIdentity | None = None,
727 organization: str | None = None,
728 project: str | None = None,
729 webhook_secret: str | None = None,
730 provider: _Provider | None = None,
731 base_url: str | httpx.URL | None = None,
732 websocket_base_url: str | httpx.URL | None = None,
733 timeout: float | Timeout | None | NotGiven = not_given,
734 max_retries: int = DEFAULT_MAX_RETRIES,
735 default_headers: Mapping[str, str] | None = None,
736 default_query: Mapping[str, object] | None = None,
737 # Configure a custom httpx client.
738 # We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
739 # See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
740 http_client: httpx.AsyncClient | None = None,
741 # Enable or disable schema validation for data returned by the API.
742 # When enabled an error APIResponseValidationError is raised
743 # if the API responds with invalid data for the expected schema.
744 #
745 # This parameter may be removed or changed in the future.
746 # If you rely on this feature, please open a GitHub issue
747 # outlining your use-case to help us decide if it should be
748 # part of our public interface in the future.
749 _strict_response_validation: bool = False,
750 _enforce_credentials: bool = True,
751 ) -> None:
752 """Construct a new async AsyncOpenAI client instance.
753
754 This automatically infers the following arguments from their corresponding environment variables if they are not provided:
755 - `api_key` from `OPENAI_API_KEY`
756 - `admin_api_key` from `OPENAI_ADMIN_KEY`
757 - `organization` from `OPENAI_ORG_ID`
758 - `project` from `OPENAI_PROJECT_ID`
759 - `webhook_secret` from `OPENAI_WEBHOOK_SECRET`
760
761 When `provider` is supplied, authentication and the base URL are configured by that provider instead.
762 """
763 provider_runtime: _ProviderRuntime | None = None
764 if provider is not None:
765 provider_name = _provider_name(provider)
766 conflicts = [
767 name
768 for name, value in (
769 ("api_key", api_key),
770 ("admin_api_key", admin_api_key),
771 ("workload_identity", workload_identity),
772 ("base_url", base_url),
773 )
774 if value is not None
775 ]
776 if conflicts:
777 formatted = ", ".join(f"`{name}`" for name in conflicts)
778 raise OpenAIError(

Callers

nothing calls this directly

Calls 7

_provider_nameFunction · 0.85
OpenAIErrorClass · 0.85
_configure_providerFunction · 0.85
is_mapping_tFunction · 0.85
getMethod · 0.45
__init__Method · 0.45

Tested by

no test coverage detected