Skip to main content

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 fails
  • TimeoutError: Raised when the prediction doesn't complete within the specified timeout
  • ValueError: Raised when required parameters are missing or invalid
  • httpx.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

synexa-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

synexa-0.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file synexa-0.1.0.tar.gz.

File metadata

  • Download URL: synexa-0.1.0.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

Hashes for synexa-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4b80b6dfc046b892494f5cc7e4c58bcd3f46d87014bc8497220258bbe5723aa4
MD5 a65dfe0d3c8545d8d023974193592851
BLAKE2b-256 d560e2aff670aa4f62b4546dddf490fc4462605487dfe9f9ab96bb5bffe29261

See more details on using hashes here.

File details

Details for the file synexa-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: synexa-0.1.0-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

Hashes for synexa-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f0acd98d791862b664b6b8e878f22431ad4aac8fdf13c3695d6f406955efb583
MD5 59b53b94afe1f8cd21723f517a00d577
BLAKE2b-256 d3a184ed77ae0200a951051f964d614e227452d22e4e9fd66f50c1cf74618c7e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page