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

Method copy

src/openai/_client.py:573–660  ·  src/openai/_client.py::OpenAI.copy

Create a new client instance re-using the same options given to the current client with optional overriding.

(
        self,
        *,
        api_key: str | Callable[[], str] | None = None,
        admin_api_key: str | None = None,
        workload_identity: WorkloadIdentity | None = None,
        provider: _Provider | None | NotGiven = not_given,
        organization: str | None = None,
        project: str | None = None,
        webhook_secret: str | None = None,
        websocket_base_url: str | httpx.URL | None = None,
        base_url: str | httpx.URL | None = None,
        timeout: float | Timeout | None | NotGiven = not_given,
        http_client: httpx.Client | None = None,
        max_retries: int | NotGiven = not_given,
        default_headers: Mapping[str, str] | None = None,
        set_default_headers: Mapping[str, str] | None = None,
        default_query: Mapping[str, object] | None = None,
        set_default_query: Mapping[str, object] | None = None,
        _enforce_credentials: bool | None = None,
        _extra_kwargs: Mapping[str, Any] = {},
    )

Source from the content-addressed store, hash-verified

571 return self.api_key
572
573 def copy(
574 self,
575 *,
576 api_key: str | Callable[[], str] | None = None,
577 admin_api_key: str | None = None,
578 workload_identity: WorkloadIdentity | None = None,
579 provider: _Provider | None | NotGiven = not_given,
580 organization: str | None = None,
581 project: str | None = None,
582 webhook_secret: str | None = None,
583 websocket_base_url: str | httpx.URL | None = None,
584 base_url: str | httpx.URL | None = None,
585 timeout: float | Timeout | None | NotGiven = not_given,
586 http_client: httpx.Client | None = None,
587 max_retries: int | NotGiven = not_given,
588 default_headers: Mapping[str, str] | None = None,
589 set_default_headers: Mapping[str, str] | None = None,
590 default_query: Mapping[str, object] | None = None,
591 set_default_query: Mapping[str, object] | None = None,
592 _enforce_credentials: bool | None = None,
593 _extra_kwargs: Mapping[str, Any] = {},
594 ) -> Self:
595 class="st">"""
596 Create a new client instance re-using the same options given to the current client with optional overriding.
597 class="st">"""
598 if default_headers is not None and set_default_headers is not None:
599 raise ValueError(class="st">"The `default_headers` and `set_default_headers` arguments are mutually exclusive")
600
601 if default_query is not None and set_default_query is not None:
602 raise ValueError(class="st">"The `default_query` and `set_default_query` arguments are mutually exclusive")
603
604 provider_changed = not isinstance(provider, NotGiven) and provider is not self._provider
605 inherited_organization = None if provider_changed else self.organization
606 inherited_project = None if provider_changed else self.project
607
608 headers: Mapping[str, str] = {} if provider_changed else self._custom_headers
609 if default_headers is not None:
610 headers = {**headers, **default_headers}
611 elif set_default_headers is not None:
612 headers = set_default_headers
613
614 params = self._custom_query
615 if default_query is not None:
616 params = {**params, **default_query}
617 elif set_default_query is not None:
618 params = set_default_query
619
620 http_client = http_client or self._client
621
622 next_provider = self._provider if isinstance(provider, NotGiven) else provider
623 auth_options: dict[str, Any]
624 if next_provider is not None:
625 auth_options = {
626 class="st">"provider": next_provider,
627 class="st">"api_key": api_key,
628 class="st">"admin_api_key": admin_api_key,
629 class="st">"workload_identity": workload_identity,
630 class="st">"base_url": base_url,

Callers 15

model_copyFunction · 0.45
mainFunction · 0.45
fresh_envFunction · 0.45
update_envFunction · 0.45
test_copyMethod · 0.45
build_requestMethod · 0.45
test_copy_authMethod · 0.45
test_copyMethod · 0.45

Calls 2

is_givenFunction · 0.85
__class__Method · 0.80

Tested by 14

fresh_envFunction · 0.36
test_copyMethod · 0.36
build_requestMethod · 0.36
test_copy_authMethod · 0.36
test_copyMethod · 0.36
build_requestMethod · 0.36
test_copy_authMethod · 0.36