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 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. |
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
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. |
required |
model_mappings
|
dict[str, dict[str, FieldMapper]]
|
Mapping from model name (or prefix) to a dict of
|
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
get_provider_field_mapping
¶
Return the field mapper registry for a provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
str
|
Provider identifier (e.g. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, FieldMapper]] | None
|
A mapping of model name/prefix → field mapper dict, or |
dict[str, dict[str, FieldMapper]] | None
|
no mapping has been registered for the provider. |
Example
Source code in packages/tarash-gateway/src/tarash/tarash_gateway/api.py
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 |
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
|
|
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
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 |
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
|
|
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
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 |
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 |
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
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 |
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 |
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
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
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
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
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. |