# This file was auto-generated by Fern from our API Definition.

import typing
from ..core.client_wrapper import SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.data_source import DataSource
from ..core.pydantic_utilities import parse_obj_as
from ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.http_validation_error import HttpValidationError
from json.decoder import JSONDecodeError
from ..core.api_error import ApiError
from ..types.configurable_data_source_names import ConfigurableDataSourceNames
from ..types.data_source_create_component import DataSourceCreateComponent
from ..types.data_source_create_custom_metadata_value import DataSourceCreateCustomMetadataValue
from ..core.serialization import convert_and_respect_annotation_metadata
from ..core.jsonable_encoder import jsonable_encoder
from .types.data_source_update_custom_metadata_value import DataSourceUpdateCustomMetadataValue
from .types.data_source_update_component import DataSourceUpdateComponent
from ..core.client_wrapper import AsyncClientWrapper

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class DataSourcesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def list_data_sources(
        self,
        *,
        project_id: typing.Optional[str] = None,
        organization_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[DataSource]:
        """
        List data sources for a given project.
        If project_id is not provided, uses the default project.

        Parameters
        ----------
        project_id : typing.Optional[str]

        organization_id : typing.Optional[str]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.List[DataSource]
            Successful Response

        Examples
        --------
        from llama_index import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.data_sources.list_data_sources()
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/v1/data-sources",
            method="GET",
            params={
                "project_id": project_id,
                "organization_id": organization_id,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    typing.List[DataSource],
                    parse_obj_as(
                        type_=typing.List[DataSource],  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def create_data_source(
        self,
        *,
        name: str,
        source_type: ConfigurableDataSourceNames,
        component: DataSourceCreateComponent,
        project_id: typing.Optional[str] = None,
        organization_id: typing.Optional[str] = None,
        custom_metadata: typing.Optional[typing.Dict[str, typing.Optional[DataSourceCreateCustomMetadataValue]]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DataSource:
        """
        Create a new data source.

        Parameters
        ----------
        name : str
            The name of the data source.

        source_type : ConfigurableDataSourceNames

        component : DataSourceCreateComponent
            Component that implements the data source

        project_id : typing.Optional[str]

        organization_id : typing.Optional[str]

        custom_metadata : typing.Optional[typing.Dict[str, typing.Optional[DataSourceCreateCustomMetadataValue]]]
            Custom metadata that will be present on all data loaded from the data source

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        DataSource
            Successful Response

        Examples
        --------
        from llama_index import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.data_sources.create_data_source(
            name="name",
            source_type="S3",
            component={"key": "value"},
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/v1/data-sources",
            method="POST",
            params={
                "project_id": project_id,
                "organization_id": organization_id,
            },
            json={
                "name": name,
                "source_type": source_type,
                "custom_metadata": convert_and_respect_annotation_metadata(
                    object_=custom_metadata,
                    annotation=typing.Dict[str, typing.Optional[DataSourceCreateCustomMetadataValue]],
                    direction="write",
                ),
                "component": convert_and_respect_annotation_metadata(
                    object_=component, annotation=DataSourceCreateComponent, direction="write"
                ),
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    DataSource,
                    parse_obj_as(
                        type_=DataSource,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def upsert_data_source(
        self,
        *,
        name: str,
        source_type: ConfigurableDataSourceNames,
        component: DataSourceCreateComponent,
        project_id: typing.Optional[str] = None,
        organization_id: typing.Optional[str] = None,
        custom_metadata: typing.Optional[typing.Dict[str, typing.Optional[DataSourceCreateCustomMetadataValue]]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DataSource:
        """
        Upserts a data source.
        Updates if a data source with the same name and project_id already exists. Otherwise, creates a new data source.

        Parameters
        ----------
        name : str
            The name of the data source.

        source_type : ConfigurableDataSourceNames

        component : DataSourceCreateComponent
            Component that implements the data source

        project_id : typing.Optional[str]

        organization_id : typing.Optional[str]

        custom_metadata : typing.Optional[typing.Dict[str, typing.Optional[DataSourceCreateCustomMetadataValue]]]
            Custom metadata that will be present on all data loaded from the data source

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        DataSource
            Successful Response

        Examples
        --------
        from llama_index import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.data_sources.upsert_data_source(
            name="name",
            source_type="S3",
            component={"key": "value"},
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/v1/data-sources",
            method="PUT",
            params={
                "project_id": project_id,
                "organization_id": organization_id,
            },
            json={
                "name": name,
                "source_type": source_type,
                "custom_metadata": convert_and_respect_annotation_metadata(
                    object_=custom_metadata,
                    annotation=typing.Dict[str, typing.Optional[DataSourceCreateCustomMetadataValue]],
                    direction="write",
                ),
                "component": convert_and_respect_annotation_metadata(
                    object_=component, annotation=DataSourceCreateComponent, direction="write"
                ),
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    DataSource,
                    parse_obj_as(
                        type_=DataSource,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def get_data_source(
        self, data_source_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DataSource:
        """
        Get a data source by ID.

        Parameters
        ----------
        data_source_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        DataSource
            Successful Response

        Examples
        --------
        from llama_index import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.data_sources.get_data_source(
            data_source_id="data_source_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/v1/data-sources/{jsonable_encoder(data_source_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    DataSource,
                    parse_obj_as(
                        type_=DataSource,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def update_data_source(
        self,
        data_source_id: str,
        *,
        source_type: ConfigurableDataSourceNames,
        name: typing.Optional[str] = OMIT,
        custom_metadata: typing.Optional[typing.Dict[str, typing.Optional[DataSourceUpdateCustomMetadataValue]]] = OMIT,
        component: typing.Optional[DataSourceUpdateComponent] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DataSource:
        """
        Update a data source by ID.

        Parameters
        ----------
        data_source_id : str

        source_type : ConfigurableDataSourceNames

        name : typing.Optional[str]
            The name of the data source.

        custom_metadata : typing.Optional[typing.Dict[str, typing.Optional[DataSourceUpdateCustomMetadataValue]]]
            Custom metadata that will be present on all data loaded from the data source

        component : typing.Optional[DataSourceUpdateComponent]
            Component that implements the data source

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        DataSource
            Successful Response

        Examples
        --------
        from llama_index import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.data_sources.update_data_source(
            data_source_id="data_source_id",
            source_type="S3",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/v1/data-sources/{jsonable_encoder(data_source_id)}",
            method="PUT",
            json={
                "name": name,
                "source_type": source_type,
                "custom_metadata": convert_and_respect_annotation_metadata(
                    object_=custom_metadata,
                    annotation=typing.Dict[str, typing.Optional[DataSourceUpdateCustomMetadataValue]],
                    direction="write",
                ),
                "component": convert_and_respect_annotation_metadata(
                    object_=component, annotation=DataSourceUpdateComponent, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    DataSource,
                    parse_obj_as(
                        type_=DataSource,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def delete_data_source(
        self, data_source_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete a data source by ID.

        Parameters
        ----------
        data_source_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        from llama_index import LlamaCloud

        client = LlamaCloud(
            token="YOUR_TOKEN",
        )
        client.data_sources.delete_data_source(
            data_source_id="data_source_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/v1/data-sources/{jsonable_encoder(data_source_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)


class AsyncDataSourcesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def list_data_sources(
        self,
        *,
        project_id: typing.Optional[str] = None,
        organization_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[DataSource]:
        """
        List data sources for a given project.
        If project_id is not provided, uses the default project.

        Parameters
        ----------
        project_id : typing.Optional[str]

        organization_id : typing.Optional[str]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.List[DataSource]
            Successful Response

        Examples
        --------
        import asyncio

        from llama_index import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.data_sources.list_data_sources()


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/v1/data-sources",
            method="GET",
            params={
                "project_id": project_id,
                "organization_id": organization_id,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    typing.List[DataSource],
                    parse_obj_as(
                        type_=typing.List[DataSource],  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def create_data_source(
        self,
        *,
        name: str,
        source_type: ConfigurableDataSourceNames,
        component: DataSourceCreateComponent,
        project_id: typing.Optional[str] = None,
        organization_id: typing.Optional[str] = None,
        custom_metadata: typing.Optional[typing.Dict[str, typing.Optional[DataSourceCreateCustomMetadataValue]]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DataSource:
        """
        Create a new data source.

        Parameters
        ----------
        name : str
            The name of the data source.

        source_type : ConfigurableDataSourceNames

        component : DataSourceCreateComponent
            Component that implements the data source

        project_id : typing.Optional[str]

        organization_id : typing.Optional[str]

        custom_metadata : typing.Optional[typing.Dict[str, typing.Optional[DataSourceCreateCustomMetadataValue]]]
            Custom metadata that will be present on all data loaded from the data source

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        DataSource
            Successful Response

        Examples
        --------
        import asyncio

        from llama_index import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.data_sources.create_data_source(
                name="name",
                source_type="S3",
                component={"key": "value"},
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/v1/data-sources",
            method="POST",
            params={
                "project_id": project_id,
                "organization_id": organization_id,
            },
            json={
                "name": name,
                "source_type": source_type,
                "custom_metadata": convert_and_respect_annotation_metadata(
                    object_=custom_metadata,
                    annotation=typing.Dict[str, typing.Optional[DataSourceCreateCustomMetadataValue]],
                    direction="write",
                ),
                "component": convert_and_respect_annotation_metadata(
                    object_=component, annotation=DataSourceCreateComponent, direction="write"
                ),
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    DataSource,
                    parse_obj_as(
                        type_=DataSource,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def upsert_data_source(
        self,
        *,
        name: str,
        source_type: ConfigurableDataSourceNames,
        component: DataSourceCreateComponent,
        project_id: typing.Optional[str] = None,
        organization_id: typing.Optional[str] = None,
        custom_metadata: typing.Optional[typing.Dict[str, typing.Optional[DataSourceCreateCustomMetadataValue]]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DataSource:
        """
        Upserts a data source.
        Updates if a data source with the same name and project_id already exists. Otherwise, creates a new data source.

        Parameters
        ----------
        name : str
            The name of the data source.

        source_type : ConfigurableDataSourceNames

        component : DataSourceCreateComponent
            Component that implements the data source

        project_id : typing.Optional[str]

        organization_id : typing.Optional[str]

        custom_metadata : typing.Optional[typing.Dict[str, typing.Optional[DataSourceCreateCustomMetadataValue]]]
            Custom metadata that will be present on all data loaded from the data source

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        DataSource
            Successful Response

        Examples
        --------
        import asyncio

        from llama_index import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.data_sources.upsert_data_source(
                name="name",
                source_type="S3",
                component={"key": "value"},
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/v1/data-sources",
            method="PUT",
            params={
                "project_id": project_id,
                "organization_id": organization_id,
            },
            json={
                "name": name,
                "source_type": source_type,
                "custom_metadata": convert_and_respect_annotation_metadata(
                    object_=custom_metadata,
                    annotation=typing.Dict[str, typing.Optional[DataSourceCreateCustomMetadataValue]],
                    direction="write",
                ),
                "component": convert_and_respect_annotation_metadata(
                    object_=component, annotation=DataSourceCreateComponent, direction="write"
                ),
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    DataSource,
                    parse_obj_as(
                        type_=DataSource,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def get_data_source(
        self, data_source_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DataSource:
        """
        Get a data source by ID.

        Parameters
        ----------
        data_source_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        DataSource
            Successful Response

        Examples
        --------
        import asyncio

        from llama_index import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.data_sources.get_data_source(
                data_source_id="data_source_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/v1/data-sources/{jsonable_encoder(data_source_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    DataSource,
                    parse_obj_as(
                        type_=DataSource,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def update_data_source(
        self,
        data_source_id: str,
        *,
        source_type: ConfigurableDataSourceNames,
        name: typing.Optional[str] = OMIT,
        custom_metadata: typing.Optional[typing.Dict[str, typing.Optional[DataSourceUpdateCustomMetadataValue]]] = OMIT,
        component: typing.Optional[DataSourceUpdateComponent] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DataSource:
        """
        Update a data source by ID.

        Parameters
        ----------
        data_source_id : str

        source_type : ConfigurableDataSourceNames

        name : typing.Optional[str]
            The name of the data source.

        custom_metadata : typing.Optional[typing.Dict[str, typing.Optional[DataSourceUpdateCustomMetadataValue]]]
            Custom metadata that will be present on all data loaded from the data source

        component : typing.Optional[DataSourceUpdateComponent]
            Component that implements the data source

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        DataSource
            Successful Response

        Examples
        --------
        import asyncio

        from llama_index import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.data_sources.update_data_source(
                data_source_id="data_source_id",
                source_type="S3",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/v1/data-sources/{jsonable_encoder(data_source_id)}",
            method="PUT",
            json={
                "name": name,
                "source_type": source_type,
                "custom_metadata": convert_and_respect_annotation_metadata(
                    object_=custom_metadata,
                    annotation=typing.Dict[str, typing.Optional[DataSourceUpdateCustomMetadataValue]],
                    direction="write",
                ),
                "component": convert_and_respect_annotation_metadata(
                    object_=component, annotation=DataSourceUpdateComponent, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    DataSource,
                    parse_obj_as(
                        type_=DataSource,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def delete_data_source(
        self, data_source_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete a data source by ID.

        Parameters
        ----------
        data_source_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from llama_index import AsyncLlamaCloud

        client = AsyncLlamaCloud(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.data_sources.delete_data_source(
                data_source_id="data_source_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/v1/data-sources/{jsonable_encoder(data_source_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)
