Skip to content

Gateway

Public API entry points. Import from tarash.tarash_gateway.

from tarash.tarash_gateway import (
    generate_video,
    generate_video_async,
    generate_image,
    generate_image_async,
    register_provider,
    register_provider_field_mapping,
    get_provider_field_mapping,
)
Function Sync/Async on_progress receives Returns
generate_video(config, request, on_progress=None) Sync VideoGenerationUpdate VideoGenerationResponse
generate_video_async(config, request, on_progress=None) Async VideoGenerationUpdate VideoGenerationResponse
generate_image(config, request, on_progress=None) Sync ImageGenerationUpdate ImageGenerationResponse
generate_image_async(config, request, on_progress=None) Async ImageGenerationUpdate ImageGenerationResponse
register_provider(name, handler) None
register_provider_field_mapping(provider, model_mappings) None
get_provider_field_mapping(provider) dict | None

on_progress accepts both sync and async callables. See the Custom Providers guide for registration usage.


Public API for video and image generation.

register_provider

register_provider(
    provider: str, handler: ProviderHandler
) -> None

Register a custom provider handler.

Extends the SDK with a new provider at runtime without modifying library code. The registered handler will be used for all subsequent calls that specify this provider name in their config.

Parameters:

Name Type Description Default
provider str

Unique provider identifier (e.g. "my-provider"). Must match the provider field passed in VideoGenerationConfig.

required
handler ProviderHandler

Instantiated handler implementing the ProviderHandler protocol.

required
Example
from tarash.tarash_gateway import register_provider
from tarash.tarash_gateway.models import (
    ProviderHandler,
    VideoGenerationConfig,
    VideoGenerationRequest,
    VideoGenerationResponse,
)

class MyHandler:
    def generate_video(self, config, request, on_progress=None):
        ...
    async def generate_video_async(self, config, request, on_progress=None):
        ...

register_provider("my-provider", MyHandler())

config = VideoGenerationConfig(provider="my-provider", model="my-model", api_key="...")
Source code in packages/tarash-gateway/src/tarash/tarash_gateway/api.py
def register_provider(
    provider: str,
    handler: ProviderHandler,
) -> None:
    """Register a custom provider handler.

    Extends the SDK with a new provider at runtime without modifying library
    code. The registered handler will be used for all subsequent calls that
    specify this provider name in their config.

    Args:
        provider: Unique provider identifier (e.g. ``"my-provider"``). Must
            match the ``provider`` field passed in [VideoGenerationConfig][].
        handler: Instantiated handler implementing the [ProviderHandler][]
            protocol.

    Example:
        ```python
        from tarash.tarash_gateway import register_provider
        from tarash.tarash_gateway.models import (
            ProviderHandler,
            VideoGenerationConfig,
            VideoGenerationRequest,
            VideoGenerationResponse,
        )

        class MyHandler:
            def generate_video(self, config, request, on_progress=None):
                ...
            async def generate_video_async(self, config, request, on_progress=None):
                ...

        register_provider("my-provider", MyHandler())

        config = VideoGenerationConfig(provider="my-provider", model="my-model", api_key="...")
        ```
    """
    _register_provider(provider, handler)

register_provider_field_mapping

register_provider_field_mapping(
    provider: str,
    model_mappings: dict[str, dict[str, FieldMapper]],
) -> None

Register field mappings for a provider's models.

Configures how VideoGenerationRequest fields are translated to the provider's own API parameter names and formats. Supports prefix-based lookup so a single mapping can cover a family of model variants.

Parameters:

Name Type Description Default
provider str

Provider identifier (e.g. "fal", "my-provider").

required
model_mappings dict[str, dict[str, FieldMapper]]

Mapping from model name (or prefix) to a dict of {api_param_name: FieldMapper}. Prefix matching is supported — the longest registered prefix wins.

required
Example
from tarash.tarash_gateway import register_provider_field_mapping
from tarash.tarash_gateway.providers.field_mappers import (
    duration_field_mapper,
    passthrough_field_mapper,
)

