MCPcopy Create free account
hub / github.com/anomalyco/opencode-sdk-python / __init__

Method __init__

src/opencode_ai/_base_client.py:822–866  ·  view source on GitHub ↗
(
        self,
        *,
        version: str,
        base_url: str | URL,
        max_retries: int = DEFAULT_MAX_RETRIES,
        timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
        http_client: httpx.Client | None = None,
        custom_headers: Mapping[str, str] | None = None,
        custom_query: Mapping[str, object] | None = None,
        _strict_response_validation: bool,
    )

Source from the content-addressed store, hash-verified

820 _default_stream_cls: type[Stream[Any]] | None = None
821
822 def __init__(
823 self,
824 *,
825 version: str,
826 base_url: str | URL,
827 max_retries: int = DEFAULT_MAX_RETRIES,
828 timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
829 http_client: httpx.Client | None = None,
830 custom_headers: Mapping[str, str] | None = None,
831 custom_query: Mapping[str, object] | None = None,
832 _strict_response_validation: bool,
833 ) -> None:
834 if not is_given(timeout):
835 # if the user passed in a custom http client with a non-default
836 # timeout set then we use that timeout.
837 #
838 # note: there is an edge case here where the user passes in a client
839 # where they've explicitly set the timeout to match the default timeout
840 # as this check is structural, meaning that we'll think they didn't
841 # pass in a timeout and will ignore it
842 if http_client and http_client.timeout != HTTPX_DEFAULT_TIMEOUT:
843 timeout = http_client.timeout
844 else:
845 timeout = DEFAULT_TIMEOUT
846
847 if http_client is not None and not isinstance(http_client, httpx.Client): # pyright: ignore[reportUnnecessaryIsInstance]
848 raise TypeError(
849 f"Invalid `http_client` argument; Expected an instance of `httpx.Client` but got {type(http_client)}"
850 )
851
852 super().__init__(
853 version=version,
854 # cast to a valid type because mypy doesn't understand our type narrowing
855 timeout=cast(Timeout, timeout),
856 base_url=base_url,
857 max_retries=max_retries,
858 custom_query=custom_query,
859 custom_headers=custom_headers,
860 _strict_response_validation=_strict_response_validation,
861 )
862 self._client = http_client or SyncHttpxClientWrapper(
863 base_url=base_url,
864 # cast to a valid type because mypy doesn't understand our type narrowing
865 timeout=cast(Timeout, timeout),
866 )
867
868 def is_closed(self) -> bool:
869 return self._client.is_closed

Callers

nothing calls this directly

Calls 3

is_givenFunction · 0.85
__init__Method · 0.45

Tested by

no test coverage detected