Uploading media
There are four ways to get a file into HalationLab.ai. All of them end with an asset in a project.
| Your file is | Use | Limit |
|---|---|---|
| Online | Its URL, directly in a generation’s input |
As for an import |
| Online | POST /v1/assets with url |
Up to 100 MB; the server must answer within 20 seconds |
| Small and local | POST /v1/assets with data (a data URI) |
About 700 KB; request bodies are limited to 1 MiB |
| Large and local | POST /v1/uploads, then PUT the bytes |
16 MiB per PUT; larger files are sent in 16 MiB parts |
Supported files: JPEG, PNG and WebP images; MP4, MOV and WebM video; MP3, WAV and M4A audio. Other types are refused with 415 unsupported_media_type.
Import from a URL
Section titled “Import from a URL”# Imports a file from a public HTTPS URL into the default project. The asset is `processing` until it is checked.set -euo pipefailAPI="${HL_API_BASE:-https://api.halationlab.ai/v1}"IMAGE="${HL_SAMPLE_IMAGE_URL:-https://docs.halationlab.ai/media/sample-image.png}"
curl -sS --fail-with-body "$API/assets" \ -H "Authorization: Bearer $HALATIONLAB_API_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d "{ \"url\": \"$IMAGE\", \"name\": \"Sample image\" }"The URL must be a public HTTPS URL. The answer is the asset with status: "processing" while the file is checked, usually a few seconds; then it is ready or failed. Read it with GET /v1/assets/{id}. A URL that cannot be fetched is 422 media_fetch_failed.
You can also put the URL straight into a generation’s input. It is imported first; if the check takes longer than about 20 seconds, the generation request answers 409 media_not_ready with Retry-After. Send the identical request again with the same Idempotency-Key and it continues where it stopped.
Send a small file inline
Section titled “Send a small file inline”# Sends a small local file inline as a data URI (up to about 700 KB). Use an upload for anything larger.set -euo pipefailAPI="${HL_API_BASE:-https://api.halationlab.ai/v1}"FILE="${1:-$(dirname "$0")/../../public/media/sample-image.png}"
data="data:image/png;base64,$(base64 < "$FILE" | tr -d '\n')"curl -sS --fail-with-body "$API/assets" \ -H "Authorization: Bearer $HALATIONLAB_API_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d @- <<JSON{ "data": "$data", "name": "Inline sample" }JSONUpload a large file
Section titled “Upload a large file”POST /v1/uploadswithname,content_type,sizeandsha256(the SHA-256 of the whole file, as 64 lower-case hex characters). The upload URLs only accept these exact bytes.- PUT each part to its
url, with theheadersgiven, exactly as given. A file up to 16 MiB is one PUT; a larger file is sent in parts ofpart_sizebytes. Keep each part’sETagresponse header. POST /v1/uploads/{id}/complete, with{"parts": [{"part_number", "etag"}]}for a multi-part upload, or{}for a single PUT.- Read
GET /v1/uploads/{id}untilstatusiscompleted, then use itsasset. It isprocessingwhile the file is checked.
The upload’s parts may list only the next parts to send. GET /v1/uploads/{id} issues fresh URLs for the parts not yet received, and received_parts lists those that arrived, so an interrupted upload can resume. An unfinished upload is discarded at expires_at.
With the Python standard library:
# Uploads a local file of any size with the standard library: start the upload with its SHA-256, PUT each part,# complete it, then wait until its asset is ready. Usage: python3 upload.py path/to/fileimport hashlibimport jsonimport mathimport mimetypesimport osimport sysimport timeimport urllib.requestimport uuid
API = os.environ.get("HL_API_BASE", "https://api.halationlab.ai/v1")KEY = os.environ["HALATIONLAB_API_KEY"]DEFAULT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "public", "media", "sample-image.png")path = sys.argv[1] if len(sys.argv) > 1 else DEFAULT
def call(method: str, route: str, body: dict | None = None) -> dict: headers = {"Authorization": f"Bearer {KEY}", "Content-Type": "application/json"} if method != "GET": headers["Idempotency-Key"] = str(uuid.uuid4()) data = json.dumps(body).encode() if body is not None else None request = urllib.request.Request(f"{API}{route}", data=data, method=method, headers=headers) with urllib.request.urlopen(request, timeout=60) as response: return json.load(response)
with open(path, "rb") as f: content = f.read()upload = call("POST", "/uploads", { "name": os.path.basename(path), "content_type": mimetypes.guess_type(path)[0] or "application/octet-stream", "size": len(content), "sha256": hashlib.sha256(content).hexdigest(),})
# One PUT up to 16 MiB; larger files use parts of `part_size` bytes. The response may list only the next parts:# reading the upload again issues URLs for the parts still missing.part_size = upload["part_size"]total = math.ceil(len(content) / part_size) if part_size else 1etags: dict[int, str] = {}while len(etags) < total: for part in upload["parts"]: n = part["part_number"] if n in etags: continue chunk = content[(n - 1) * part_size: n * part_size] if part_size else content put = urllib.request.Request(part["url"], data=chunk, method="PUT", headers=part["headers"]) with urllib.request.urlopen(put, timeout=300) as response: etags[n] = response.headers["ETag"] if len(etags) < total: upload = call("GET", f"/uploads/{upload['id']}")
parts = [{"part_number": n, "etag": etag} for n, etag in sorted(etags.items())]upload = call("POST", f"/uploads/{upload['id']}/complete", {"parts": parts} if part_size else {})
# The file is checked before it can be used; this usually takes seconds.while upload["status"] == "processing": time.sleep(2) upload = call("GET", f"/uploads/{upload['id']}")if upload["status"] != "completed": sys.exit(f"Upload {upload['status']}: {upload['error']}")print("asset", upload["asset"])The SDKs do all of this in one call:
// Uploads a local file with the TypeScript SDK, which hashes it, sends the parts and waits for the asset.import { HalationLab } from '@halationlab/sdk';
const hl = new HalationLab({ apiKey: process.env.HALATIONLAB_API_KEY });
const asset = await hl.assets.upload(process.argv[2] ?? 'product.png');console.log(asset.id, asset.status);# 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"])Use the asset
Section titled “Use the asset”Pass the asset ID as a media input, for example "first_frame": "asset_…". Generated outputs are assets too: pass outputs[0].asset, or the generation ID for its first output.
Asset download URLs need no credentials and expire at url_expires_at (one hour). Read the asset again for a fresh URL. url is null unless status is ready.
Crop, trim and resize
Section titled “Crop, trim and resize”POST /v1/assets/{id}/transform makes a copy with crop (a rectangle in source pixels), trim (start and end in seconds, for video and audio) or resize (width and height in pixels), or a combination. The copy is a new asset with origin: "derived".
{ "crop": { "x": 0, "y": 140, "width": 1080, "height": 1080 } }Delete
Section titled “Delete”DELETE /v1/assets/{id} moves an asset to the account’s trash, from which the owner can restore it in the app for 30 days.