register_provider_field_mapping("my-provider", {
    "my-provider/model-v1": {
        "prompt": passthrough_field_mapper("prompt", required=True),
        "num_seconds": duration_field_mapper(field_type="int"),
    },
})
Source code in packages/tarash-gateway/src/tarash/tarash_gateway/api.py
def register_provider_field_mapping(
    provider: str,
    model_mappings: dict[str, dict[str, FieldMapper]],
) -> None:
    """Register field mappings for a provider's models.

    Configures how [VideoGenerationRequest][] fields are translated to the
    provider's own API parameter names and formats. Supports prefix-based
    lookup so a single mapping can cover a family of model variants.

    Args:
        provider: Provider identifier (e.g. ``"fal"``, ``"my-provider"``).
        model_mappings: Mapping from model name (or prefix) to a dict of
            ``{api_param_name: FieldMapper}``. Prefix matching is supported —
            the longest registered prefix wins.

    Example:
        ```python
        from tarash.tarash_gateway import register_provider_field_mapping
        from tarash.tarash_gateway.providers.field_mappers import (
            duration_field_mapper,
            passthrough_field_mapper,
        )

        register_provider_field_mapping("my-provider", {
            "my-provider/model-v1": {
                "prompt": passthrough_field_mapper("prompt", required=True),
                "num_seconds": duration_field_mapper(field_type="int"),
            },
        })
        ```
    """
    _FIELD_MAPPER_REGISTRIES[provider] = model_mappings
    log_debug(
        "Registered field mappings for provider",
        context={
            "provider": provider,
            "num_models": len(model_mappings),
        },
        logger_name="tarash.tarash_gateway.api",
    )

get_provider_field_mapping

get_provider_field_mapping(
    provider: str,
) -> dict[str, dict[str, FieldMapper]] | None

Return the field mapper registry for a provider.

Parameters:

Name Type Description Default
provider str

Provider identifier (e.g. "fal", "replicate").

required

Returns:

Type Description
dict[str, dict[str, FieldMapper]] | None

A mapping of model name/prefix → field mapper dict, or None if

dict[str, dict[str, FieldMapper]] | None

no mapping has been registered for the provider.

Example
from tarash.tarash_gateway import get_provider_field_mapping

registry = get_provider_field_mapping("fal")
if registry:
    mappers = registry.get("fal-ai/minimax")
Source code in packages/tarash-gateway/src/tarash/tarash_gateway/api.py
def get_provider_field_mapping(
    provider: str,
) -> dict[str, dict[str, FieldMapper]] | None:
    """Return the field mapper registry for a provider.

    Args:
        provider: Provider identifier (e.g. ``"fal"``, ``"replicate"``).

    Returns:
        A mapping of model name/prefix → field mapper dict, or ``None`` if
        no mapping has been registered for the provider.

    Example:
        ```python
        from tarash.tarash_gateway import get_provider_field_mapping

        registry = get_provider_field_mapping("fal")
        if registry:
            mappers = registry.get("fal-ai/minimax")
        ```
    """
    return _FIELD_MAPPER_REGISTRIES.get(provider)

generate_video_async async

generate_video_async(
    config: VideoGenerationConfig,
    request: VideoGenerationRequest,
    on_progress: ProgressCallback | None = None,
) -> VideoGenerationResponse

Generate a video asynchronously using the configured provider.

Runs the full orchestration pipeline: applies field mappings, submits the request to the provider, polls for completion, and returns a unified response. Automatically falls back to config.fallback_configs on retryable errors.

Parameters:

Name Type Description Default
config VideoGenerationConfig

Provider configuration including API key, model, timeout, and optional fallback chain.

required
request VideoGenerationRequest

Video generation parameters (prompt, duration, aspect ratio, etc.). Unknown fields are captured into extra_params.

required
on_progress ProgressCallback | None

Optional callback invoked on each polling cycle with a VideoGenerationUpdate. Accepts both sync and async callables.

None

Returns:

Type Description
VideoGenerationResponse

VideoGenerationResponse with the video URL, status, and full

VideoGenerationResponse

execution_metadata including timing and fallback attempts.

Raises:

Type Description
TarashException

