Python client for Synexa AI API
Project description
Synexa Python Client
This is a Python client for Synexa AI. It lets you run AI models from your Python code or Jupyter notebook.
Requirements
- Python 3.8+
Installation
pip install synexa
Authentication
Before running any Python scripts that use the API, you need to set your Synexa API key in your environment:
export SYNEXA_API_KEY=your-api-key
Alternatively, you can pass the API key directly when creating a client:
client = synexa.Synexa(api_key="your-api-key")
Usage
Here's a simple example of how to use the client:
import synexa
# Run a model
output = synexa.run(
"black-forest-labs/flux-schnell",
input={"prompt": "An astronaut riding a rainbow unicorn, cinematic, dramatic"}
)
# Save the generated image
for i, img in enumerate(output):
with open(f'output_{i}.webp', 'wb') as f:
f.write(img.read())
Async Support
The client supports both synchronous and asynchronous operations. By default, it will wait for the prediction to complete (up to 60 seconds). You can modify this behavior:
# Don't wait for completion
output = synexa.run(
"black-forest-labs/flux-schnell",
input={"prompt": "An astronaut riding a rainbow unicorn"},
wait=False
)
# Wait with custom timeout (in seconds)
output = synexa.run(
"black-forest-labs/flux-schnell",
input={"prompt": "An astronaut riding a rainbow unicorn"},
wait=30
)
Error Handling
The client will raise exceptions for various error conditions:
ModelError: Raised when the prediction failsTimeoutError: Raised when the prediction doesn't complete within the specified timeoutValueError: Raised when required parameters are missing or invalidhttpx.HTTPError: Raised for HTTP-related errors
Example error handling:
from synexa import ModelError
try:
output = synexa.run(
"black-forest-labs/flux-schnell",
input={"prompt": "An astronaut riding a rainbow unicorn"}
)
except ModelError as e:
print(f"Prediction failed: {e}")
if e.prediction:
print(f"Prediction ID: {e.prediction['id']}")
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file synexa-0.1.1.tar.gz.
File metadata
- Download URL: synexa-0.1.1.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b8aaf91a1f39ce62fe4b98f7d74060fbda6f560bcf06288ecee8ebbc166d993
|
|
| MD5 |
b2cd73caaf437e563bd8a4dcfe89cce1
|
|
| BLAKE2b-256 |
b68be3d57cae56994ebd9ca14217c094032d5713045f8a10cee5c291be602881
|
File details
Details for the file synexa-0.1.1-py3-none-any.whl.
File metadata
- Download URL: synexa-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08d0f0652dfab7432bba43a67c9223ff4f4dfbaee0009ec0b32289530ecd80c1
|
|
| MD5 |
d946776a8964b83b95a5ebfbe7841bc2
|
|
| BLAKE2b-256 |
f6ff99f9beafc147af42f0fe880109ca5cb64404dfdc9e196a42946206164a4f
|