Python SDK
pip install halationlabQuickstart
Section titled “Quickstart”# Generates a 5-second video with the Python SDK and prints its download URL. Spends at most 400 tokens.import os
from halationlab import HalationLab
client = HalationLab(api_key=os.environ["HALATIONLAB_API_KEY"])
# run() starts the generation and waits until it is completed, failed or canceled.generation = client.generations.run( model="seedance-2.5", input={"prompt": "A red fox running through snow", "duration": 5, "aspect_ratio": "16:9"}, max_cost=400,)
print(generation["status"], generation["cost"]["charged"], generation["outputs"][0]["url"] if generation["outputs"] else None)client.generations.run() starts a generation and waits until it is final. Every write sends an Idempotency-Key for you, so retries are safe.
Clients
Section titled “Clients”HalationLab is synchronous. AsyncHalationLab has the same methods, awaited:
# The async Python client. Spends at most 100 tokens.import asyncioimport os
from halationlab import AsyncHalationLab
async def main() -> None: client = AsyncHalationLab(api_key=os.environ["HALATIONLAB_API_KEY"]) generation = await client.generations.run( model="flux.2-pro", input={"prompt": "A red ceramic mug on a linen tablecloth"}, max_cost=100, ) print(generation["id"], generation["status"])
asyncio.run(main())Resources
Section titled “Resources”The Python SDK mirrors the TypeScript SDK in snake_case: client.generations, client.quotes, client.models, client.projects, client.assets (including client.assets.upload(path)), client.uploads, client.account, client.webhook_endpoints and client.events. Webhook verification is halationlab.webhooks.verify(body, headers, secret).
Errors
Section titled “Errors”Failed requests raise halationlab.HalationLabError with type, code, status, param and request_id, from the error object.
# The Python SDK: a client, a few reads and typed errors. AsyncHalationLab has the same methods, awaited.import os
import halationlabfrom halationlab import HalationLab
client = HalationLab(api_key=os.environ["HALATIONLAB_API_KEY"])
account = client.account.get()print(account["credential"]["name"], account["balance"]["available"] if account["balance"] else None)
models = client.models.list(task="text-to-video")for model in models["data"]: print(model["id"], model["name"])
try: client.models.get("not-a-model")except halationlab.HalationLabError as e: print(e.status, e.type, e.code, e.param, e.request_id)Uploads and webhooks
Section titled “Uploads and webhooks”# Uploads a local file with the Python SDK, which hashes it, sends the parts and waits for the asset.import osimport sys
from halationlab import HalationLab
client = HalationLab(api_key=os.environ["HALATIONLAB_API_KEY"])
asset = client.assets.upload(sys.argv[1] if len(sys.argv) > 1 else "product.png")print(asset["id"], asset["status"])# Verifies a webhook with the Python SDK. Pass the raw body exactly as received, not re-serialised JSON.import os
import halationlab
def handle(raw_body: bytes, headers: dict) -> dict: # Raises if the signature or timestamp is not valid. return halationlab.webhooks.verify(raw_body, headers, os.environ["HL_WEBHOOK_SECRET"])