If generation fails on all providers in the fallback chain.

Example
import asyncio
from tarash.tarash_gateway import generate_video_async
from tarash.tarash_gateway.models import (
    VideoGenerationConfig,
    VideoGenerationRequest,
    VideoGenerationUpdate,
)

async def main():
    config = VideoGenerationConfig(
        provider="fal",
        model="fal-ai/veo3",
        api_key="FAL_KEY",
    )
    request = VideoGenerationRequest(
        prompt="A cat playing piano, cinematic lighting",
        duration_seconds=4,
        aspect_ratio="16:9",
    )

    def on_progress(update: VideoGenerationUpdate) -> None:
        print(f"{update.status}{update.progress_percent}%")

    response = await generate_video_async(config, request, on_progress)
    print(response.video)

asyncio.run(main())
Source code in packages/tarash-gateway/src/tarash/tarash_gateway/api.py
async def generate_video_async(
    config: VideoGenerationConfig,
    request: VideoGenerationRequest,
    on_progress: ProgressCallback | None = None,
) -> VideoGenerationResponse:
    """Generate a video asynchronously using the configured provider.

    Runs the full orchestration pipeline: applies field mappings, submits the
    request to the provider, polls for completion, and returns a unified
    response. Automatically falls back to ``config.fallback_configs`` on
    retryable errors.

    Args:
        config: Provider configuration including API key, model, timeout, and
            optional fallback chain.
        request: Video generation parameters (prompt, duration, aspect ratio,
            etc.). Unknown fields are captured into ``extra_params``.
        on_progress: Optional callback invoked on each polling cycle with a
            [VideoGenerationUpdate][]. Accepts both sync and async callables.

    Returns:
        [VideoGenerationResponse][] with the video URL, status, and full
        ``execution_metadata`` including timing and fallback attempts.

    Raises:
        TarashException: If generation fails on all providers in the fallback
            chain.

    Example:
        ```python
        import asyncio
        from tarash.tarash_gateway import generate_video_async
        from tarash.tarash_gateway.models import (
            VideoGenerationConfig,
            VideoGenerationRequest,
            VideoGenerationUpdate,
        )

        async def main():
            config = VideoGenerationConfig(
                provider="fal",
                model="fal-ai/veo3",
                api_key="FAL_KEY",
            )
            request = VideoGenerationRequest(
                prompt="A cat playing piano, cinematic lighting",
                duration_seconds=4,
                aspect_ratio="16:9",
            )

            def on_progress(update: VideoGenerationUpdate) -> None:
                print(f"{update.status} — {update.progress_percent}%")

            response = await generate_video_async(config, request, on_progress)
            print(response.video)

        asyncio.run(main())
        ```
    """
    log_info(
        "Video generation request received (async)",
        context={
            "config": config,
            "request": request,
        },
        logger_name="tarash.tarash_gateway.api",
        redact=True,
    )

    # Delegate to orchestrator (handles mock, fallbacks, and execution)
    return await _ORCHESTRATOR.execute_async(config, request, on_progress=on_progress)

generate_video

generate_video(
    config: VideoGenerationConfig,
    request: VideoGenerationRequest,
    on_progress: ProgressCallback | None = None,
) -> VideoGenerationResponse

Generate a video synchronously using the configured provider.

Blocking version of [generate_video_async][]. Runs the full orchestration pipeline and returns only when generation is complete. Automatically falls back to config.fallback_configs on retryable errors.

Parameters:

Name Type Description Default
config VideoGenerationConfig

Provider configuration including API key, model, timeout, and optional fallback chain.

required
request VideoGenerationRequest

Video generation parameters (prompt, duration, aspect ratio, etc.). Unknown fields are captured into extra_params.

required
on_progress ProgressCallback | None

Optional callback invoked on each polling cycle with a VideoGenerationUpdate. Accepts both sync and async callables.

None

Returns:

Type Description
VideoGenerationResponse

VideoGenerationResponse with the video URL, status, and full

VideoGenerationResponse

execution_metadata including timing and fallback attempts.

Raises:

Type Description
TarashException

If generation fails on all providers in the fallback chain.

