Sunra manages endpoint requests through a queue system, ensuring reliability and scalability. Use the subscribe method to submit a request and await the result.Example:
Copy
import sunra_clientresult = sunra_client.subscribe( "black-forest-labs/flux-kontext-pro/text-to-image", arguments={ "prompt": 'A Studio Ghibli-inspired seaside town with colorful houses, laundry flapping, and cats sleeping on windowsills.', "width": 1024, "height": 768, "output_format": 'jpeg' }, with_logs=True, on_enqueue=print, on_queue_update=print,)print(result)
Upload files to obtain URLs for use in asynchronous requests. This is essential for models that process files, such as image-to-video or speech-to-text converters.
Maximum file size: 100MB
Uploading a Local File
You can easily upload a file from your local filesystem. This is useful for scripts or applications that process local data.
Copy
import sunra_client# Initialize the synchronous clientclient = sunra_client.SyncClient()try: # Upload a file from a given path file_url = client.upload_file(path="path/to/your/image.png") print(f"File uploaded successfully: {file_url}") # This URL can now be used with a model endpointexcept FileNotFoundError: print("Error: The file was not found at the specified path.")except Exception as e: print(f"An error occurred: {e}")
Uploading In-Memory Data
You can also upload data that is held in memory, such as the content of an image created with PIL (Pillow) or a file received in a web request.
Copy
import sunra_clientfrom PIL import Imageimport io# Initialize the synchronous clientclient = sunra_client.SyncClient()# Create an image in memory, for example with Pillowimage = Image.new("RGB", (600, 400), color = 'red')byte_arr = io.BytesIO()image.save(byte_arr, format='PNG')image_bytes = byte_arr.getvalue()# Upload the in-memory image data using the `upload` methodimage_url = client.upload( data=image_bytes, content_type="image/png")print(f"Image uploaded successfully: {image_url}")