# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# pyformat: disable
# pylint: skip-file

"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from .basesdk import AsyncBaseSDK, BaseSDK
from . import errors, models, types, utils
from ._hooks import AfterParseErrorContext, HookContext, ResponseContext
from .types import (
    BaseModel,
    OptionalNullable,
    UNSET,
    credentials,
    interactions,
)
from .utils import get_security_from_env, response_helpers
from .utils.unmarshal_json_response import unmarshal_json_response
import httpx
from typing import Any, List, Literal, Mapping, Optional, Union, cast, overload


class Credentials(BaseSDK):
    @property
    def with_raw_response(self):
        return CredentialsWithRawResponse(self)

    @property
    def with_streaming_response(self):
        return CredentialsWithStreamingResponse(self)

    def list(
        self,
        *,
        api_version: Optional[str] = None,
        page_size: Optional[int] = None,
        page_token: Optional[str] = None,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.CredentialListResponse:
        r"""Lists credentials.

        :param api_version: API version for request routing.
        :param page_size: Optional. Maximum number of credentials to return.
        :param page_token: Optional. Pagination token.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """
        base_url = None
        url_variables = None
        retries: OptionalNullable[utils.RetryConfig] = UNSET
        server_url = None
        http_headers = extra_headers
        timeout_ms = self._coerce_timeout_ms(timeout)
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.ListCredentialsRequest(
            api_version=api_version,
            page_size=page_size,
            page_token=page_token,
        )

        _speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
            http_headers
        )
        req = self._build_request(
            method="GET",
            path="/{api_version}/credentials",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            extra_query_params=extra_query,
            _globals=models.ListCredentialsGlobals(
                api_version=self.sdk_configuration.globals.api_version,
            ),
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "attempt-count-backoff",
                    utils.BackoffStrategy(500, 8000, 2, 30000),
                    True,
                    max_retries=4,
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["408", "409", "429", "5XX"])

        def _speakeasy_parse_response(http_res):
            if utils.match_response(http_res, "4XX", "*"):
                http_res_text = utils.stream_to_text(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "5XX", "*"):
                http_res_text = utils.stream_to_text(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "default", "application/json"):
                return unmarshal_json_response(
                    credentials.CredentialListResponse, http_res, validate=False
                )

            raise errors.GenAiDefaultError("Unexpected response received", http_res)

        _speakeasy_hook_ctx = HookContext(
            config=self.sdk_configuration,
            base_url=base_url or "",
            operation_id="ListCredentials",
            oauth2_scopes=None,
            security_source=get_security_from_env(
                self.sdk_configuration.security, types.Security
            ),
            tags=["credentials"],
            extensions=None,
            response=ResponseContext(mode=_speakeasy_response_mode, execution="sync"),
        )
        http_res = self.do_request(
            hook_ctx=_speakeasy_hook_ctx,
            request=req,
            is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
            stream=_speakeasy_response_mode == "streaming",
            retry_config=retry_config,
        )
        if _speakeasy_response_mode != "parsed":
            if utils.match_status_codes(["4XX", "5XX"], http_res.status_code):
                http_res.read()
                try:
                    _speakeasy_parse_response(http_res)
                except Exception as parse_exc_:
                    response_helpers.raise_parse_error(
                        self.sdk_configuration.__dict__["_hooks"],
                        AfterParseErrorContext(_speakeasy_hook_ctx),
                        http_res,
                        parse_exc_,
                    )
            _speakeasy_response_cls = (
                response_helpers.StreamedAPIResponse
                if _speakeasy_response_mode == "streaming"
                else response_helpers.APIResponse
            )
            return cast(
                Any,
                _speakeasy_response_cls(
                    raw=http_res,
                    parser=_speakeasy_parse_response,
                    mode="buffered",
                    client_ref=self,
                    hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
                    hooks=self.sdk_configuration.__dict__.get("_hooks"),
                ),
            )
        try:
            return _speakeasy_parse_response(http_res)
        except Exception as parse_exc_:
            response_helpers.raise_parse_error(
                self.sdk_configuration.__dict__["_hooks"],
                AfterParseErrorContext(_speakeasy_hook_ctx),
                http_res,
                parse_exc_,
            )

    @overload
    def create(
        self,
        *,
        request: Union[
            models.CreateCredentialRequest, models.CreateCredentialRequestParam
        ],
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Creates a new credential.

        :param body: Required. The request body.
        :param api_version: API version for request routing.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    @overload
    def create(
        self,
        *,
        api_version: Optional[str] = None,
        client_id: str,
        client_secret: str,
        id: str,
        refresh_token: str,
        scopes: List[str] = ...,
        token_url: str,
        type_: Literal["oauth2"],
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Creates a new credential.

        :param api_version: API version for request routing.
        :param client_id: Required. OAuth2 client ID.
        :param client_secret: Required. Input only. OAuth2 client secret. Write-only; never returned in responses.
        :param id:
        :param refresh_token: Required. Input only. OAuth2 refresh token. Write-only; never returned in responses.
        :param scopes: Optional. List of OAuth2 scopes.
        :param token_url: Required. OAuth2 token endpoint URL for refreshing access tokens.
        :param type:
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    @overload
    def create(
        self,
        *,
        api_version: Optional[str] = None,
        id: str,
        injection_location: credentials.EnvironmentVariableConfigInjectionLocationParam,
        trusted_domains: List[str] = ...,
        type_: Literal["environment_variable"],
        value: str,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Creates a new credential.

        :param api_version: API version for request routing.
        :param id:
        :param injection_location: Required. Locations where the environment variable can be injected in
            outgoing HTTP requests. Must contain at least one location.
            Accepts either a single location (e.g. \"header\") or an array of locations.
        :param trusted_domains: Optional. List of domains allowed to receive this environment variable
            value in HTTP requests.
        :param type:
        :param value: Required. Input only. Secret value of the environment variable. Write-only; never
            returned in responses.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    @overload
    def create(
        self,
        *,
        api_version: Optional[str] = None,
        header_name: str = ...,
        id: str,
        prefix: str = ...,
        token: str,
        type_: Literal["bearer_token"],
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Creates a new credential.

        :param api_version: API version for request routing.
        :param header_name: Optional. Header name to inject the token into. Defaults to
            'Authorization'.
        :param id:
        :param prefix: Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
            for no prefix.
        :param token: Required. Input only. The static bearer token. Write-only; never returned in responses.
        :param type:
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    @overload
    def create(
        self,
        *,
        request: OptionalNullable[
            Union[models.CreateCredentialRequest, models.CreateCredentialRequestParam]
        ] = UNSET,
        api_version: OptionalNullable[str] = UNSET,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
        **body_kwargs: Any,
    ) -> credentials.Credential:
        r"""Creates a new credential.

        :param api_version: API version for request routing.
        :param client_id: Required. OAuth2 client ID.
        :param client_secret: Required. Input only. OAuth2 client secret. Write-only; never returned in responses.
        :param id:
        :param refresh_token: Required. Input only. OAuth2 refresh token. Write-only; never returned in responses.
        :param scopes: Optional. List of OAuth2 scopes.
        :param token_url: Required. OAuth2 token endpoint URL for refreshing access tokens.
        :param type:
        :param injection_location: Required. Locations where the environment variable can be injected in
            outgoing HTTP requests. Must contain at least one location.
            Accepts either a single location (e.g. \"header\") or an array of locations.
        :param trusted_domains: Optional. List of domains allowed to receive this environment variable
            value in HTTP requests.
        :param value: Required. Input only. Secret value of the environment variable. Write-only; never
            returned in responses.
        :param header_name: Optional. Header name to inject the token into. Defaults to
            'Authorization'.
        :param prefix: Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
            for no prefix.
        :param token: Required. Input only. The static bearer token. Write-only; never returned in responses.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    def create(
        self,
        *,
        request: OptionalNullable[
            Union[models.CreateCredentialRequest, models.CreateCredentialRequestParam]
        ] = UNSET,
        api_version: OptionalNullable[str] = UNSET,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
        **body_kwargs: Any,
    ) -> credentials.Credential:
        r"""Creates a new credential.

        :param api_version: API version for request routing.
        :param client_id: Required. OAuth2 client ID.
        :param client_secret: Required. Input only. OAuth2 client secret. Write-only; never returned in responses.
        :param id:
        :param refresh_token: Required. Input only. OAuth2 refresh token. Write-only; never returned in responses.
        :param scopes: Optional. List of OAuth2 scopes.
        :param token_url: Required. OAuth2 token endpoint URL for refreshing access tokens.
        :param type:
        :param injection_location: Required. Locations where the environment variable can be injected in
            outgoing HTTP requests. Must contain at least one location.
            Accepts either a single location (e.g. \"header\") or an array of locations.
        :param trusted_domains: Optional. List of domains allowed to receive this environment variable
            value in HTTP requests.
        :param value: Required. Input only. Secret value of the environment variable. Write-only; never
            returned in responses.
        :param header_name: Optional. Header name to inject the token into. Defaults to
            'Authorization'.
        :param prefix: Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
            for no prefix.
        :param token: Required. Input only. The static bearer token. Write-only; never returned in responses.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """
        if "client_id" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'injection_location'.")
        if "client_id" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'trusted_domains'.")
        if "client_id" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'value'.")
        if "client_id" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'header_name'.")
        if "client_id" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'prefix'.")
        if "client_id" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'token'.")
        if "client_secret" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'client_secret' and 'injection_location'."
            )
        if "client_secret" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'client_secret' and 'trusted_domains'."
            )
        if "client_secret" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'client_secret' and 'value'.")
        if "client_secret" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'client_secret' and 'header_name'.")
        if "client_secret" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'client_secret' and 'prefix'.")
        if "client_secret" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'client_secret' and 'token'.")
        if "refresh_token" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'refresh_token' and 'injection_location'."
            )
        if "refresh_token" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'refresh_token' and 'trusted_domains'."
            )
        if "refresh_token" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'refresh_token' and 'value'.")
        if "refresh_token" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'refresh_token' and 'header_name'.")
        if "refresh_token" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'refresh_token' and 'prefix'.")
        if "refresh_token" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'refresh_token' and 'token'.")
        if "scopes" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'injection_location'.")
        if "scopes" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'trusted_domains'.")
        if "scopes" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'value'.")
        if "scopes" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'header_name'.")
        if "scopes" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'prefix'.")
        if "scopes" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'token'.")
        if "token_url" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'injection_location'.")
        if "token_url" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'trusted_domains'.")
        if "token_url" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'value'.")
        if "token_url" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'header_name'.")
        if "token_url" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'prefix'.")
        if "token_url" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'token'.")
        if "injection_location" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'injection_location' and 'header_name'."
            )
        if "injection_location" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'injection_location' and 'prefix'.")
        if "injection_location" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'injection_location' and 'token'.")
        if "trusted_domains" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'trusted_domains' and 'header_name'.")
        if "trusted_domains" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'trusted_domains' and 'prefix'.")
        if "trusted_domains" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'trusted_domains' and 'token'.")
        if "value" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'value' and 'header_name'.")
        if "value" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'value' and 'prefix'.")
        if "value" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'value' and 'token'.")
        base_url = None
        url_variables = None
        retries: OptionalNullable[utils.RetryConfig] = UNSET
        server_url = None
        http_headers = extra_headers
        timeout_ms = self._coerce_timeout_ms(timeout)
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        if request is not UNSET:
            request = cast(
                models.CreateCredentialRequest,
                request
                if isinstance(request, BaseModel)
                else utils.unmarshal(
                    cast(Any, request), models.CreateCredentialRequest
                ),
            )
        else:
            _body_kwargs = dict(body_kwargs)
            _body_kwargs = {k: v for k, v in _body_kwargs.items() if v is not UNSET}
            _request_kwargs: dict[str, Any] = {"api_version": api_version}
            _request_kwargs = {
                k: v for k, v in _request_kwargs.items() if v is not UNSET
            }
            _request_kwargs["body"] = _body_kwargs
            request = cast(
                models.CreateCredentialRequest,
                utils.unmarshal(_request_kwargs, models.CreateCredentialRequest),
            )

        _speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
            http_headers
        )
        req = self._build_request(
            method="POST",
            path="/{api_version}/credentials",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            extra_query_params=extra_query,
            _globals=models.CreateCredentialGlobals(
                api_version=self.sdk_configuration.globals.api_version,
            ),
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.body,
                False,
                False,
                "json",
                credentials.CredentialCreateParams,
                extra_body=extra_body,
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "attempt-count-backoff",
                    utils.BackoffStrategy(500, 8000, 2, 30000),
                    True,
                    max_retries=4,
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["408", "409", "429", "5XX"])

        def _speakeasy_parse_response(http_res):
            if utils.match_response(http_res, "4XX", "*"):
                http_res_text = utils.stream_to_text(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "5XX", "*"):
                http_res_text = utils.stream_to_text(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "default", "application/json"):
                return unmarshal_json_response(
                    credentials.Credential, http_res, validate=False
                )

            raise errors.GenAiDefaultError("Unexpected response received", http_res)

        _speakeasy_hook_ctx = HookContext(
            config=self.sdk_configuration,
            base_url=base_url or "",
            operation_id="CreateCredential",
            oauth2_scopes=None,
            security_source=get_security_from_env(
                self.sdk_configuration.security, types.Security
            ),
            tags=["credentials"],
            extensions=None,
            response=ResponseContext(mode=_speakeasy_response_mode, execution="sync"),
        )
        http_res = self.do_request(
            hook_ctx=_speakeasy_hook_ctx,
            request=req,
            is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
            stream=_speakeasy_response_mode == "streaming",
            retry_config=retry_config,
        )
        if _speakeasy_response_mode != "parsed":
            if utils.match_status_codes(["4XX", "5XX"], http_res.status_code):
                http_res.read()
                try:
                    _speakeasy_parse_response(http_res)
                except Exception as parse_exc_:
                    response_helpers.raise_parse_error(
                        self.sdk_configuration.__dict__["_hooks"],
                        AfterParseErrorContext(_speakeasy_hook_ctx),
                        http_res,
                        parse_exc_,
                    )
            _speakeasy_response_cls = (
                response_helpers.StreamedAPIResponse
                if _speakeasy_response_mode == "streaming"
                else response_helpers.APIResponse
            )
            return cast(
                Any,
                _speakeasy_response_cls(
                    raw=http_res,
                    parser=_speakeasy_parse_response,
                    mode="buffered",
                    client_ref=self,
                    hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
                    hooks=self.sdk_configuration.__dict__.get("_hooks"),
                ),
            )
        try:
            return _speakeasy_parse_response(http_res)
        except Exception as parse_exc_:
            response_helpers.raise_parse_error(
                self.sdk_configuration.__dict__["_hooks"],
                AfterParseErrorContext(_speakeasy_hook_ctx),
                http_res,
                parse_exc_,
            )

    def delete(
        self,
        id: str,
        *,
        api_version: Optional[str] = None,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> interactions.Empty:
        r"""Deletes a credential.

        :param id: Required. Resource ID segment making up resource `name`. It identifies the resource
            within its parent collection as described in https://google.aip.dev/122.
        :param api_version: API version for request routing.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """
        base_url = None
        url_variables = None
        retries: OptionalNullable[utils.RetryConfig] = UNSET
        server_url = None
        http_headers = extra_headers
        timeout_ms = self._coerce_timeout_ms(timeout)
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.DeleteCredentialRequest(
            api_version=api_version,
            id=id,
        )

        _speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
            http_headers
        )
        req = self._build_request(
            method="DELETE",
            path="/{api_version}/credentials/{id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            extra_query_params=extra_query,
            _globals=models.DeleteCredentialGlobals(
                api_version=self.sdk_configuration.globals.api_version,
            ),
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "attempt-count-backoff",
                    utils.BackoffStrategy(500, 8000, 2, 30000),
                    True,
                    max_retries=4,
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["408", "409", "429", "5XX"])

        def _speakeasy_parse_response(http_res):
            if utils.match_response(http_res, "4XX", "*"):
                http_res_text = utils.stream_to_text(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "5XX", "*"):
                http_res_text = utils.stream_to_text(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "default", "application/json"):
                return unmarshal_json_response(
                    interactions.Empty, http_res, validate=False
                )

            raise errors.GenAiDefaultError("Unexpected response received", http_res)

        _speakeasy_hook_ctx = HookContext(
            config=self.sdk_configuration,
            base_url=base_url or "",
            operation_id="DeleteCredential",
            oauth2_scopes=None,
            security_source=get_security_from_env(
                self.sdk_configuration.security, types.Security
            ),
            tags=["credentials"],
            extensions=None,
            response=ResponseContext(mode=_speakeasy_response_mode, execution="sync"),
        )
        http_res = self.do_request(
            hook_ctx=_speakeasy_hook_ctx,
            request=req,
            is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
            stream=_speakeasy_response_mode == "streaming",
            retry_config=retry_config,
        )
        if _speakeasy_response_mode != "parsed":
            if utils.match_status_codes(["4XX", "5XX"], http_res.status_code):
                http_res.read()
                try:
                    _speakeasy_parse_response(http_res)
                except Exception as parse_exc_:
                    response_helpers.raise_parse_error(
                        self.sdk_configuration.__dict__["_hooks"],
                        AfterParseErrorContext(_speakeasy_hook_ctx),
                        http_res,
                        parse_exc_,
                    )
            _speakeasy_response_cls = (
                response_helpers.StreamedAPIResponse
                if _speakeasy_response_mode == "streaming"
                else response_helpers.APIResponse
            )
            return cast(
                Any,
                _speakeasy_response_cls(
                    raw=http_res,
                    parser=_speakeasy_parse_response,
                    mode="buffered",
                    client_ref=self,
                    hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
                    hooks=self.sdk_configuration.__dict__.get("_hooks"),
                ),
            )
        try:
            return _speakeasy_parse_response(http_res)
        except Exception as parse_exc_:
            response_helpers.raise_parse_error(
                self.sdk_configuration.__dict__["_hooks"],
                AfterParseErrorContext(_speakeasy_hook_ctx),
                http_res,
                parse_exc_,
            )

    def get(
        self,
        id: str,
        *,
        api_version: Optional[str] = None,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Gets a credential by ID.

        :param id: Required. Resource ID segment making up resource `name`. It identifies the resource
            within its parent collection as described in https://google.aip.dev/122.
        :param api_version: API version for request routing.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """
        base_url = None
        url_variables = None
        retries: OptionalNullable[utils.RetryConfig] = UNSET
        server_url = None
        http_headers = extra_headers
        timeout_ms = self._coerce_timeout_ms(timeout)
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.GetCredentialRequest(
            api_version=api_version,
            id=id,
        )

        _speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
            http_headers
        )
        req = self._build_request(
            method="GET",
            path="/{api_version}/credentials/{id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            extra_query_params=extra_query,
            _globals=models.GetCredentialGlobals(
                api_version=self.sdk_configuration.globals.api_version,
            ),
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "attempt-count-backoff",
                    utils.BackoffStrategy(500, 8000, 2, 30000),
                    True,
                    max_retries=4,
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["408", "409", "429", "5XX"])

        def _speakeasy_parse_response(http_res):
            if utils.match_response(http_res, "4XX", "*"):
                http_res_text = utils.stream_to_text(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "5XX", "*"):
                http_res_text = utils.stream_to_text(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "default", "application/json"):
                return unmarshal_json_response(
                    credentials.Credential, http_res, validate=False
                )

            raise errors.GenAiDefaultError("Unexpected response received", http_res)

        _speakeasy_hook_ctx = HookContext(
            config=self.sdk_configuration,
            base_url=base_url or "",
            operation_id="GetCredential",
            oauth2_scopes=None,
            security_source=get_security_from_env(
                self.sdk_configuration.security, types.Security
            ),
            tags=["credentials"],
            extensions=None,
            response=ResponseContext(mode=_speakeasy_response_mode, execution="sync"),
        )
        http_res = self.do_request(
            hook_ctx=_speakeasy_hook_ctx,
            request=req,
            is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
            stream=_speakeasy_response_mode == "streaming",
            retry_config=retry_config,
        )
        if _speakeasy_response_mode != "parsed":
            if utils.match_status_codes(["4XX", "5XX"], http_res.status_code):
                http_res.read()
                try:
                    _speakeasy_parse_response(http_res)
                except Exception as parse_exc_:
                    response_helpers.raise_parse_error(
                        self.sdk_configuration.__dict__["_hooks"],
                        AfterParseErrorContext(_speakeasy_hook_ctx),
                        http_res,
                        parse_exc_,
                    )
            _speakeasy_response_cls = (
                response_helpers.StreamedAPIResponse
                if _speakeasy_response_mode == "streaming"
                else response_helpers.APIResponse
            )
            return cast(
                Any,
                _speakeasy_response_cls(
                    raw=http_res,
                    parser=_speakeasy_parse_response,
                    mode="buffered",
                    client_ref=self,
                    hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
                    hooks=self.sdk_configuration.__dict__.get("_hooks"),
                ),
            )
        try:
            return _speakeasy_parse_response(http_res)
        except Exception as parse_exc_:
            response_helpers.raise_parse_error(
                self.sdk_configuration.__dict__["_hooks"],
                AfterParseErrorContext(_speakeasy_hook_ctx),
                http_res,
                parse_exc_,
            )

    @overload
    def update(
        self,
        id: str,
        *,
        request: Union[
            models.UpdateCredentialRequest, models.UpdateCredentialRequestParam
        ],
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Updates a credential.

        :param id: Required. Resource ID segment making up resource `name`. It identifies the resource
            within its parent collection as described in https://google.aip.dev/122.
        :param body: Required. The request body.
        :param api_version: API version for request routing.
        :param update_mask: Optional. The list of fields to update.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    @overload
    def update(
        self,
        id: str,
        *,
        api_version: Optional[str] = None,
        update_mask: Optional[str] = None,
        client_id: str = ...,
        client_secret: str = ...,
        refresh_token: str = ...,
        scopes: List[str] = ...,
        token_url: str = ...,
        type_: Literal["oauth2"],
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Updates a credential.

        :param api_version: API version for request routing.
        :param update_mask: Optional. The list of fields to update.
        :param client_id: Optional. OAuth2 client ID.
        :param client_secret: Optional. Input only. OAuth2 client secret. Write-only; never returned in responses.
        :param refresh_token: Optional. Input only. OAuth2 refresh token. Write-only; never returned in responses.
        :param scopes: Optional. List of OAuth2 scopes.
        :param token_url: Optional. OAuth2 token endpoint URL for refreshing access tokens.
        :param type:
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    @overload
    def update(
        self,
        id: str,
        *,
        api_version: Optional[str] = None,
        update_mask: Optional[str] = None,
        injection_location: credentials.EnvironmentVariableUpdateConfigInjectionLocationParam = ...,
        trusted_domains: List[str] = ...,
        type_: Literal["environment_variable"],
        value: str = ...,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Updates a credential.

        :param api_version: API version for request routing.
        :param update_mask: Optional. The list of fields to update.
        :param injection_location: Optional. Locations where the environment variable can be injected in
            outgoing HTTP requests.
            Accepts either a single location (e.g. \"header\") or an array of locations.
        :param trusted_domains: Optional. List of domains allowed to receive this environment variable
            value in HTTP requests.
        :param type:
        :param value: Optional. Input only. Secret value of the environment variable. Write-only; never
            returned in responses.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    @overload
    def update(
        self,
        id: str,
        *,
        api_version: Optional[str] = None,
        update_mask: Optional[str] = None,
        header_name: str = ...,
        prefix: str = ...,
        token: str = ...,
        type_: Literal["bearer_token"],
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Updates a credential.

        :param api_version: API version for request routing.
        :param update_mask: Optional. The list of fields to update.
        :param header_name: Optional. Header name to inject the token into. Defaults to
            'Authorization'.
        :param prefix: Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
            for no prefix.
        :param token: Optional. Input only. The static bearer token. Write-only; never returned in responses.
        :param type:
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    @overload
    def update(
        self,
        id: str,
        *,
        request: OptionalNullable[
            Union[models.UpdateCredentialRequest, models.UpdateCredentialRequestParam]
        ] = UNSET,
        api_version: OptionalNullable[str] = UNSET,
        update_mask: OptionalNullable[str] = UNSET,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
        **body_kwargs: Any,
    ) -> credentials.Credential:
        r"""Updates a credential.

        :param api_version: API version for request routing.
        :param update_mask: Optional. The list of fields to update.
        :param client_id: Optional. OAuth2 client ID.
        :param client_secret: Optional. Input only. OAuth2 client secret. Write-only; never returned in responses.
        :param refresh_token: Optional. Input only. OAuth2 refresh token. Write-only; never returned in responses.
        :param scopes: Optional. List of OAuth2 scopes.
        :param token_url: Optional. OAuth2 token endpoint URL for refreshing access tokens.
        :param type:
        :param injection_location: Optional. Locations where the environment variable can be injected in
            outgoing HTTP requests.
            Accepts either a single location (e.g. \"header\") or an array of locations.
        :param trusted_domains: Optional. List of domains allowed to receive this environment variable
            value in HTTP requests.
        :param value: Optional. Input only. Secret value of the environment variable. Write-only; never
            returned in responses.
        :param header_name: Optional. Header name to inject the token into. Defaults to
            'Authorization'.
        :param prefix: Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
            for no prefix.
        :param token: Optional. Input only. The static bearer token. Write-only; never returned in responses.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    def update(
        self,
        id: str,
        *,
        request: OptionalNullable[
            Union[models.UpdateCredentialRequest, models.UpdateCredentialRequestParam]
        ] = UNSET,
        api_version: OptionalNullable[str] = UNSET,
        update_mask: OptionalNullable[str] = UNSET,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
        **body_kwargs: Any,
    ) -> credentials.Credential:
        r"""Updates a credential.

        :param api_version: API version for request routing.
        :param update_mask: Optional. The list of fields to update.
        :param client_id: Optional. OAuth2 client ID.
        :param client_secret: Optional. Input only. OAuth2 client secret. Write-only; never returned in responses.
        :param refresh_token: Optional. Input only. OAuth2 refresh token. Write-only; never returned in responses.
        :param scopes: Optional. List of OAuth2 scopes.
        :param token_url: Optional. OAuth2 token endpoint URL for refreshing access tokens.
        :param type:
        :param injection_location: Optional. Locations where the environment variable can be injected in
            outgoing HTTP requests.
            Accepts either a single location (e.g. \"header\") or an array of locations.
        :param trusted_domains: Optional. List of domains allowed to receive this environment variable
            value in HTTP requests.
        :param value: Optional. Input only. Secret value of the environment variable. Write-only; never
            returned in responses.
        :param header_name: Optional. Header name to inject the token into. Defaults to
            'Authorization'.
        :param prefix: Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
            for no prefix.
        :param token: Optional. Input only. The static bearer token. Write-only; never returned in responses.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """
        if "client_id" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'injection_location'.")
        if "client_id" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'trusted_domains'.")
        if "client_id" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'value'.")
        if "client_id" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'header_name'.")
        if "client_id" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'prefix'.")
        if "client_id" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'token'.")
        if "client_secret" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'client_secret' and 'injection_location'."
            )
        if "client_secret" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'client_secret' and 'trusted_domains'."
            )
        if "client_secret" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'client_secret' and 'value'.")
        if "client_secret" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'client_secret' and 'header_name'.")
        if "client_secret" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'client_secret' and 'prefix'.")
        if "client_secret" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'client_secret' and 'token'.")
        if "refresh_token" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'refresh_token' and 'injection_location'."
            )
        if "refresh_token" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'refresh_token' and 'trusted_domains'."
            )
        if "refresh_token" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'refresh_token' and 'value'.")
        if "refresh_token" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'refresh_token' and 'header_name'.")
        if "refresh_token" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'refresh_token' and 'prefix'.")
        if "refresh_token" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'refresh_token' and 'token'.")
        if "scopes" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'injection_location'.")
        if "scopes" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'trusted_domains'.")
        if "scopes" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'value'.")
        if "scopes" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'header_name'.")
        if "scopes" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'prefix'.")
        if "scopes" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'token'.")
        if "token_url" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'injection_location'.")
        if "token_url" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'trusted_domains'.")
        if "token_url" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'value'.")
        if "token_url" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'header_name'.")
        if "token_url" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'prefix'.")
        if "token_url" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'token'.")
        if "injection_location" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'injection_location' and 'header_name'."
            )
        if "injection_location" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'injection_location' and 'prefix'.")
        if "injection_location" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'injection_location' and 'token'.")
        if "trusted_domains" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'trusted_domains' and 'header_name'.")
        if "trusted_domains" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'trusted_domains' and 'prefix'.")
        if "trusted_domains" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'trusted_domains' and 'token'.")
        if "value" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'value' and 'header_name'.")
        if "value" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'value' and 'prefix'.")
        if "value" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'value' and 'token'.")
        base_url = None
        url_variables = None
        retries: OptionalNullable[utils.RetryConfig] = UNSET
        server_url = None
        http_headers = extra_headers
        timeout_ms = self._coerce_timeout_ms(timeout)
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        if request is not UNSET:
            request = cast(
                models.UpdateCredentialRequest,
                request
                if isinstance(request, BaseModel)
                else utils.unmarshal(
                    cast(Any, request), models.UpdateCredentialRequest
                ),
            )
        else:
            _body_kwargs = dict(body_kwargs)
            _body_kwargs = {k: v for k, v in _body_kwargs.items() if v is not UNSET}
            _request_kwargs: dict[str, Any] = {
                "api_version": api_version,
                "id": id,
                "update_mask": update_mask,
            }
            _request_kwargs = {
                k: v for k, v in _request_kwargs.items() if v is not UNSET
            }
            _request_kwargs["body"] = _body_kwargs
            request = cast(
                models.UpdateCredentialRequest,
                utils.unmarshal(_request_kwargs, models.UpdateCredentialRequest),
            )

        _speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
            http_headers
        )
        req = self._build_request(
            method="PATCH",
            path="/{api_version}/credentials/{id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            extra_query_params=extra_query,
            _globals=models.UpdateCredentialGlobals(
                api_version=self.sdk_configuration.globals.api_version,
            ),
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.body,
                False,
                False,
                "json",
                credentials.CredentialUpdate,
                extra_body=extra_body,
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "attempt-count-backoff",
                    utils.BackoffStrategy(500, 8000, 2, 30000),
                    True,
                    max_retries=4,
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["408", "409", "429", "5XX"])

        def _speakeasy_parse_response(http_res):
            if utils.match_response(http_res, "4XX", "*"):
                http_res_text = utils.stream_to_text(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "5XX", "*"):
                http_res_text = utils.stream_to_text(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "default", "application/json"):
                return unmarshal_json_response(
                    credentials.Credential, http_res, validate=False
                )

            raise errors.GenAiDefaultError("Unexpected response received", http_res)

        _speakeasy_hook_ctx = HookContext(
            config=self.sdk_configuration,
            base_url=base_url or "",
            operation_id="UpdateCredential",
            oauth2_scopes=None,
            security_source=get_security_from_env(
                self.sdk_configuration.security, types.Security
            ),
            tags=["credentials"],
            extensions=None,
            response=ResponseContext(mode=_speakeasy_response_mode, execution="sync"),
        )
        http_res = self.do_request(
            hook_ctx=_speakeasy_hook_ctx,
            request=req,
            is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
            stream=_speakeasy_response_mode == "streaming",
            retry_config=retry_config,
        )
        if _speakeasy_response_mode != "parsed":
            if utils.match_status_codes(["4XX", "5XX"], http_res.status_code):
                http_res.read()
                try:
                    _speakeasy_parse_response(http_res)
                except Exception as parse_exc_:
                    response_helpers.raise_parse_error(
                        self.sdk_configuration.__dict__["_hooks"],
                        AfterParseErrorContext(_speakeasy_hook_ctx),
                        http_res,
                        parse_exc_,
                    )
            _speakeasy_response_cls = (
                response_helpers.StreamedAPIResponse
                if _speakeasy_response_mode == "streaming"
                else response_helpers.APIResponse
            )
            return cast(
                Any,
                _speakeasy_response_cls(
                    raw=http_res,
                    parser=_speakeasy_parse_response,
                    mode="buffered",
                    client_ref=self,
                    hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
                    hooks=self.sdk_configuration.__dict__.get("_hooks"),
                ),
            )
        try:
            return _speakeasy_parse_response(http_res)
        except Exception as parse_exc_:
            response_helpers.raise_parse_error(
                self.sdk_configuration.__dict__["_hooks"],
                AfterParseErrorContext(_speakeasy_hook_ctx),
                http_res,
                parse_exc_,
            )


class CredentialsWithRawResponse:
    def __init__(self, sdk: Credentials) -> None:
        self._sdk = sdk
        self.list = response_helpers.to_raw_response_wrapper(sdk.list, "extra_headers")
        self.create = response_helpers.to_raw_response_wrapper(
            sdk.create, "extra_headers"
        )
        self.delete = response_helpers.to_raw_response_wrapper(
            sdk.delete, "extra_headers"
        )
        self.get = response_helpers.to_raw_response_wrapper(sdk.get, "extra_headers")
        self.update = response_helpers.to_raw_response_wrapper(
            sdk.update, "extra_headers"
        )


class CredentialsWithStreamingResponse:
    def __init__(self, sdk: Credentials) -> None:
        self._sdk = sdk
        self.list = response_helpers.to_streamed_response_wrapper(
            sdk.list, "extra_headers"
        )
        self.create = response_helpers.to_streamed_response_wrapper(
            sdk.create, "extra_headers"
        )
        self.delete = response_helpers.to_streamed_response_wrapper(
            sdk.delete, "extra_headers"
        )
        self.get = response_helpers.to_streamed_response_wrapper(
            sdk.get, "extra_headers"
        )
        self.update = response_helpers.to_streamed_response_wrapper(
            sdk.update, "extra_headers"
        )


class AsyncCredentials(AsyncBaseSDK):
    @property
    def with_raw_response(self):
        return AsyncCredentialsWithRawResponse(self)

    @property
    def with_streaming_response(self):
        return AsyncCredentialsWithStreamingResponse(self)

    async def list(
        self,
        *,
        api_version: Optional[str] = None,
        page_size: Optional[int] = None,
        page_token: Optional[str] = None,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.CredentialListResponse:
        r"""Lists credentials.

        :param api_version: API version for request routing.
        :param page_size: Optional. Maximum number of credentials to return.
        :param page_token: Optional. Pagination token.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """
        base_url = None
        url_variables = None
        retries: OptionalNullable[utils.RetryConfig] = UNSET
        server_url = None
        http_headers = extra_headers
        timeout_ms = self._coerce_timeout_ms(timeout)
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.ListCredentialsRequest(
            api_version=api_version,
            page_size=page_size,
            page_token=page_token,
        )

        _speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
            http_headers
        )
        req = self._build_request_async(
            method="GET",
            path="/{api_version}/credentials",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            extra_query_params=extra_query,
            _globals=models.ListCredentialsGlobals(
                api_version=self.sdk_configuration.globals.api_version,
            ),
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "attempt-count-backoff",
                    utils.BackoffStrategy(500, 8000, 2, 30000),
                    True,
                    max_retries=4,
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["408", "409", "429", "5XX"])

        async def _speakeasy_parse_response(http_res):
            if utils.match_response(http_res, "4XX", "*"):
                http_res_text = await utils.stream_to_text_async(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "5XX", "*"):
                http_res_text = await utils.stream_to_text_async(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "default", "application/json"):
                return unmarshal_json_response(
                    credentials.CredentialListResponse, http_res, validate=False
                )

            raise errors.GenAiDefaultError("Unexpected response received", http_res)

        _speakeasy_hook_ctx = HookContext(
            config=self.sdk_configuration,
            base_url=base_url or "",
            operation_id="ListCredentials",
            oauth2_scopes=None,
            security_source=get_security_from_env(
                self.sdk_configuration.security, types.Security
            ),
            tags=["credentials"],
            extensions=None,
            response=ResponseContext(mode=_speakeasy_response_mode, execution="async"),
        )
        http_res = await self.do_request_async(
            hook_ctx=_speakeasy_hook_ctx,
            request=req,
            is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
            stream=_speakeasy_response_mode == "streaming",
            retry_config=retry_config,
        )
        if _speakeasy_response_mode != "parsed":
            if utils.match_status_codes(["4XX", "5XX"], http_res.status_code):
                await http_res.aread()
                try:
                    await _speakeasy_parse_response(http_res)
                except Exception as parse_exc_:
                    await response_helpers.raise_parse_error_async(
                        self.sdk_configuration.__dict__.get("_async_hooks"),
                        self.sdk_configuration.__dict__.get("_hooks"),
                        AfterParseErrorContext(_speakeasy_hook_ctx),
                        http_res,
                        parse_exc_,
                    )
            _speakeasy_response_cls = (
                response_helpers.AsyncStreamedAPIResponse
                if _speakeasy_response_mode == "streaming"
                else response_helpers.AsyncAPIResponse
            )
            return cast(
                Any,
                _speakeasy_response_cls(
                    raw=http_res,
                    parser=_speakeasy_parse_response,
                    mode="buffered",
                    client_ref=self,
                    hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
                    hooks=self.sdk_configuration.__dict__.get("_hooks"),
                    async_hooks=self.sdk_configuration.__dict__.get("_async_hooks"),
                ),
            )
        try:
            return await _speakeasy_parse_response(http_res)
        except Exception as parse_exc_:
            await response_helpers.raise_parse_error_async(
                self.sdk_configuration.__dict__.get("_async_hooks"),
                self.sdk_configuration.__dict__.get("_hooks"),
                AfterParseErrorContext(_speakeasy_hook_ctx),
                http_res,
                parse_exc_,
            )

    @overload
    async def create(
        self,
        *,
        request: Union[
            models.CreateCredentialRequest, models.CreateCredentialRequestParam
        ],
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Creates a new credential.

        :param body: Required. The request body.
        :param api_version: API version for request routing.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    @overload
    async def create(
        self,
        *,
        api_version: Optional[str] = None,
        client_id: str,
        client_secret: str,
        id: str,
        refresh_token: str,
        scopes: List[str] = ...,
        token_url: str,
        type_: Literal["oauth2"],
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Creates a new credential.

        :param api_version: API version for request routing.
        :param client_id: Required. OAuth2 client ID.
        :param client_secret: Required. Input only. OAuth2 client secret. Write-only; never returned in responses.
        :param id:
        :param refresh_token: Required. Input only. OAuth2 refresh token. Write-only; never returned in responses.
        :param scopes: Optional. List of OAuth2 scopes.
        :param token_url: Required. OAuth2 token endpoint URL for refreshing access tokens.
        :param type:
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    @overload
    async def create(
        self,
        *,
        api_version: Optional[str] = None,
        id: str,
        injection_location: credentials.EnvironmentVariableConfigInjectionLocationParam,
        trusted_domains: List[str] = ...,
        type_: Literal["environment_variable"],
        value: str,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Creates a new credential.

        :param api_version: API version for request routing.
        :param id:
        :param injection_location: Required. Locations where the environment variable can be injected in
            outgoing HTTP requests. Must contain at least one location.
            Accepts either a single location (e.g. \"header\") or an array of locations.
        :param trusted_domains: Optional. List of domains allowed to receive this environment variable
            value in HTTP requests.
        :param type:
        :param value: Required. Input only. Secret value of the environment variable. Write-only; never
            returned in responses.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    @overload
    async def create(
        self,
        *,
        api_version: Optional[str] = None,
        header_name: str = ...,
        id: str,
        prefix: str = ...,
        token: str,
        type_: Literal["bearer_token"],
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Creates a new credential.

        :param api_version: API version for request routing.
        :param header_name: Optional. Header name to inject the token into. Defaults to
            'Authorization'.
        :param id:
        :param prefix: Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
            for no prefix.
        :param token: Required. Input only. The static bearer token. Write-only; never returned in responses.
        :param type:
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    @overload
    async def create(
        self,
        *,
        request: OptionalNullable[
            Union[models.CreateCredentialRequest, models.CreateCredentialRequestParam]
        ] = UNSET,
        api_version: OptionalNullable[str] = UNSET,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
        **body_kwargs: Any,
    ) -> credentials.Credential:
        r"""Creates a new credential.

        :param api_version: API version for request routing.
        :param client_id: Required. OAuth2 client ID.
        :param client_secret: Required. Input only. OAuth2 client secret. Write-only; never returned in responses.
        :param id:
        :param refresh_token: Required. Input only. OAuth2 refresh token. Write-only; never returned in responses.
        :param scopes: Optional. List of OAuth2 scopes.
        :param token_url: Required. OAuth2 token endpoint URL for refreshing access tokens.
        :param type:
        :param injection_location: Required. Locations where the environment variable can be injected in
            outgoing HTTP requests. Must contain at least one location.
            Accepts either a single location (e.g. \"header\") or an array of locations.
        :param trusted_domains: Optional. List of domains allowed to receive this environment variable
            value in HTTP requests.
        :param value: Required. Input only. Secret value of the environment variable. Write-only; never
            returned in responses.
        :param header_name: Optional. Header name to inject the token into. Defaults to
            'Authorization'.
        :param prefix: Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
            for no prefix.
        :param token: Required. Input only. The static bearer token. Write-only; never returned in responses.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    async def create(
        self,
        *,
        request: OptionalNullable[
            Union[models.CreateCredentialRequest, models.CreateCredentialRequestParam]
        ] = UNSET,
        api_version: OptionalNullable[str] = UNSET,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
        **body_kwargs: Any,
    ) -> credentials.Credential:
        r"""Creates a new credential.

        :param api_version: API version for request routing.
        :param client_id: Required. OAuth2 client ID.
        :param client_secret: Required. Input only. OAuth2 client secret. Write-only; never returned in responses.
        :param id:
        :param refresh_token: Required. Input only. OAuth2 refresh token. Write-only; never returned in responses.
        :param scopes: Optional. List of OAuth2 scopes.
        :param token_url: Required. OAuth2 token endpoint URL for refreshing access tokens.
        :param type:
        :param injection_location: Required. Locations where the environment variable can be injected in
            outgoing HTTP requests. Must contain at least one location.
            Accepts either a single location (e.g. \"header\") or an array of locations.
        :param trusted_domains: Optional. List of domains allowed to receive this environment variable
            value in HTTP requests.
        :param value: Required. Input only. Secret value of the environment variable. Write-only; never
            returned in responses.
        :param header_name: Optional. Header name to inject the token into. Defaults to
            'Authorization'.
        :param prefix: Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
            for no prefix.
        :param token: Required. Input only. The static bearer token. Write-only; never returned in responses.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """
        if "client_id" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'injection_location'.")
        if "client_id" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'trusted_domains'.")
        if "client_id" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'value'.")
        if "client_id" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'header_name'.")
        if "client_id" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'prefix'.")
        if "client_id" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'token'.")
        if "client_secret" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'client_secret' and 'injection_location'."
            )
        if "client_secret" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'client_secret' and 'trusted_domains'."
            )
        if "client_secret" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'client_secret' and 'value'.")
        if "client_secret" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'client_secret' and 'header_name'.")
        if "client_secret" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'client_secret' and 'prefix'.")
        if "client_secret" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'client_secret' and 'token'.")
        if "refresh_token" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'refresh_token' and 'injection_location'."
            )
        if "refresh_token" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'refresh_token' and 'trusted_domains'."
            )
        if "refresh_token" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'refresh_token' and 'value'.")
        if "refresh_token" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'refresh_token' and 'header_name'.")
        if "refresh_token" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'refresh_token' and 'prefix'.")
        if "refresh_token" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'refresh_token' and 'token'.")
        if "scopes" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'injection_location'.")
        if "scopes" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'trusted_domains'.")
        if "scopes" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'value'.")
        if "scopes" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'header_name'.")
        if "scopes" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'prefix'.")
        if "scopes" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'token'.")
        if "token_url" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'injection_location'.")
        if "token_url" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'trusted_domains'.")
        if "token_url" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'value'.")
        if "token_url" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'header_name'.")
        if "token_url" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'prefix'.")
        if "token_url" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'token'.")
        if "injection_location" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'injection_location' and 'header_name'."
            )
        if "injection_location" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'injection_location' and 'prefix'.")
        if "injection_location" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'injection_location' and 'token'.")
        if "trusted_domains" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'trusted_domains' and 'header_name'.")
        if "trusted_domains" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'trusted_domains' and 'prefix'.")
        if "trusted_domains" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'trusted_domains' and 'token'.")
        if "value" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'value' and 'header_name'.")
        if "value" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'value' and 'prefix'.")
        if "value" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'value' and 'token'.")
        base_url = None
        url_variables = None
        retries: OptionalNullable[utils.RetryConfig] = UNSET
        server_url = None
        http_headers = extra_headers
        timeout_ms = self._coerce_timeout_ms(timeout)
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        if request is not UNSET:
            request = cast(
                models.CreateCredentialRequest,
                request
                if isinstance(request, BaseModel)
                else utils.unmarshal(
                    cast(Any, request), models.CreateCredentialRequest
                ),
            )
        else:
            _body_kwargs = dict(body_kwargs)
            _body_kwargs = {k: v for k, v in _body_kwargs.items() if v is not UNSET}
            _request_kwargs: dict[str, Any] = {"api_version": api_version}
            _request_kwargs = {
                k: v for k, v in _request_kwargs.items() if v is not UNSET
            }
            _request_kwargs["body"] = _body_kwargs
            request = cast(
                models.CreateCredentialRequest,
                utils.unmarshal(_request_kwargs, models.CreateCredentialRequest),
            )

        _speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
            http_headers
        )
        req = self._build_request_async(
            method="POST",
            path="/{api_version}/credentials",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            extra_query_params=extra_query,
            _globals=models.CreateCredentialGlobals(
                api_version=self.sdk_configuration.globals.api_version,
            ),
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.body,
                False,
                False,
                "json",
                credentials.CredentialCreateParams,
                extra_body=extra_body,
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "attempt-count-backoff",
                    utils.BackoffStrategy(500, 8000, 2, 30000),
                    True,
                    max_retries=4,
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["408", "409", "429", "5XX"])

        async def _speakeasy_parse_response(http_res):
            if utils.match_response(http_res, "4XX", "*"):
                http_res_text = await utils.stream_to_text_async(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "5XX", "*"):
                http_res_text = await utils.stream_to_text_async(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "default", "application/json"):
                return unmarshal_json_response(
                    credentials.Credential, http_res, validate=False
                )

            raise errors.GenAiDefaultError("Unexpected response received", http_res)

        _speakeasy_hook_ctx = HookContext(
            config=self.sdk_configuration,
            base_url=base_url or "",
            operation_id="CreateCredential",
            oauth2_scopes=None,
            security_source=get_security_from_env(
                self.sdk_configuration.security, types.Security
            ),
            tags=["credentials"],
            extensions=None,
            response=ResponseContext(mode=_speakeasy_response_mode, execution="async"),
        )
        http_res = await self.do_request_async(
            hook_ctx=_speakeasy_hook_ctx,
            request=req,
            is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
            stream=_speakeasy_response_mode == "streaming",
            retry_config=retry_config,
        )
        if _speakeasy_response_mode != "parsed":
            if utils.match_status_codes(["4XX", "5XX"], http_res.status_code):
                await http_res.aread()
                try:
                    await _speakeasy_parse_response(http_res)
                except Exception as parse_exc_:
                    await response_helpers.raise_parse_error_async(
                        self.sdk_configuration.__dict__.get("_async_hooks"),
                        self.sdk_configuration.__dict__.get("_hooks"),
                        AfterParseErrorContext(_speakeasy_hook_ctx),
                        http_res,
                        parse_exc_,
                    )
            _speakeasy_response_cls = (
                response_helpers.AsyncStreamedAPIResponse
                if _speakeasy_response_mode == "streaming"
                else response_helpers.AsyncAPIResponse
            )
            return cast(
                Any,
                _speakeasy_response_cls(
                    raw=http_res,
                    parser=_speakeasy_parse_response,
                    mode="buffered",
                    client_ref=self,
                    hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
                    hooks=self.sdk_configuration.__dict__.get("_hooks"),
                    async_hooks=self.sdk_configuration.__dict__.get("_async_hooks"),
                ),
            )
        try:
            return await _speakeasy_parse_response(http_res)
        except Exception as parse_exc_:
            await response_helpers.raise_parse_error_async(
                self.sdk_configuration.__dict__.get("_async_hooks"),
                self.sdk_configuration.__dict__.get("_hooks"),
                AfterParseErrorContext(_speakeasy_hook_ctx),
                http_res,
                parse_exc_,
            )

    async def delete(
        self,
        id: str,
        *,
        api_version: Optional[str] = None,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> interactions.Empty:
        r"""Deletes a credential.

        :param id: Required. Resource ID segment making up resource `name`. It identifies the resource
            within its parent collection as described in https://google.aip.dev/122.
        :param api_version: API version for request routing.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """
        base_url = None
        url_variables = None
        retries: OptionalNullable[utils.RetryConfig] = UNSET
        server_url = None
        http_headers = extra_headers
        timeout_ms = self._coerce_timeout_ms(timeout)
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.DeleteCredentialRequest(
            api_version=api_version,
            id=id,
        )

        _speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
            http_headers
        )
        req = self._build_request_async(
            method="DELETE",
            path="/{api_version}/credentials/{id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            extra_query_params=extra_query,
            _globals=models.DeleteCredentialGlobals(
                api_version=self.sdk_configuration.globals.api_version,
            ),
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "attempt-count-backoff",
                    utils.BackoffStrategy(500, 8000, 2, 30000),
                    True,
                    max_retries=4,
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["408", "409", "429", "5XX"])

        async def _speakeasy_parse_response(http_res):
            if utils.match_response(http_res, "4XX", "*"):
                http_res_text = await utils.stream_to_text_async(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "5XX", "*"):
                http_res_text = await utils.stream_to_text_async(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "default", "application/json"):
                return unmarshal_json_response(
                    interactions.Empty, http_res, validate=False
                )

            raise errors.GenAiDefaultError("Unexpected response received", http_res)

        _speakeasy_hook_ctx = HookContext(
            config=self.sdk_configuration,
            base_url=base_url or "",
            operation_id="DeleteCredential",
            oauth2_scopes=None,
            security_source=get_security_from_env(
                self.sdk_configuration.security, types.Security
            ),
            tags=["credentials"],
            extensions=None,
            response=ResponseContext(mode=_speakeasy_response_mode, execution="async"),
        )
        http_res = await self.do_request_async(
            hook_ctx=_speakeasy_hook_ctx,
            request=req,
            is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
            stream=_speakeasy_response_mode == "streaming",
            retry_config=retry_config,
        )
        if _speakeasy_response_mode != "parsed":
            if utils.match_status_codes(["4XX", "5XX"], http_res.status_code):
                await http_res.aread()
                try:
                    await _speakeasy_parse_response(http_res)
                except Exception as parse_exc_:
                    await response_helpers.raise_parse_error_async(
                        self.sdk_configuration.__dict__.get("_async_hooks"),
                        self.sdk_configuration.__dict__.get("_hooks"),
                        AfterParseErrorContext(_speakeasy_hook_ctx),
                        http_res,
                        parse_exc_,
                    )
            _speakeasy_response_cls = (
                response_helpers.AsyncStreamedAPIResponse
                if _speakeasy_response_mode == "streaming"
                else response_helpers.AsyncAPIResponse
            )
            return cast(
                Any,
                _speakeasy_response_cls(
                    raw=http_res,
                    parser=_speakeasy_parse_response,
                    mode="buffered",
                    client_ref=self,
                    hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
                    hooks=self.sdk_configuration.__dict__.get("_hooks"),
                    async_hooks=self.sdk_configuration.__dict__.get("_async_hooks"),
                ),
            )
        try:
            return await _speakeasy_parse_response(http_res)
        except Exception as parse_exc_:
            await response_helpers.raise_parse_error_async(
                self.sdk_configuration.__dict__.get("_async_hooks"),
                self.sdk_configuration.__dict__.get("_hooks"),
                AfterParseErrorContext(_speakeasy_hook_ctx),
                http_res,
                parse_exc_,
            )

    async def get(
        self,
        id: str,
        *,
        api_version: Optional[str] = None,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Gets a credential by ID.

        :param id: Required. Resource ID segment making up resource `name`. It identifies the resource
            within its parent collection as described in https://google.aip.dev/122.
        :param api_version: API version for request routing.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """
        base_url = None
        url_variables = None
        retries: OptionalNullable[utils.RetryConfig] = UNSET
        server_url = None
        http_headers = extra_headers
        timeout_ms = self._coerce_timeout_ms(timeout)
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.GetCredentialRequest(
            api_version=api_version,
            id=id,
        )

        _speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
            http_headers
        )
        req = self._build_request_async(
            method="GET",
            path="/{api_version}/credentials/{id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            extra_query_params=extra_query,
            _globals=models.GetCredentialGlobals(
                api_version=self.sdk_configuration.globals.api_version,
            ),
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "attempt-count-backoff",
                    utils.BackoffStrategy(500, 8000, 2, 30000),
                    True,
                    max_retries=4,
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["408", "409", "429", "5XX"])

        async def _speakeasy_parse_response(http_res):
            if utils.match_response(http_res, "4XX", "*"):
                http_res_text = await utils.stream_to_text_async(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "5XX", "*"):
                http_res_text = await utils.stream_to_text_async(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "default", "application/json"):
                return unmarshal_json_response(
                    credentials.Credential, http_res, validate=False
                )

            raise errors.GenAiDefaultError("Unexpected response received", http_res)

        _speakeasy_hook_ctx = HookContext(
            config=self.sdk_configuration,
            base_url=base_url or "",
            operation_id="GetCredential",
            oauth2_scopes=None,
            security_source=get_security_from_env(
                self.sdk_configuration.security, types.Security
            ),
            tags=["credentials"],
            extensions=None,
            response=ResponseContext(mode=_speakeasy_response_mode, execution="async"),
        )
        http_res = await self.do_request_async(
            hook_ctx=_speakeasy_hook_ctx,
            request=req,
            is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
            stream=_speakeasy_response_mode == "streaming",
            retry_config=retry_config,
        )
        if _speakeasy_response_mode != "parsed":
            if utils.match_status_codes(["4XX", "5XX"], http_res.status_code):
                await http_res.aread()
                try:
                    await _speakeasy_parse_response(http_res)
                except Exception as parse_exc_:
                    await response_helpers.raise_parse_error_async(
                        self.sdk_configuration.__dict__.get("_async_hooks"),
                        self.sdk_configuration.__dict__.get("_hooks"),
                        AfterParseErrorContext(_speakeasy_hook_ctx),
                        http_res,
                        parse_exc_,
                    )
            _speakeasy_response_cls = (
                response_helpers.AsyncStreamedAPIResponse
                if _speakeasy_response_mode == "streaming"
                else response_helpers.AsyncAPIResponse
            )
            return cast(
                Any,
                _speakeasy_response_cls(
                    raw=http_res,
                    parser=_speakeasy_parse_response,
                    mode="buffered",
                    client_ref=self,
                    hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
                    hooks=self.sdk_configuration.__dict__.get("_hooks"),
                    async_hooks=self.sdk_configuration.__dict__.get("_async_hooks"),
                ),
            )
        try:
            return await _speakeasy_parse_response(http_res)
        except Exception as parse_exc_:
            await response_helpers.raise_parse_error_async(
                self.sdk_configuration.__dict__.get("_async_hooks"),
                self.sdk_configuration.__dict__.get("_hooks"),
                AfterParseErrorContext(_speakeasy_hook_ctx),
                http_res,
                parse_exc_,
            )

    @overload
    async def update(
        self,
        id: str,
        *,
        request: Union[
            models.UpdateCredentialRequest, models.UpdateCredentialRequestParam
        ],
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Updates a credential.

        :param id: Required. Resource ID segment making up resource `name`. It identifies the resource
            within its parent collection as described in https://google.aip.dev/122.
        :param body: Required. The request body.
        :param api_version: API version for request routing.
        :param update_mask: Optional. The list of fields to update.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    @overload
    async def update(
        self,
        id: str,
        *,
        api_version: Optional[str] = None,
        update_mask: Optional[str] = None,
        client_id: str = ...,
        client_secret: str = ...,
        refresh_token: str = ...,
        scopes: List[str] = ...,
        token_url: str = ...,
        type_: Literal["oauth2"],
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Updates a credential.

        :param api_version: API version for request routing.
        :param update_mask: Optional. The list of fields to update.
        :param client_id: Optional. OAuth2 client ID.
        :param client_secret: Optional. Input only. OAuth2 client secret. Write-only; never returned in responses.
        :param refresh_token: Optional. Input only. OAuth2 refresh token. Write-only; never returned in responses.
        :param scopes: Optional. List of OAuth2 scopes.
        :param token_url: Optional. OAuth2 token endpoint URL for refreshing access tokens.
        :param type:
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    @overload
    async def update(
        self,
        id: str,
        *,
        api_version: Optional[str] = None,
        update_mask: Optional[str] = None,
        injection_location: credentials.EnvironmentVariableUpdateConfigInjectionLocationParam = ...,
        trusted_domains: List[str] = ...,
        type_: Literal["environment_variable"],
        value: str = ...,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Updates a credential.

        :param api_version: API version for request routing.
        :param update_mask: Optional. The list of fields to update.
        :param injection_location: Optional. Locations where the environment variable can be injected in
            outgoing HTTP requests.
            Accepts either a single location (e.g. \"header\") or an array of locations.
        :param trusted_domains: Optional. List of domains allowed to receive this environment variable
            value in HTTP requests.
        :param type:
        :param value: Optional. Input only. Secret value of the environment variable. Write-only; never
            returned in responses.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    @overload
    async def update(
        self,
        id: str,
        *,
        api_version: Optional[str] = None,
        update_mask: Optional[str] = None,
        header_name: str = ...,
        prefix: str = ...,
        token: str = ...,
        type_: Literal["bearer_token"],
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
    ) -> credentials.Credential:
        r"""Updates a credential.

        :param api_version: API version for request routing.
        :param update_mask: Optional. The list of fields to update.
        :param header_name: Optional. Header name to inject the token into. Defaults to
            'Authorization'.
        :param prefix: Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
            for no prefix.
        :param token: Optional. Input only. The static bearer token. Write-only; never returned in responses.
        :param type:
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    @overload
    async def update(
        self,
        id: str,
        *,
        request: OptionalNullable[
            Union[models.UpdateCredentialRequest, models.UpdateCredentialRequestParam]
        ] = UNSET,
        api_version: OptionalNullable[str] = UNSET,
        update_mask: OptionalNullable[str] = UNSET,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
        **body_kwargs: Any,
    ) -> credentials.Credential:
        r"""Updates a credential.

        :param api_version: API version for request routing.
        :param update_mask: Optional. The list of fields to update.
        :param client_id: Optional. OAuth2 client ID.
        :param client_secret: Optional. Input only. OAuth2 client secret. Write-only; never returned in responses.
        :param refresh_token: Optional. Input only. OAuth2 refresh token. Write-only; never returned in responses.
        :param scopes: Optional. List of OAuth2 scopes.
        :param token_url: Optional. OAuth2 token endpoint URL for refreshing access tokens.
        :param type:
        :param injection_location: Optional. Locations where the environment variable can be injected in
            outgoing HTTP requests.
            Accepts either a single location (e.g. \"header\") or an array of locations.
        :param trusted_domains: Optional. List of domains allowed to receive this environment variable
            value in HTTP requests.
        :param value: Optional. Input only. Secret value of the environment variable. Write-only; never
            returned in responses.
        :param header_name: Optional. Header name to inject the token into. Defaults to
            'Authorization'.
        :param prefix: Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
            for no prefix.
        :param token: Optional. Input only. The static bearer token. Write-only; never returned in responses.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """

    async def update(
        self,
        id: str,
        *,
        request: OptionalNullable[
            Union[models.UpdateCredentialRequest, models.UpdateCredentialRequestParam]
        ] = UNSET,
        api_version: OptionalNullable[str] = UNSET,
        update_mask: OptionalNullable[str] = UNSET,
        extra_headers: Optional[Mapping[str, str]] = None,
        extra_query: Optional[Mapping[str, Any]] = None,
        extra_body: Optional[Mapping[str, Any]] = None,
        timeout: Optional[Union[float, httpx.Timeout]] = None,
        **body_kwargs: Any,
    ) -> credentials.Credential:
        r"""Updates a credential.

        :param api_version: API version for request routing.
        :param update_mask: Optional. The list of fields to update.
        :param client_id: Optional. OAuth2 client ID.
        :param client_secret: Optional. Input only. OAuth2 client secret. Write-only; never returned in responses.
        :param refresh_token: Optional. Input only. OAuth2 refresh token. Write-only; never returned in responses.
        :param scopes: Optional. List of OAuth2 scopes.
        :param token_url: Optional. OAuth2 token endpoint URL for refreshing access tokens.
        :param type:
        :param injection_location: Optional. Locations where the environment variable can be injected in
            outgoing HTTP requests.
            Accepts either a single location (e.g. \"header\") or an array of locations.
        :param trusted_domains: Optional. List of domains allowed to receive this environment variable
            value in HTTP requests.
        :param value: Optional. Input only. Secret value of the environment variable. Write-only; never
            returned in responses.
        :param header_name: Optional. Header name to inject the token into. Defaults to
            'Authorization'.
        :param prefix: Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
            for no prefix.
        :param token: Optional. Input only. The static bearer token. Write-only; never returned in responses.
        :param extra_headers: Additional headers to set or replace on requests.
        :param extra_query: Additional query parameters to append to requests.
        :param extra_body: Additional JSON object fields to merge into request bodies.
        :param timeout: Override the default request timeout configuration for this method in seconds
        """
        if "client_id" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'injection_location'.")
        if "client_id" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'trusted_domains'.")
        if "client_id" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'value'.")
        if "client_id" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'header_name'.")
        if "client_id" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'prefix'.")
        if "client_id" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'client_id' and 'token'.")
        if "client_secret" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'client_secret' and 'injection_location'."
            )
        if "client_secret" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'client_secret' and 'trusted_domains'."
            )
        if "client_secret" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'client_secret' and 'value'.")
        if "client_secret" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'client_secret' and 'header_name'.")
        if "client_secret" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'client_secret' and 'prefix'.")
        if "client_secret" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'client_secret' and 'token'.")
        if "refresh_token" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'refresh_token' and 'injection_location'."
            )
        if "refresh_token" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'refresh_token' and 'trusted_domains'."
            )
        if "refresh_token" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'refresh_token' and 'value'.")
        if "refresh_token" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'refresh_token' and 'header_name'.")
        if "refresh_token" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'refresh_token' and 'prefix'.")
        if "refresh_token" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'refresh_token' and 'token'.")
        if "scopes" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'injection_location'.")
        if "scopes" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'trusted_domains'.")
        if "scopes" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'value'.")
        if "scopes" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'header_name'.")
        if "scopes" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'prefix'.")
        if "scopes" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'scopes' and 'token'.")
        if "token_url" in body_kwargs and "injection_location" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'injection_location'.")
        if "token_url" in body_kwargs and "trusted_domains" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'trusted_domains'.")
        if "token_url" in body_kwargs and "value" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'value'.")
        if "token_url" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'header_name'.")
        if "token_url" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'prefix'.")
        if "token_url" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'token_url' and 'token'.")
        if "injection_location" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError(
                "Cannot supply both 'injection_location' and 'header_name'."
            )
        if "injection_location" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'injection_location' and 'prefix'.")
        if "injection_location" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'injection_location' and 'token'.")
        if "trusted_domains" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'trusted_domains' and 'header_name'.")
        if "trusted_domains" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'trusted_domains' and 'prefix'.")
        if "trusted_domains" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'trusted_domains' and 'token'.")
        if "value" in body_kwargs and "header_name" in body_kwargs:
            raise ValueError("Cannot supply both 'value' and 'header_name'.")
        if "value" in body_kwargs and "prefix" in body_kwargs:
            raise ValueError("Cannot supply both 'value' and 'prefix'.")
        if "value" in body_kwargs and "token" in body_kwargs:
            raise ValueError("Cannot supply both 'value' and 'token'.")
        base_url = None
        url_variables = None
        retries: OptionalNullable[utils.RetryConfig] = UNSET
        server_url = None
        http_headers = extra_headers
        timeout_ms = self._coerce_timeout_ms(timeout)
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        if request is not UNSET:
            request = cast(
                models.UpdateCredentialRequest,
                request
                if isinstance(request, BaseModel)
                else utils.unmarshal(
                    cast(Any, request), models.UpdateCredentialRequest
                ),
            )
        else:
            _body_kwargs = dict(body_kwargs)
            _body_kwargs = {k: v for k, v in _body_kwargs.items() if v is not UNSET}
            _request_kwargs: dict[str, Any] = {
                "api_version": api_version,
                "id": id,
                "update_mask": update_mask,
            }
            _request_kwargs = {
                k: v for k, v in _request_kwargs.items() if v is not UNSET
            }
            _request_kwargs["body"] = _body_kwargs
            request = cast(
                models.UpdateCredentialRequest,
                utils.unmarshal(_request_kwargs, models.UpdateCredentialRequest),
            )

        _speakeasy_response_mode, http_headers = response_helpers.consume_response_mode(
            http_headers
        )
        req = self._build_request_async(
            method="PATCH",
            path="/{api_version}/credentials/{id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            extra_query_params=extra_query,
            _globals=models.UpdateCredentialGlobals(
                api_version=self.sdk_configuration.globals.api_version,
            ),
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.body,
                False,
                False,
                "json",
                credentials.CredentialUpdate,
                extra_body=extra_body,
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config
            else:
                retries = utils.RetryConfig(
                    "attempt-count-backoff",
                    utils.BackoffStrategy(500, 8000, 2, 30000),
                    True,
                    max_retries=4,
                )

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["408", "409", "429", "5XX"])

        async def _speakeasy_parse_response(http_res):
            if utils.match_response(http_res, "4XX", "*"):
                http_res_text = await utils.stream_to_text_async(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "5XX", "*"):
                http_res_text = await utils.stream_to_text_async(http_res)
                raise errors.GenAiDefaultError(
                    "API error occurred", http_res, http_res_text
                )
            if utils.match_response(http_res, "default", "application/json"):
                return unmarshal_json_response(
                    credentials.Credential, http_res, validate=False
                )

            raise errors.GenAiDefaultError("Unexpected response received", http_res)

        _speakeasy_hook_ctx = HookContext(
            config=self.sdk_configuration,
            base_url=base_url or "",
            operation_id="UpdateCredential",
            oauth2_scopes=None,
            security_source=get_security_from_env(
                self.sdk_configuration.security, types.Security
            ),
            tags=["credentials"],
            extensions=None,
            response=ResponseContext(mode=_speakeasy_response_mode, execution="async"),
        )
        http_res = await self.do_request_async(
            hook_ctx=_speakeasy_hook_ctx,
            request=req,
            is_error_status_code=lambda c: utils.match_status_codes(["4XX", "5XX"], c),
            stream=_speakeasy_response_mode == "streaming",
            retry_config=retry_config,
        )
        if _speakeasy_response_mode != "parsed":
            if utils.match_status_codes(["4XX", "5XX"], http_res.status_code):
                await http_res.aread()
                try:
                    await _speakeasy_parse_response(http_res)
                except Exception as parse_exc_:
                    await response_helpers.raise_parse_error_async(
                        self.sdk_configuration.__dict__.get("_async_hooks"),
                        self.sdk_configuration.__dict__.get("_hooks"),
                        AfterParseErrorContext(_speakeasy_hook_ctx),
                        http_res,
                        parse_exc_,
                    )
            _speakeasy_response_cls = (
                response_helpers.AsyncStreamedAPIResponse
                if _speakeasy_response_mode == "streaming"
                else response_helpers.AsyncAPIResponse
            )
            return cast(
                Any,
                _speakeasy_response_cls(
                    raw=http_res,
                    parser=_speakeasy_parse_response,
                    mode="buffered",
                    client_ref=self,
                    hook_ctx=AfterParseErrorContext(_speakeasy_hook_ctx),
                    hooks=self.sdk_configuration.__dict__.get("_hooks"),
                    async_hooks=self.sdk_configuration.__dict__.get("_async_hooks"),
                ),
            )
        try:
            return await _speakeasy_parse_response(http_res)
        except Exception as parse_exc_:
            await response_helpers.raise_parse_error_async(
                self.sdk_configuration.__dict__.get("_async_hooks"),
                self.sdk_configuration.__dict__.get("_hooks"),
                AfterParseErrorContext(_speakeasy_hook_ctx),
                http_res,
                parse_exc_,
            )


class AsyncCredentialsWithRawResponse:
    def __init__(self, sdk: AsyncCredentials) -> None:
        self._sdk = sdk
        self.list = response_helpers.async_to_raw_response_wrapper(
            sdk.list, "extra_headers"
        )
        self.create = response_helpers.async_to_raw_response_wrapper(
            sdk.create, "extra_headers"
        )
        self.delete = response_helpers.async_to_raw_response_wrapper(
            sdk.delete, "extra_headers"
        )
        self.get = response_helpers.async_to_raw_response_wrapper(
            sdk.get, "extra_headers"
        )
        self.update = response_helpers.async_to_raw_response_wrapper(
            sdk.update, "extra_headers"
        )


class AsyncCredentialsWithStreamingResponse:
    def __init__(self, sdk: AsyncCredentials) -> None:
        self._sdk = sdk
        self.list = response_helpers.async_to_streamed_response_wrapper(
            sdk.list, "extra_headers"
        )
        self.create = response_helpers.async_to_streamed_response_wrapper(
            sdk.create, "extra_headers"
        )
        self.delete = response_helpers.async_to_streamed_response_wrapper(
            sdk.delete, "extra_headers"
        )
        self.get = response_helpers.async_to_streamed_response_wrapper(
            sdk.get, "extra_headers"
        )
        self.update = response_helpers.async_to_streamed_response_wrapper(
            sdk.update, "extra_headers"
        )