Example
from tarash.tarash_gateway import generate_video
from tarash.tarash_gateway.models import VideoGenerationConfig, VideoGenerationRequest

config = VideoGenerationConfig(
    provider="fal",
    model="fal-ai/veo3",
    api_key="FAL_KEY",
)
request = VideoGenerationRequest(
    prompt="A cat playing piano, cinematic lighting",
    duration_seconds=4,
    aspect_ratio="16:9",
)
response = generate_video(config, request)
print(response.video)
Source code in packages/tarash-gateway/src/tarash/tarash_gateway/api.py
def generate_video(
    config: VideoGenerationConfig,
    request: VideoGenerationRequest,
    on_progress: ProgressCallback | None = None,
) -> VideoGenerationResponse:
    """Generate a video synchronously using the configured provider.

    Blocking version of [generate_video_async][]. Runs the full orchestration
    pipeline and returns only when generation is complete. Automatically falls
    back to ``config.fallback_configs`` on retryable errors.

    Args:
        config: Provider configuration including API key, model, timeout, and
            optional fallback chain.
        request: Video generation parameters (prompt, duration, aspect ratio,
            etc.). Unknown fields are captured into ``extra_params``.
        on_progress: Optional callback invoked on each polling cycle with a
            [VideoGenerationUpdate][]. Accepts both sync and async callables.

    Returns:
        [VideoGenerationResponse][] with the video URL, status, and full
        ``execution_metadata`` including timing and fallback attempts.

    Raises:
        TarashException: If generation fails on all providers in the fallback
            chain.

    Example:
        ```python
        from tarash.tarash_gateway import generate_video
        from tarash.tarash_gateway.models import VideoGenerationConfig, VideoGenerationRequest

        config = VideoGenerationConfig(
            provider="fal",
            model="fal-ai/veo3",
            api_key="FAL_KEY",
        )
        request = VideoGenerationRequest(
            prompt="A cat playing piano, cinematic lighting",
            duration_seconds=4,
            aspect_ratio="16:9",
        )
        response = generate_video(config, request)
        print(response.video)
        ```
    """
    log_info(
        "Video generation request received (sync)",
        context={
            "config": config,
            "request": request,
        },
        redact=True,
        logger_name="tarash.tarash_gateway.api",
    )

    # Delegate to orchestrator (handles mock, fallbacks, and execution)
    return _ORCHESTRATOR.execute_sync(config, request, on_progress=on_progress)

generate_image_async async

generate_image_async(
    config: ImageGenerationConfig,
    request: ImageGenerationRequest,
    on_progress: ImageProgressCallback | None = None,
) -> ImageGenerationResponse

Generate an image asynchronously using the configured provider.

Runs the full orchestration pipeline for image generation and returns a unified response. Automatically falls back to config.fallback_configs on retryable errors.

Parameters:

Name Type Description Default
config ImageGenerationConfig

Provider configuration including API key, model, timeout, and optional fallback chain.

required
request ImageGenerationRequest

Image generation parameters (prompt, size, quality, style, etc.). Unknown fields are captured into extra_params.

required
on_progress ImageProgressCallback | None

Optional callback invoked with an ImageGenerationUpdate during generation. Accepts both sync and async callables.

None

Returns:

Type Description
ImageGenerationResponse

ImageGenerationResponse containing a list of generated images

ImageGenerationResponse

(base64 or URL), status, and execution_metadata.

Raises:

Type Description
TarashException

If generation fails on all providers in the fallback chain.

NotImplementedError

If the configured provider does not support image generation.

Example
import asyncio
from tarash.tarash_gateway import generate_image_async
from tarash.tarash_gateway.models import ImageGenerationConfig, ImageGenerationRequest

async def main():
    config = ImageGenerationConfig(provider="openai", api_key="OPENAI_KEY")
    request = ImageGenerationRequest(
        prompt="A futuristic cityscape at dusk, photorealistic",
        size="1024x1024",
        quality="hd",
    )
    response = await generate_image_async(config, request)
    print(response.images[0])

