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

import contextlib
import json
import typing
from json.decoder import JSONDecodeError

import httpx_sse
from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.request_options import RequestOptions
from ..core.serialization import convert_and_respect_annotation_metadata
from ..core.unchecked_base_model import construct_type
from ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.block_input import BlockInput
from ..types.http_validation_error import HttpValidationError
from ..types.placeholder_input import PlaceholderInput
from ..types.src_handlers_create_workflow_response import SrcHandlersCreateWorkflowResponse
from ..types.src_handlers_create_workflow_revision_response import SrcHandlersCreateWorkflowRevisionResponse
from ..types.src_handlers_delete_workflow_response import SrcHandlersDeleteWorkflowResponse
from ..types.src_handlers_get_workflow_response import SrcHandlersGetWorkflowResponse
from ..types.src_handlers_list_workflows_response import SrcHandlersListWorkflowsResponse
from ..types.src_handlers_update_workflow_response import SrcHandlersUpdateWorkflowResponse
from ..types.workflow_config_input import WorkflowConfigInput
from ..types.workflow_note_input import WorkflowNoteInput
from ..types.workflow_run_response import WorkflowRunResponse
from ..types.workflow_run_stream_response import WorkflowRunStreamResponse
from .types.src_handlers_workflows_execute_with_config_req_body_inputs_value import (
    SrcHandlersWorkflowsExecuteWithConfigReqBodyInputsValue,
)
from .types.workflows_run_request_inputs_value import WorkflowsRunRequestInputsValue
from .types.workflows_run_stream_request_inputs_value import WorkflowsRunStreamRequestInputsValue
from .types.workflows_run_with_config_response import WorkflowsRunWithConfigResponse

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


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

    def create_revision(
        self,
        *,
        workflow_id: typing.Optional[str] = None,
        workflow_key: typing.Optional[str] = None,
        workflow_display_name: typing.Optional[str] = OMIT,
        workflow_schema_version: typing.Optional[str] = OMIT,
        workflow_img_url: typing.Optional[str] = OMIT,
        workflow_description: typing.Optional[str] = OMIT,
        blocks: typing.Optional[typing.Sequence[BlockInput]] = OMIT,
        notes: typing.Optional[typing.Sequence[WorkflowNoteInput]] = OMIT,
        placeholders: typing.Optional[typing.Sequence[PlaceholderInput]] = OMIT,
        tags: typing.Optional[typing.Sequence[str]] = OMIT,
        is_tool: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[SrcHandlersCreateWorkflowRevisionResponse]:
        """
        Parameters
        ----------
        workflow_id : typing.Optional[str]

        workflow_key : typing.Optional[str]

        workflow_display_name : typing.Optional[str]

        workflow_schema_version : typing.Optional[str]

        workflow_img_url : typing.Optional[str]

        workflow_description : typing.Optional[str]

        blocks : typing.Optional[typing.Sequence[BlockInput]]

        notes : typing.Optional[typing.Sequence[WorkflowNoteInput]]

        placeholders : typing.Optional[typing.Sequence[PlaceholderInput]]

        tags : typing.Optional[typing.Sequence[str]]

        is_tool : typing.Optional[bool]

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

        Returns
        -------
        HttpResponse[SrcHandlersCreateWorkflowRevisionResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v2/workflows/revisions",
            method="POST",
            params={
                "workflow_id": workflow_id,
                "workflow_key": workflow_key,
            },
            json={
                "workflow_display_name": workflow_display_name,
                "workflow_schema_version": workflow_schema_version,
                "workflow_img_url": workflow_img_url,
                "workflow_description": workflow_description,
                "blocks": convert_and_respect_annotation_metadata(
                    object_=blocks, annotation=typing.Sequence[BlockInput], direction="write"
                ),
                "notes": convert_and_respect_annotation_metadata(
                    object_=notes, annotation=typing.Sequence[WorkflowNoteInput], direction="write"
                ),
                "placeholders": convert_and_respect_annotation_metadata(
                    object_=placeholders, annotation=typing.Sequence[PlaceholderInput], direction="write"
                ),
                "tags": tags,
                "is_tool": is_tool,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcHandlersCreateWorkflowRevisionResponse,
                    construct_type(
                        type_=SrcHandlersCreateWorkflowRevisionResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def list(
        self,
        *,
        sort: typing.Optional[str] = None,
        direction: typing.Optional[str] = None,
        start_at: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        query: typing.Optional[str] = None,
        tags: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[SrcHandlersListWorkflowsResponse]:
        """
        List all workflows in the organization

        Parameters
        ----------
        sort : typing.Optional[str]
            Field to sort by

        direction : typing.Optional[str]
            Sort in ascending or descending order

        start_at : typing.Optional[str]
            created_at to start at

        limit : typing.Optional[int]
            Limit of records to return

        query : typing.Optional[str]
            Search query

        tags : typing.Optional[str]
            Filter by tags

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

        Returns
        -------
        HttpResponse[SrcHandlersListWorkflowsResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v2/workflows",
            method="GET",
            params={
                "sort": sort,
                "direction": direction,
                "start_at": start_at,
                "limit": limit,
                "query": query,
                "tags": tags,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcHandlersListWorkflowsResponse,
                    construct_type(
                        type_=SrcHandlersListWorkflowsResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def create(
        self,
        *,
        workflow_key: typing.Optional[str] = None,
        workflow_display_name: typing.Optional[str] = OMIT,
        workflow_schema_version: typing.Optional[str] = OMIT,
        workflow_img_url: typing.Optional[str] = OMIT,
        workflow_description: typing.Optional[str] = OMIT,
        blocks: typing.Optional[typing.Sequence[BlockInput]] = OMIT,
        notes: typing.Optional[typing.Sequence[WorkflowNoteInput]] = OMIT,
        placeholders: typing.Optional[typing.Sequence[PlaceholderInput]] = OMIT,
        tags: typing.Optional[typing.Sequence[str]] = OMIT,
        is_tool: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[SrcHandlersCreateWorkflowResponse]:
        """
        Parameters
        ----------
        workflow_key : typing.Optional[str]
            A unique key to identify the workflow

        workflow_display_name : typing.Optional[str]

        workflow_schema_version : typing.Optional[str]

        workflow_img_url : typing.Optional[str]

        workflow_description : typing.Optional[str]

        blocks : typing.Optional[typing.Sequence[BlockInput]]

        notes : typing.Optional[typing.Sequence[WorkflowNoteInput]]

        placeholders : typing.Optional[typing.Sequence[PlaceholderInput]]

        tags : typing.Optional[typing.Sequence[str]]

        is_tool : typing.Optional[bool]

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

        Returns
        -------
        HttpResponse[SrcHandlersCreateWorkflowResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v2/workflows",
            method="POST",
            params={
                "workflow_key": workflow_key,
            },
            json={
                "workflow_display_name": workflow_display_name,
                "workflow_schema_version": workflow_schema_version,
                "workflow_img_url": workflow_img_url,
                "workflow_description": workflow_description,
                "blocks": convert_and_respect_annotation_metadata(
                    object_=blocks, annotation=typing.Sequence[BlockInput], direction="write"
                ),
                "notes": convert_and_respect_annotation_metadata(
                    object_=notes, annotation=typing.Sequence[WorkflowNoteInput], direction="write"
                ),
                "placeholders": convert_and_respect_annotation_metadata(
                    object_=placeholders, annotation=typing.Sequence[PlaceholderInput], direction="write"
                ),
                "tags": tags,
                "is_tool": is_tool,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcHandlersCreateWorkflowResponse,
                    construct_type(
                        type_=SrcHandlersCreateWorkflowResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get(
        self, workflow_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[SrcHandlersGetWorkflowResponse]:
        """
        Fetch app configuration by ID.

        Parameters
        ----------
        workflow_id : str

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

        Returns
        -------
        HttpResponse[SrcHandlersGetWorkflowResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/workflows/{jsonable_encoder(workflow_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcHandlersGetWorkflowResponse,
                    construct_type(
                        type_=SrcHandlersGetWorkflowResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def update(
        self,
        workflow_id: str,
        *,
        workflow_display_name: typing.Optional[str] = OMIT,
        workflow_schema_version: typing.Optional[str] = OMIT,
        workflow_img_url: typing.Optional[str] = OMIT,
        workflow_description: typing.Optional[str] = OMIT,
        blocks: typing.Optional[typing.Sequence[BlockInput]] = OMIT,
        notes: typing.Optional[typing.Sequence[WorkflowNoteInput]] = OMIT,
        placeholders: typing.Optional[typing.Sequence[PlaceholderInput]] = OMIT,
        tags: typing.Optional[typing.Sequence[str]] = OMIT,
        is_tool: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[SrcHandlersUpdateWorkflowResponse]:
        """
        Parameters
        ----------
        workflow_id : str

        workflow_display_name : typing.Optional[str]

        workflow_schema_version : typing.Optional[str]

        workflow_img_url : typing.Optional[str]

        workflow_description : typing.Optional[str]

        blocks : typing.Optional[typing.Sequence[BlockInput]]

        notes : typing.Optional[typing.Sequence[WorkflowNoteInput]]

        placeholders : typing.Optional[typing.Sequence[PlaceholderInput]]

        tags : typing.Optional[typing.Sequence[str]]

        is_tool : typing.Optional[bool]

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

        Returns
        -------
        HttpResponse[SrcHandlersUpdateWorkflowResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/workflows/{jsonable_encoder(workflow_id)}",
            method="PUT",
            json={
                "workflow_display_name": workflow_display_name,
                "workflow_schema_version": workflow_schema_version,
                "workflow_img_url": workflow_img_url,
                "workflow_description": workflow_description,
                "blocks": convert_and_respect_annotation_metadata(
                    object_=blocks, annotation=typing.Sequence[BlockInput], direction="write"
                ),
                "notes": convert_and_respect_annotation_metadata(
                    object_=notes, annotation=typing.Sequence[WorkflowNoteInput], direction="write"
                ),
                "placeholders": convert_and_respect_annotation_metadata(
                    object_=placeholders, annotation=typing.Sequence[PlaceholderInput], direction="write"
                ),
                "tags": tags,
                "is_tool": is_tool,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcHandlersUpdateWorkflowResponse,
                    construct_type(
                        type_=SrcHandlersUpdateWorkflowResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def delete(
        self, workflow_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[SrcHandlersDeleteWorkflowResponse]:
        """
        Parameters
        ----------
        workflow_id : str

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

        Returns
        -------
        HttpResponse[SrcHandlersDeleteWorkflowResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/workflows/{jsonable_encoder(workflow_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcHandlersDeleteWorkflowResponse,
                    construct_type(
                        type_=SrcHandlersDeleteWorkflowResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    @contextlib.contextmanager
    def run_stream(
        self,
        workflow_id: str,
        *,
        environment: typing.Optional[str] = None,
        revision_id: typing.Optional[str] = None,
        session_id: typing.Optional[str] = None,
        inputs: typing.Optional[typing.Dict[str, WorkflowsRunStreamRequestInputsValue]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Iterator[HttpResponse[typing.Iterator[WorkflowRunStreamResponse]]]:
        """
        Parameters
        ----------
        workflow_id : str

        environment : typing.Optional[str]
            Specifies the execution environment for the workflow. The available environments include:
            - `production`: The production environment, where workflows are executed under live conditions.
            - `staging`: A staging environment used for testing prior to production deployment.
            - `development`: A development environment used for testing new changes.
            - `console`: The console environment, runs latest changes on a workflow.

        revision_id : typing.Optional[str]

        session_id : typing.Optional[str]

        inputs : typing.Optional[typing.Dict[str, WorkflowsRunStreamRequestInputsValue]]

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

        Yields
        ------
        typing.Iterator[HttpResponse[typing.Iterator[WorkflowRunStreamResponse]]]

        """
        with self._client_wrapper.httpx_client.stream(
            f"v2/workflows/{jsonable_encoder(workflow_id)}/execute",
            method="POST",
            params={
                "environment": environment,
                "revision_id": revision_id,
                "session_id": session_id,
            },
            json={
                "inputs": convert_and_respect_annotation_metadata(
                    object_=inputs, annotation=typing.Dict[str, WorkflowsRunStreamRequestInputsValue], direction="write"
                ),
                "streaming": True,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        ) as _response:

            def _stream() -> HttpResponse[typing.Iterator[WorkflowRunStreamResponse]]:
                try:
                    if 200 <= _response.status_code < 300:

                        def _iter():
                            _event_source = httpx_sse.EventSource(_response)
                            for _sse in _event_source.iter_sse():
                                if _sse.data == None:
                                    return
                                try:
                                    yield typing.cast(
                                        WorkflowRunStreamResponse,
                                        construct_type(
                                            type_=WorkflowRunStreamResponse,  # type: ignore
                                            object_=json.loads(_sse.data),
                                        ),
                                    )
                                except Exception:
                                    pass
                            return

                        return HttpResponse(response=_response, data=_iter())
                    _response.read()
                    if _response.status_code == 422:
                        raise UnprocessableEntityError(
                            headers=dict(_response.headers),
                            body=typing.cast(
                                HttpValidationError,
                                construct_type(
                                    type_=HttpValidationError,  # type: ignore
                                    object_=_response.json(),
                                ),
                            ),
                        )
                    _response_json = _response.json()
                except JSONDecodeError:
                    raise ApiError(
                        status_code=_response.status_code, headers=dict(_response.headers), body=_response.text
                    )
                raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

            yield _stream()

    def run(
        self,
        workflow_id: str,
        *,
        environment: typing.Optional[str] = None,
        revision_id: typing.Optional[str] = None,
        session_id: typing.Optional[str] = None,
        inputs: typing.Optional[typing.Dict[str, WorkflowsRunRequestInputsValue]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[WorkflowRunResponse]:
        """
        Parameters
        ----------
        workflow_id : str

        environment : typing.Optional[str]
            Specifies the execution environment for the workflow. The available environments include:
            - `production`: The production environment, where workflows are executed under live conditions.
            - `staging`: A staging environment used for testing prior to production deployment.
            - `development`: A development environment used for testing new changes.
            - `console`: The console environment, runs latest changes on a workflow.

        revision_id : typing.Optional[str]

        session_id : typing.Optional[str]

        inputs : typing.Optional[typing.Dict[str, WorkflowsRunRequestInputsValue]]

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

        Returns
        -------
        HttpResponse[WorkflowRunResponse]

        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/workflows/{jsonable_encoder(workflow_id)}/execute",
            method="POST",
            params={
                "environment": environment,
                "revision_id": revision_id,
                "session_id": session_id,
            },
            json={
                "inputs": convert_and_respect_annotation_metadata(
                    object_=inputs, annotation=typing.Dict[str, WorkflowsRunRequestInputsValue], direction="write"
                ),
                "streaming": False,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    WorkflowRunResponse,
                    construct_type(
                        type_=WorkflowRunResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def run_with_config(
        self,
        *,
        workflow_config: WorkflowConfigInput,
        environment: typing.Optional[str] = None,
        revision_id: typing.Optional[str] = None,
        session_id: typing.Optional[str] = None,
        workflow_key: typing.Optional[str] = OMIT,
        inputs: typing.Optional[typing.Dict[str, SrcHandlersWorkflowsExecuteWithConfigReqBodyInputsValue]] = OMIT,
        streaming: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[WorkflowsRunWithConfigResponse]:
        """
        Parameters
        ----------
        workflow_config : WorkflowConfigInput

        environment : typing.Optional[str]
            Specifies the execution environment for the workflow. The available environments include:
            - `production`: The production environment, where workflows are executed under live conditions.
            - `staging`: A staging environment used for testing prior to production deployment.
            - `development`: A development environment used for testing new changes.
            - `console`: The console environment, runs latest changes on a workflow.

        revision_id : typing.Optional[str]

        session_id : typing.Optional[str]

        workflow_key : typing.Optional[str]

        inputs : typing.Optional[typing.Dict[str, SrcHandlersWorkflowsExecuteWithConfigReqBodyInputsValue]]

        streaming : typing.Optional[bool]

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

        Returns
        -------
        HttpResponse[WorkflowsRunWithConfigResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v2/workflows/execute",
            method="POST",
            params={
                "environment": environment,
                "revision_id": revision_id,
                "session_id": session_id,
            },
            json={
                "workflow_key": workflow_key,
                "inputs": convert_and_respect_annotation_metadata(
                    object_=inputs,
                    annotation=typing.Dict[str, SrcHandlersWorkflowsExecuteWithConfigReqBodyInputsValue],
                    direction="write",
                ),
                "streaming": streaming,
                "workflow_config": convert_and_respect_annotation_metadata(
                    object_=workflow_config, annotation=WorkflowConfigInput, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    WorkflowsRunWithConfigResponse,
                    construct_type(
                        type_=WorkflowsRunWithConfigResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


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

    async def create_revision(
        self,
        *,
        workflow_id: typing.Optional[str] = None,
        workflow_key: typing.Optional[str] = None,
        workflow_display_name: typing.Optional[str] = OMIT,
        workflow_schema_version: typing.Optional[str] = OMIT,
        workflow_img_url: typing.Optional[str] = OMIT,
        workflow_description: typing.Optional[str] = OMIT,
        blocks: typing.Optional[typing.Sequence[BlockInput]] = OMIT,
        notes: typing.Optional[typing.Sequence[WorkflowNoteInput]] = OMIT,
        placeholders: typing.Optional[typing.Sequence[PlaceholderInput]] = OMIT,
        tags: typing.Optional[typing.Sequence[str]] = OMIT,
        is_tool: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[SrcHandlersCreateWorkflowRevisionResponse]:
        """
        Parameters
        ----------
        workflow_id : typing.Optional[str]

        workflow_key : typing.Optional[str]

        workflow_display_name : typing.Optional[str]

        workflow_schema_version : typing.Optional[str]

        workflow_img_url : typing.Optional[str]

        workflow_description : typing.Optional[str]

        blocks : typing.Optional[typing.Sequence[BlockInput]]

        notes : typing.Optional[typing.Sequence[WorkflowNoteInput]]

        placeholders : typing.Optional[typing.Sequence[PlaceholderInput]]

        tags : typing.Optional[typing.Sequence[str]]

        is_tool : typing.Optional[bool]

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

        Returns
        -------
        AsyncHttpResponse[SrcHandlersCreateWorkflowRevisionResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v2/workflows/revisions",
            method="POST",
            params={
                "workflow_id": workflow_id,
                "workflow_key": workflow_key,
            },
            json={
                "workflow_display_name": workflow_display_name,
                "workflow_schema_version": workflow_schema_version,
                "workflow_img_url": workflow_img_url,
                "workflow_description": workflow_description,
                "blocks": convert_and_respect_annotation_metadata(
                    object_=blocks, annotation=typing.Sequence[BlockInput], direction="write"
                ),
                "notes": convert_and_respect_annotation_metadata(
                    object_=notes, annotation=typing.Sequence[WorkflowNoteInput], direction="write"
                ),
                "placeholders": convert_and_respect_annotation_metadata(
                    object_=placeholders, annotation=typing.Sequence[PlaceholderInput], direction="write"
                ),
                "tags": tags,
                "is_tool": is_tool,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcHandlersCreateWorkflowRevisionResponse,
                    construct_type(
                        type_=SrcHandlersCreateWorkflowRevisionResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def list(
        self,
        *,
        sort: typing.Optional[str] = None,
        direction: typing.Optional[str] = None,
        start_at: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        query: typing.Optional[str] = None,
        tags: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[SrcHandlersListWorkflowsResponse]:
        """
        List all workflows in the organization

        Parameters
        ----------
        sort : typing.Optional[str]
            Field to sort by

        direction : typing.Optional[str]
            Sort in ascending or descending order

        start_at : typing.Optional[str]
            created_at to start at

        limit : typing.Optional[int]
            Limit of records to return

        query : typing.Optional[str]
            Search query

        tags : typing.Optional[str]
            Filter by tags

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

        Returns
        -------
        AsyncHttpResponse[SrcHandlersListWorkflowsResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v2/workflows",
            method="GET",
            params={
                "sort": sort,
                "direction": direction,
                "start_at": start_at,
                "limit": limit,
                "query": query,
                "tags": tags,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcHandlersListWorkflowsResponse,
                    construct_type(
                        type_=SrcHandlersListWorkflowsResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def create(
        self,
        *,
        workflow_key: typing.Optional[str] = None,
        workflow_display_name: typing.Optional[str] = OMIT,
        workflow_schema_version: typing.Optional[str] = OMIT,
        workflow_img_url: typing.Optional[str] = OMIT,
        workflow_description: typing.Optional[str] = OMIT,
        blocks: typing.Optional[typing.Sequence[BlockInput]] = OMIT,
        notes: typing.Optional[typing.Sequence[WorkflowNoteInput]] = OMIT,
        placeholders: typing.Optional[typing.Sequence[PlaceholderInput]] = OMIT,
        tags: typing.Optional[typing.Sequence[str]] = OMIT,
        is_tool: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[SrcHandlersCreateWorkflowResponse]:
        """
        Parameters
        ----------
        workflow_key : typing.Optional[str]
            A unique key to identify the workflow

        workflow_display_name : typing.Optional[str]

        workflow_schema_version : typing.Optional[str]

        workflow_img_url : typing.Optional[str]

        workflow_description : typing.Optional[str]

        blocks : typing.Optional[typing.Sequence[BlockInput]]

        notes : typing.Optional[typing.Sequence[WorkflowNoteInput]]

        placeholders : typing.Optional[typing.Sequence[PlaceholderInput]]

        tags : typing.Optional[typing.Sequence[str]]

        is_tool : typing.Optional[bool]

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

        Returns
        -------
        AsyncHttpResponse[SrcHandlersCreateWorkflowResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v2/workflows",
            method="POST",
            params={
                "workflow_key": workflow_key,
            },
            json={
                "workflow_display_name": workflow_display_name,
                "workflow_schema_version": workflow_schema_version,
                "workflow_img_url": workflow_img_url,
                "workflow_description": workflow_description,
                "blocks": convert_and_respect_annotation_metadata(
                    object_=blocks, annotation=typing.Sequence[BlockInput], direction="write"
                ),
                "notes": convert_and_respect_annotation_metadata(
                    object_=notes, annotation=typing.Sequence[WorkflowNoteInput], direction="write"
                ),
                "placeholders": convert_and_respect_annotation_metadata(
                    object_=placeholders, annotation=typing.Sequence[PlaceholderInput], direction="write"
                ),
                "tags": tags,
                "is_tool": is_tool,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcHandlersCreateWorkflowResponse,
                    construct_type(
                        type_=SrcHandlersCreateWorkflowResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get(
        self, workflow_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[SrcHandlersGetWorkflowResponse]:
        """
        Fetch app configuration by ID.

        Parameters
        ----------
        workflow_id : str

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

        Returns
        -------
        AsyncHttpResponse[SrcHandlersGetWorkflowResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/workflows/{jsonable_encoder(workflow_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcHandlersGetWorkflowResponse,
                    construct_type(
                        type_=SrcHandlersGetWorkflowResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def update(
        self,
        workflow_id: str,
        *,
        workflow_display_name: typing.Optional[str] = OMIT,
        workflow_schema_version: typing.Optional[str] = OMIT,
        workflow_img_url: typing.Optional[str] = OMIT,
        workflow_description: typing.Optional[str] = OMIT,
        blocks: typing.Optional[typing.Sequence[BlockInput]] = OMIT,
        notes: typing.Optional[typing.Sequence[WorkflowNoteInput]] = OMIT,
        placeholders: typing.Optional[typing.Sequence[PlaceholderInput]] = OMIT,
        tags: typing.Optional[typing.Sequence[str]] = OMIT,
        is_tool: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[SrcHandlersUpdateWorkflowResponse]:
        """
        Parameters
        ----------
        workflow_id : str

        workflow_display_name : typing.Optional[str]

        workflow_schema_version : typing.Optional[str]

        workflow_img_url : typing.Optional[str]

        workflow_description : typing.Optional[str]

        blocks : typing.Optional[typing.Sequence[BlockInput]]

        notes : typing.Optional[typing.Sequence[WorkflowNoteInput]]

        placeholders : typing.Optional[typing.Sequence[PlaceholderInput]]

        tags : typing.Optional[typing.Sequence[str]]

        is_tool : typing.Optional[bool]

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

        Returns
        -------
        AsyncHttpResponse[SrcHandlersUpdateWorkflowResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/workflows/{jsonable_encoder(workflow_id)}",
            method="PUT",
            json={
                "workflow_display_name": workflow_display_name,
                "workflow_schema_version": workflow_schema_version,
                "workflow_img_url": workflow_img_url,
                "workflow_description": workflow_description,
                "blocks": convert_and_respect_annotation_metadata(
                    object_=blocks, annotation=typing.Sequence[BlockInput], direction="write"
                ),
                "notes": convert_and_respect_annotation_metadata(
                    object_=notes, annotation=typing.Sequence[WorkflowNoteInput], direction="write"
                ),
                "placeholders": convert_and_respect_annotation_metadata(
                    object_=placeholders, annotation=typing.Sequence[PlaceholderInput], direction="write"
                ),
                "tags": tags,
                "is_tool": is_tool,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcHandlersUpdateWorkflowResponse,
                    construct_type(
                        type_=SrcHandlersUpdateWorkflowResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def delete(
        self, workflow_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[SrcHandlersDeleteWorkflowResponse]:
        """
        Parameters
        ----------
        workflow_id : str

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

        Returns
        -------
        AsyncHttpResponse[SrcHandlersDeleteWorkflowResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/workflows/{jsonable_encoder(workflow_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SrcHandlersDeleteWorkflowResponse,
                    construct_type(
                        type_=SrcHandlersDeleteWorkflowResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    @contextlib.asynccontextmanager
    async def run_stream(
        self,
        workflow_id: str,
        *,
        environment: typing.Optional[str] = None,
        revision_id: typing.Optional[str] = None,
        session_id: typing.Optional[str] = None,
        inputs: typing.Optional[typing.Dict[str, WorkflowsRunStreamRequestInputsValue]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[WorkflowRunStreamResponse]]]:
        """
        Parameters
        ----------
        workflow_id : str

        environment : typing.Optional[str]
            Specifies the execution environment for the workflow. The available environments include:
            - `production`: The production environment, where workflows are executed under live conditions.
            - `staging`: A staging environment used for testing prior to production deployment.
            - `development`: A development environment used for testing new changes.
            - `console`: The console environment, runs latest changes on a workflow.

        revision_id : typing.Optional[str]

        session_id : typing.Optional[str]

        inputs : typing.Optional[typing.Dict[str, WorkflowsRunStreamRequestInputsValue]]

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

        Yields
        ------
        typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[WorkflowRunStreamResponse]]]

        """
        async with self._client_wrapper.httpx_client.stream(
            f"v2/workflows/{jsonable_encoder(workflow_id)}/execute",
            method="POST",
            params={
                "environment": environment,
                "revision_id": revision_id,
                "session_id": session_id,
            },
            json={
                "inputs": convert_and_respect_annotation_metadata(
                    object_=inputs, annotation=typing.Dict[str, WorkflowsRunStreamRequestInputsValue], direction="write"
                ),
                "streaming": True,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        ) as _response:

            async def _stream() -> AsyncHttpResponse[typing.AsyncIterator[WorkflowRunStreamResponse]]:
                try:
                    if 200 <= _response.status_code < 300:

                        async def _iter():
                            _event_source = httpx_sse.EventSource(_response)
                            async for _sse in _event_source.aiter_sse():
                                if _sse.data == None:
                                    return
                                try:
                                    yield typing.cast(
                                        WorkflowRunStreamResponse,
                                        construct_type(
                                            type_=WorkflowRunStreamResponse,  # type: ignore
                                            object_=json.loads(_sse.data),
                                        ),
                                    )
                                except Exception:
                                    pass
                            return

                        return AsyncHttpResponse(response=_response, data=_iter())
                    await _response.aread()
                    if _response.status_code == 422:
                        raise UnprocessableEntityError(
                            headers=dict(_response.headers),
                            body=typing.cast(
                                HttpValidationError,
                                construct_type(
                                    type_=HttpValidationError,  # type: ignore
                                    object_=_response.json(),
                                ),
                            ),
                        )
                    _response_json = _response.json()
                except JSONDecodeError:
                    raise ApiError(
                        status_code=_response.status_code, headers=dict(_response.headers), body=_response.text
                    )
                raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

            yield await _stream()

    async def run(
        self,
        workflow_id: str,
        *,
        environment: typing.Optional[str] = None,
        revision_id: typing.Optional[str] = None,
        session_id: typing.Optional[str] = None,
        inputs: typing.Optional[typing.Dict[str, WorkflowsRunRequestInputsValue]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[WorkflowRunResponse]:
        """
        Parameters
        ----------
        workflow_id : str

        environment : typing.Optional[str]
            Specifies the execution environment for the workflow. The available environments include:
            - `production`: The production environment, where workflows are executed under live conditions.
            - `staging`: A staging environment used for testing prior to production deployment.
            - `development`: A development environment used for testing new changes.
            - `console`: The console environment, runs latest changes on a workflow.

        revision_id : typing.Optional[str]

        session_id : typing.Optional[str]

        inputs : typing.Optional[typing.Dict[str, WorkflowsRunRequestInputsValue]]

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

        Returns
        -------
        AsyncHttpResponse[WorkflowRunResponse]

        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/workflows/{jsonable_encoder(workflow_id)}/execute",
            method="POST",
            params={
                "environment": environment,
                "revision_id": revision_id,
                "session_id": session_id,
            },
            json={
                "inputs": convert_and_respect_annotation_metadata(
                    object_=inputs, annotation=typing.Dict[str, WorkflowsRunRequestInputsValue], direction="write"
                ),
                "streaming": False,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    WorkflowRunResponse,
                    construct_type(
                        type_=WorkflowRunResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def run_with_config(
        self,
        *,
        workflow_config: WorkflowConfigInput,
        environment: typing.Optional[str] = None,
        revision_id: typing.Optional[str] = None,
        session_id: typing.Optional[str] = None,
        workflow_key: typing.Optional[str] = OMIT,
        inputs: typing.Optional[typing.Dict[str, SrcHandlersWorkflowsExecuteWithConfigReqBodyInputsValue]] = OMIT,
        streaming: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[WorkflowsRunWithConfigResponse]:
        """
        Parameters
        ----------
        workflow_config : WorkflowConfigInput

        environment : typing.Optional[str]
            Specifies the execution environment for the workflow. The available environments include:
            - `production`: The production environment, where workflows are executed under live conditions.
            - `staging`: A staging environment used for testing prior to production deployment.
            - `development`: A development environment used for testing new changes.
            - `console`: The console environment, runs latest changes on a workflow.

        revision_id : typing.Optional[str]

        session_id : typing.Optional[str]

        workflow_key : typing.Optional[str]

        inputs : typing.Optional[typing.Dict[str, SrcHandlersWorkflowsExecuteWithConfigReqBodyInputsValue]]

        streaming : typing.Optional[bool]

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

        Returns
        -------
        AsyncHttpResponse[WorkflowsRunWithConfigResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v2/workflows/execute",
            method="POST",
            params={
                "environment": environment,
                "revision_id": revision_id,
                "session_id": session_id,
            },
            json={
                "workflow_key": workflow_key,
                "inputs": convert_and_respect_annotation_metadata(
                    object_=inputs,
                    annotation=typing.Dict[str, SrcHandlersWorkflowsExecuteWithConfigReqBodyInputsValue],
                    direction="write",
                ),
                "streaming": streaming,
                "workflow_config": convert_and_respect_annotation_metadata(
                    object_=workflow_config, annotation=WorkflowConfigInput, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    WorkflowsRunWithConfigResponse,
                    construct_type(
                        type_=WorkflowsRunWithConfigResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        construct_type(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
