The official Python client library for Siray AI - a platform for AI-powered image and video generation.
Install the package using pip:
pip install sirayOr install from source:
git clone https://github.com/siray-ai/siray-python.git
cd siray-python
pip install .Get your API key from Siray AI Dashboard and set it as an environment variable:
export SIRAY_API_KEY="your-api-key-here"Or pass it directly when initializing the client:
from siray import Siray
client = Siray(api_key="your-api-key-here")from siray import Siray
client = Siray()
# Optional: load a local file and get a ready-to-use data URI
local_image = client.load_from_local("~/Pictures/input.jpg")
# Generate image asynchronously
response = client.image.generate_async(
model="black-forest-labs/flux-1.1-pro-ultra-i2i",
prompt="A beautiful sunset over mountains with vibrant colors",
image=local_image,
)
print(f"Task ID: {response.task_id}")
client.load_from_local(path)reads the file, infers the MIME type, and returns adata:<mime>;base64,...string accepted by the API. This is handy when you do not have a public URL for the asset you want to condition on.
# After starting an async generation, query its status
status = client.image.query_task(response.task_id)
if status.is_completed():
print(f"âś“ Completed!")
for i, url in enumerate(status.outputs, 1):
print(f" Image {i}: {url}")
elif status.is_processing():
print(f"⏳ Processing... {status.progress}")
elif status.is_failed():
print(f"âś— Failed: {status.fail_reason}")# Convenience helper that starts a task and polls until it finishes
status = client.image.run(
model="black-forest-labs/flux-1.1-pro-ultra-i2i",
prompt="A futuristic city skyline at dusk",
image="https://example.com/input-image.jpg",
poll_interval=2.0, # optional, defaults to 2 seconds
)
print(f"Final status: {status.status}")
if status.is_completed():
print(status.outputs)See
examples/blocking_generation.pyfor a full runnable script that usesimage.run().
from siray import Siray
client = Siray()
# Generate video asynchronously
response = client.video.generate_async(
model="your-video-model",
prompt="A cat playing piano in a cozy room"
)
print(f"Task ID: {response.task_id}")
# Or block until the task finishes
status = client.video.run(
model="your-video-model",
prompt="A cat playing piano in a cozy room",
)
print(status.status)A complete blocking flow for both media types lives in
examples/blocking_generation.py.
Main client for interacting with Siray AI API.
Parameters:
api_key(str, optional): API key for authentication. If not provided, reads fromSIRAY_API_KEYenvironment variable.base_url(str, optional): Base URL for the API. Default:https://api.siray.ai
Attributes:
image: Image generation namespacevideo: Video generation namespace
Generate an image asynchronously using image-to-image models.
Parameters:
model(str): Model identifier (e.g.,"black-forest-labs/flux-1.1-pro-ultra-i2i")prompt(str): Text prompt for image generationimage(str): Input image (URL or base64 encoded string)**kwargs: Additional model-specific parameters
Returns: GenerationResponse object with the following attributes:
task_id(str): Unique identifier for the generation taskraw_response(dict): Raw API response data
Query the status and result of an image generation task.
Parameters:
task_id(str): Task ID returned from the image generation request
Returns: TaskStatus object with the following attributes:
code(str): Response code (e.g., 'success')message(str): Response messagetask_id(str): Task identifieraction(str): Action type (e.g., 'imageGenerate')status(str): Current task status (e.g., 'SUCCESS', 'PENDING', 'FAILED')outputs(List[str]): List of output URLsfail_reason(str | None): Failure reason if task failedprogress(str | None): Progress string (e.g., '100%')submit_time(int | None): Unix timestamp when submittedstart_time(int | None): Unix timestamp when startedfinish_time(int | None): Unix timestamp when finishedresult(property): First output URL (for backward compatibility)progress_percent(property): Progress as integer (0-100)is_completed()(method): Check if task is completedis_processing()(method): Check if task is still processingis_failed()(method): Check if task has failed
Example:
# Start async generation
response = client.image.generate_async(
model="black-forest-labs/flux-kontext-i2i-max",
prompt="A beautiful sunset",
image="https://example.com/input.jpg"
)
# Query task status
status = client.image.query_task(response.task_id)
if status.is_completed():
print(f"Generated {len(status.outputs)} image(s)")
for url in status.outputs:
print(f" - {url}")
elif status.is_failed():
print(f"Error: {status.fail_reason}")Start an async image generation and continuously poll its status until it completes or fails.
Parameters:
model(str): Model identifierprompt(str): Text promptpoll_interval(float, optional): Seconds between status checks (minimum 0.1). Default:2.0timeout(float | None, optional): Maximum seconds to wait before raisingTimeoutError.Nonedisables the timeout.**kwargs: Additional model-specific parameters
Returns: TaskStatus with the final state of the task.
Raises:
TimeoutError: If the task is still processing when the timeout is reached
Generate a video asynchronously.
Parameters:
model(str): Model identifierprompt(str): Text prompt for video generation**kwargs: Additional model-specific parameters (e.g., duration, fps)
Returns: GenerationResponse object with the following attributes:
task_id(str): Unique identifier for the generation taskraw_response(dict): Raw API response data
Query the status and result of a video generation task.
Parameters:
task_id(str): Task ID returned from the video generation request
Returns: TaskStatus object (same structure as image query)
Example:
# Start async generation
response = client.video.generate_async(
model="your-video-model",
prompt="A cat playing piano"
)
# Query task status
status = client.video.query_task(response.task_id)
if status.is_completed():
print(f"Generated {len(status.outputs)} video(s)")
for url in status.outputs:
print(f" - {url}")
elif status.is_failed():
print(f"Error: {status.fail_reason}")Start an async video generation and wait for it to complete by polling the task status.
Parameters: Same as image.run.
Returns: Final TaskStatus.
Raises:
TimeoutError: If the task does not finish before the timeout
The SDK provides typed response objects instead of raw dictionaries:
Returned by generate_async() methods. Contains:
task_id: Unique task identifierraw_response: Raw API response datato_dict(): Convert to dictionary
Returned by query_task() method. Contains:
code: Response code (e.g., 'success')message: Response messagetask_id: Task identifieraction: Action type (e.g., 'imageGenerate')status: Current status (e.g., 'SUCCESS', 'PENDING', 'FAILED')outputs: List of output URLsfail_reason: Failure reason if task failedprogress: Progress string (e.g., '100%')submit_time: Unix timestamp when submittedstart_time: Unix timestamp when startedfinish_time: Unix timestamp when finishedresult(property): First output URL (backward compatibility)progress_percent(property): Progress as integer (0-100)is_completed(): Check if completedis_processing(): Check if processingis_failed(): Check if failedto_dict(): Convert to dictionary
The SDK provides specific exception classes for different error scenarios:
from siray import Siray, SirayError, AuthenticationError, BadRequestError
client = Siray()
try:
result = client.image.generate_async(
model="black-forest-labs/flux-1.1-pro-ultra-i2i",
prompt="A beautiful sunset",
image="https://example.com/image.jpg"
)
except AuthenticationError as e:
print(f"Authentication failed: {e.message}")
except BadRequestError as e:
print(f"Invalid request: {e.message}")
print(f"Error code: {e.code}")
print(f"Error type: {e.error_type}")
except SirayError as e:
print(f"API error: {e.message}")
print(f"Status code: {e.status_code}")SirayError: Base exception for all SDK errorsAuthenticationError: Raised when authentication fails (401)BadRequestError: Raised when the request is invalid (400)InternalServerError: Raised when the server encounters an error (500)APIError: Raised for general API errors
See the examples directory for more comprehensive usage examples:
# Clone the repository
git clone https://github.com/siray-ai/siray-python.git
cd siray-python
# Install development dependencies
pip install -r requirements-dev.txt
# Install package in editable mode
pip install .pytest tests/# Format code
black siray/
# Check code style
flake8 siray/
# Sort imports
isort siray/
# Type checking
mypy siray/Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- Documentation: https://docs.siray.ai
- API Reference: https://docs.siray.ai/api-reference/
- Issues: https://github.com/siray-ai/siray-python/issues
- Email: support@siray.ai
See CHANGELOG.md for a list of changes in each release.