asyncio.run(main())
Source code in packages/tarash-gateway/src/tarash/tarash_gateway/api.py
async def generate_image_async(
    config: ImageGenerationConfig,
    request: ImageGenerationRequest,
    on_progress: ImageProgressCallback | None = None,
) -> ImageGenerationResponse:
    """Generate an image asynchronously using the configured provider.

    Runs the full orchestration pipeline for image generation and returns a
    unified response. Automatically falls back to ``config.fallback_configs``
    on retryable errors.

    Args:
        config: Provider configuration including API key, model, timeout, and
            optional fallback chain.
        request: Image generation parameters (prompt, size, quality, style,
            etc.). Unknown fields are captured into ``extra_params``.
        on_progress: Optional callback invoked with an [ImageGenerationUpdate][]
            during generation. Accepts both sync and async callables.

    Returns:
        [ImageGenerationResponse][] containing a list of generated images
        (base64 or URL), status, and ``execution_metadata``.

    Raises:
        TarashException: If generation fails on all providers in the fallback
            chain.
        NotImplementedError: If the configured provider does not support image
            generation.

    Example:
        ```python
        import asyncio
        from tarash.tarash_gateway import generate_image_async
        from tarash.tarash_gateway.models import ImageGenerationConfig, ImageGenerationRequest

        async def main():
            config = ImageGenerationConfig(provider="openai", api_key="OPENAI_KEY")
            request = ImageGenerationRequest(
                prompt="A futuristic cityscape at dusk, photorealistic",
                size="1024x1024",
                quality="hd",
            )
            response = await generate_image_async(config, request)
            print(response.images[0])

        asyncio.run(main())
        ```
    """
    log_info(
        "Image generation request received (async)",
        context={
            "config": config,
            "request": request,
        },
        logger_name="tarash.tarash_gateway.api",
        redact=True,
    )

    # Delegate to orchestrator
    return await _ORCHESTRATOR.execute_image_async(
        config, request, on_progress=on_progress
    )

generate_image

generate_image(
    config: ImageGenerationConfig,
    request: ImageGenerationRequest,
    on_progress: ImageProgressCallback | None = None,
) -> ImageGenerationResponse

Generate an image synchronously using the configured provider.

Blocking version of [generate_image_async][]. Runs the full orchestration pipeline and returns only when generation is complete. Automatically falls back to config.fallback_configs on retryable errors.

Parameters:

Name Type Description Default
config ImageGenerationConfig

Provider configuration including API key, model, timeout, and optional fallback chain.

required
request ImageGenerationRequest

Image generation parameters (prompt, size, quality, style, etc.). Unknown fields are captured into extra_params.

required
on_progress ImageProgressCallback | None

Optional callback invoked with an ImageGenerationUpdate during generation. Accepts both sync and async callables.

None

Returns:

Type Description
ImageGenerationResponse

ImageGenerationResponse containing a list of generated images

ImageGenerationResponse

(base64 or URL), status, and execution_metadata.

Raises:

Type Description
TarashException

If generation fails on all providers in the fallback chain.

NotImplementedError

If the configured provider does not support image generation.

Example
from tarash.tarash_gateway import generate_image
from tarash.tarash_gateway.models import ImageGenerationConfig, ImageGenerationRequest

