# This file was auto-generated by Fern from our API Definition. from __future__ import annotations import typing from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.request_options import RequestOptions from ...types.template_list_response import TemplateListResponse from ...types.template_summary import TemplateSummary from .raw_client import AsyncRawTemplatesClient, RawTemplatesClient if typing.TYPE_CHECKING: from .runs.client import AsyncRunsClient, RunsClient class TemplatesClient: def __init__(self, *, client_wrapper: SyncClientWrapper): self._raw_client = RawTemplatesClient(client_wrapper=client_wrapper) self._client_wrapper = client_wrapper self._runs: typing.Optional[RunsClient] = None @property def with_raw_response(self) -> RawTemplatesClient: """ Retrieves a raw implementation of this client that returns raw responses. Returns ------- RawTemplatesClient """ return self._raw_client def list( self, *, cursor: typing.Optional[str] = None, page_size: typing.Optional[int] = None, versions_per_template: typing.Optional[int] = None, search: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None, ) -> TemplateListResponse: """ List the published flows templates in your workspace, together with each runnable version's inputs and outputs. Use the ids here as `template_id` / `version_id` on `POST /v1/flows/templates/{template_id}/runs`. Versions built on models that are not available to you through the API are left out, so `versions` is empty when none of a template's published versions is runnable through this API. Templates shared with you by link, or published to Explore from another workspace, are not listed but can still be fetched and run by `template_id`. Parameters ---------- cursor : typing.Optional[str] Pagination cursor: the `next_cursor` value of the previous page's response. Omit it for the first page. page_size : typing.Optional[int] How many templates to return per page. Lower than the run list's ceiling because each row expands its versions' input and output schemas. versions_per_template : typing.Optional[int] How many of each template's published versions to return, newest first. `has_more_versions` tells you when a template has more. search : typing.Optional[str] Only return templates whose name or description contains this text. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- TemplateListResponse Successful Response Examples -------- from elevenlabs import ElevenLabs client = ElevenLabs( api_key="YOUR_API_KEY", ) client.flows.templates.list( cursor="cursor", page_size=1, versions_per_template=1, search="search", ) """ _response = self._raw_client.list( cursor=cursor, page_size=page_size, versions_per_template=versions_per_template, search=search, request_options=request_options, ) return _response.data def get( self, template_id: str, *, versions_per_template: typing.Optional[int] = None, request_options: typing.Optional[RequestOptions] = None, ) -> TemplateSummary: """ Retrieve one flows template, together with each runnable version's inputs and outputs. `versions` is empty when no published version is runnable through this API. Works for any template you can open, including templates shared with you by link or published to Explore from another workspace, which `GET /v1/flows/templates` does not list. Parameters ---------- template_id : str The ID of the template, as shown in the ElevenLabs app or by `GET /v1/flows/templates`. versions_per_template : typing.Optional[int] How many of each template's published versions to return, newest first. `has_more_versions` tells you when a template has more. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- TemplateSummary Successful Response Examples -------- from elevenlabs import ElevenLabs client = ElevenLabs( api_key="YOUR_API_KEY", ) client.flows.templates.get( template_id="template_id", versions_per_template=1, ) """ _response = self._raw_client.get( template_id, versions_per_template=versions_per_template, request_options=request_options ) return _response.data @property def runs(self): if self._runs is None: from .runs.client import RunsClient # noqa: E402 self._runs = RunsClient(client_wrapper=self._client_wrapper) return self._runs class AsyncTemplatesClient: def __init__(self, *, client_wrapper: AsyncClientWrapper): self._raw_client = AsyncRawTemplatesClient(client_wrapper=client_wrapper) self._client_wrapper = client_wrapper self._runs: typing.Optional[AsyncRunsClient] = None @property def with_raw_response(self) -> AsyncRawTemplatesClient: """ Retrieves a raw implementation of this client that returns raw responses. Returns ------- AsyncRawTemplatesClient """ return self._raw_client async def list( self, *, cursor: typing.Optional[str] = None, page_size: typing.Optional[int] = None, versions_per_template: typing.Optional[int] = None, search: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None, ) -> TemplateListResponse: """ List the published flows templates in your workspace, together with each runnable version's inputs and outputs. Use the ids here as `template_id` / `version_id` on `POST /v1/flows/templates/{template_id}/runs`. Versions built on models that are not available to you through the API are left out, so `versions` is empty when none of a template's published versions is runnable through this API. Templates shared with you by link, or published to Explore from another workspace, are not listed but can still be fetched and run by `template_id`. Parameters ---------- cursor : typing.Optional[str] Pagination cursor: the `next_cursor` value of the previous page's response. Omit it for the first page. page_size : typing.Optional[int] How many templates to return per page. Lower than the run list's ceiling because each row expands its versions' input and output schemas. versions_per_template : typing.Optional[int] How many of each template's published versions to return, newest first. `has_more_versions` tells you when a template has more. search : typing.Optional[str] Only return templates whose name or description contains this text. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- TemplateListResponse Successful Response Examples -------- import asyncio from elevenlabs import AsyncElevenLabs client = AsyncElevenLabs( api_key="YOUR_API_KEY", ) async def main() -> None: await client.flows.templates.list( cursor="cursor", page_size=1, versions_per_template=1, search="search", ) asyncio.run(main()) """ _response = await self._raw_client.list( cursor=cursor, page_size=page_size, versions_per_template=versions_per_template, search=search, request_options=request_options, ) return _response.data async def get( self, template_id: str, *, versions_per_template: typing.Optional[int] = None, request_options: typing.Optional[RequestOptions] = None, ) -> TemplateSummary: """ Retrieve one flows template, together with each runnable version's inputs and outputs. `versions` is empty when no published version is runnable through this API. Works for any template you can open, including templates shared with you by link or published to Explore from another workspace, which `GET /v1/flows/templates` does not list. Parameters ---------- template_id : str The ID of the template, as shown in the ElevenLabs app or by `GET /v1/flows/templates`. versions_per_template : typing.Optional[int] How many of each template's published versions to return, newest first. `has_more_versions` tells you when a template has more. request_options : typing.Optional[RequestOptions] Request-specific configuration. Returns ------- TemplateSummary Successful Response Examples -------- import asyncio from elevenlabs import AsyncElevenLabs client = AsyncElevenLabs( api_key="YOUR_API_KEY", ) async def main() -> None: await client.flows.templates.get( template_id="template_id", versions_per_template=1, ) asyncio.run(main()) """ _response = await self._raw_client.get( template_id, versions_per_template=versions_per_template, request_options=request_options ) return _response.data @property def runs(self): if self._runs is None: from .runs.client import AsyncRunsClient # noqa: E402 self._runs = AsyncRunsClient(client_wrapper=self._client_wrapper) return self._runs