config = ImageGenerationConfig(provider="openai", api_key="OPENAI_KEY")
request = ImageGenerationRequest(
    prompt="A futuristic cityscape at dusk, photorealistic",
    size="1024x1024",
    quality="hd",
)
response = generate_image(config, request)
print(response.images[0])
Source code in packages/tarash-gateway/src/tarash/tarash_gateway/api.py
def generate_image(
    config: ImageGenerationConfig,
    request: ImageGenerationRequest,
    on_progress: ImageProgressCallback | None = None,
) -> ImageGenerationResponse:
    """Generate an image synchronously using the configured provider.

    Blocking version of [generate_image_async][]. Runs the full orchestration
    pipeline and returns only when generation is complete. Automatically falls
    back to ``config.fallback_configs`` on retryable errors.

    Args:
        config: Provider configuration including API key, model, timeout, and
            optional fallback chain.
        request: Image generation parameters (prompt, size, quality, style,
            etc.). Unknown fields are captured into ``extra_params``.
        on_progress: Optional callback invoked with an [ImageGenerationUpdate][]
            during generation. Accepts both sync and async callables.

    Returns:
        [ImageGenerationResponse][] containing a list of generated images
        (base64 or URL), status, and ``execution_metadata``.

    Raises:
        TarashException: If generation fails on all providers in the fallback
            chain.
        NotImplementedError: If the configured provider does not support image
            generation.

    Example:
        ```python
        from tarash.tarash_gateway import generate_image
        from tarash.tarash_gateway.models import ImageGenerationConfig, ImageGenerationRequest

        config = ImageGenerationConfig(provider="openai", api_key="OPENAI_KEY")
        request = ImageGenerationRequest(
            prompt="A futuristic cityscape at dusk, photorealistic",
            size="1024x1024",
            quality="hd",
        )
        response = generate_image(config, request)
        print(response.images[0])
        ```
    """
    log_info(
        "Image generation request received (sync)",
        context={
            "config": config,
            "request": request,
        },
        redact=True,
        logger_name="tarash.tarash_gateway.api",
    )

    # Delegate to orchestrator
    return _ORCHESTRATOR.execute_image_sync(config, request, on_progress=on_progress)

generate_tts_async async

generate_tts_async(
    config: AudioGenerationConfig,
    request: TTSRequest,
    on_progress: TTSProgressCallback | None = None,
) -> TTSResponse

Generate speech from text asynchronously using the configured provider.

Parameters:

Name Type Description Default
config AudioGenerationConfig

Provider configuration including API key, model, and timeout.

required
request TTSRequest

TTS parameters (text, voice_id, output_format, etc.).

required
on_progress TTSProgressCallback | None

Optional callback invoked during generation.

None

Returns:

Type Description
TTSResponse

TTSResponse with base64-encoded audio and metadata.

Raises:

Type Description
TarashException

If generation fails on all providers in the fallback chain.

NotImplementedError

If the configured provider does not support TTS.

Source code in packages/tarash-gateway/src/tarash/tarash_gateway/api.py
async def generate_tts_async(
    config: AudioGenerationConfig,
    request: TTSRequest,
    on_progress: TTSProgressCallback | None = None,
) -> TTSResponse:
    """Generate speech from text asynchronously using the configured provider.

    Args:
        config: Provider configuration including API key, model, and timeout.
        request: TTS parameters (text, voice_id, output_format, etc.).
        on_progress: Optional callback invoked during generation.

    Returns:
        [TTSResponse][] with base64-encoded audio and metadata.

    Raises:
        TarashException: If generation fails on all providers in the fallback chain.
        NotImplementedError: If the configured provider does not support TTS.
    """
    log_info(
        "TTS generation request received (async)",
        context={
            "config": config,
            "request": request,
        },
        logger_name="tarash.tarash_gateway.api",
        redact=True,
    )

    return await _ORCHESTRATOR.execute_tts_async(
        config, request, on_progress=on_progress
    )

generate_tts

generate_tts(
    config: AudioGenerationConfig,
    request: TTSRequest,
    on_progress: TTSProgressCallback | None = None,
) -> TTSResponse

Generate speech from text synchronously using the configured provider.

Parameters:

Name Type Description Default
config AudioGenerationConfig

Provider configuration including API key, model, and timeout.

required
request TTSRequest

TTS parameters (text, voice_id, output_format, etc.).

required
on_progress TTSProgressCallback | None

Optional callback invoked during generation.

None

Returns:

Type Description
TTSResponse

TTSResponse with base64-encoded audio and metadata.

Raises:

Type Description
TarashException

If generation fails on all providers in the fallback chain.

NotImplementedError

If the configured provider does not support TTS.

Source code in packages/tarash-gateway/src/tarash/tarash_gateway/api.py
def generate_tts(
    config: AudioGenerationConfig,
    request: TTSRequest,
    on_progress: TTSProgressCallback | None = None,
) -> TTSResponse:
    """Generate speech from text synchronously using the configured provider.

    Args:
        config: Provider configuration including API key, model, and timeout.
        request: TTS parameters (text, voice_id, output_format, etc.).
        on_progress: Optional callback invoked during generation.

    Returns:
        [TTSResponse][] with base64-encoded audio and metadata.

    Raises:
        TarashException: If generation fails on all providers in the fallback chain.
        NotImplementedError: If the configured provider does not support TTS.
    """
    log_info(
        "TTS generation request received (sync)",
        context={
            "config": config,
            "request": request,
        },
        redact=True,
        logger_name="tarash.tarash_gateway.api",
    )

    return _ORCHESTRATOR.execute_tts_sync(config, request, on_progress=on_progress)

generate_sts_async async

generate_sts_async(
    config: AudioGenerationConfig,
    request: STSRequest,
    on_progress: STSProgressCallback | None = None,
) -> STSResponse

Convert speech to speech asynchronously using the configured provider.

Parameters:

Name Type Description Default
config AudioGenerationConfig

Provider configuration including API key, model, and timeout.

required
request STSRequest

STS parameters (audio, voice_id, output_format, etc.).

required
on_progress STSProgressCallback | None

Optional callback invoked during generation.

None

Returns:

Type Description
STSResponse

STSResponse with base64-encoded audio and metadata.

Raises:

Type Description
TarashException

If generation fails on all providers in the fallback chain.

NotImplementedError

If the configured provider does not support STS.

Source code in packages/tarash-gateway/src/tarash/tarash_gateway/api.py
async def generate_sts_async(
    config: AudioGenerationConfig,
    request: STSRequest,
    on_progress: STSProgressCallback | None = None,
) -> STSResponse:
    """Convert speech to speech asynchronously using the configured provider.

    Args:
        config: Provider configuration including API key, model, and timeout.
        request: STS parameters (audio, voice_id, output_format, etc.).
        on_progress: Optional callback invoked during generation.

    Returns:
        [STSResponse][] with base64-encoded audio and metadata.

    Raises:
        TarashException: If generation fails on all providers in the fallback chain.
        NotImplementedError: If the configured provider does not support STS.
    """
    log_info(
        "STS generation request received (async)",
        context={
            "config": config,
            "request": request,
        },
        logger_name="tarash.tarash_gateway.api",
        redact=True,
    )

    return await _ORCHESTRATOR.execute_sts_async(
        config, request, on_progress=on_progress
    )

generate_sts

generate_sts(
    config: AudioGenerationConfig,
    request: STSRequest,
    on_progress: STSProgressCallback | None = None,
) -> STSResponse

Convert speech to speech synchronously using the configured provider.

Parameters:

Name Type Description Default
config AudioGenerationConfig

Provider configuration including API key, model, and timeout.

required
request STSRequest

STS parameters (audio, voice_id, output_format, etc.).

required
on_progress STSProgressCallback | None

Optional callback invoked during generation.

None

Returns:

Type Description
STSResponse

STSResponse with base64-encoded audio and metadata.

Raises:

Type Description
TarashException

If generation fails on all providers in the fallback chain.

NotImplementedError

If the configured provider does not support STS.

Source code in packages/tarash-gateway/src/tarash/tarash_gateway/api.py
def generate_sts(
    config: AudioGenerationConfig,
    request: STSRequest,
    on_progress: STSProgressCallback | None = None,
) -> STSResponse:
    """Convert speech to speech synchronously using the configured provider.

    Args:
        config: Provider configuration including API key, model, and timeout.
        request: STS parameters (audio, voice_id, output_format, etc.).
        on_progress: Optional callback invoked during generation.

    Returns:
        [STSResponse][] with base64-encoded audio and metadata.

    Raises:
        TarashException: If generation fails on all providers in the fallback chain.
        NotImplementedError: If the configured provider does not support STS.
    """
    log_info(
        "STS generation request received (sync)",
        context={
            "config": config,
            "request": request,
        },
        redact=True,
        logger_name="tarash.tarash_gateway.api",
    )

    return _ORCHESTRATOR.execute_sts_sync(config, request, on_progress=on_progress)