Skip to main content

Magic Hour for Haystack

Generate images with Magic Hour in Haystack pipelines. Creating an image and retrieving it are separate components, so you can save the project ID in between and resume a job without paying for it again.

It uses the z-image-turbo model and makes one square 640-pixel image per call.

Install

pip install magic-hour-haystack

Requires Python 3.11 or newer and Haystack 3.0 or newer. Set MAGIC_HOUR_API_KEY to a key from your Magic Hour developer dashboard.

Components

Component Input Output
MagicHourImageGenerator prompt project_id, credits_charged. Starts one paid job.
MagicHourImageWaiter project_id project, once the job completes
MagicHourImageDownloader project images as ByteStreams, and project_id

Save the project ID from the generator, then wait for and download it in a second pipeline:

from haystack import Pipeline
from magic_hour_haystack import (
    MagicHourImageDownloader,
    MagicHourImageGenerator,
    MagicHourImageWaiter,
)

create = Pipeline()
create.add_component("generate", MagicHourImageGenerator())
project_id = create.run({"generate": {"prompt": "A tiny orange paper bird"}})["generate"]["project_id"]
# Save project_id somewhere durable before waiting.

fetch = Pipeline()
fetch.add_component("wait", MagicHourImageWaiter())
fetch.add_component("download", MagicHourImageDownloader())
fetch.connect("wait.project", "download.project")
images = fetch.run({"wait": {"project_id": project_id}})["download"]["images"]

Running the second pipeline again with the same ID retrieves the same image, with fresh download URLs. examples/image_pipeline.py does this from the command line, saving the ID to a file between the two steps.

MagicHourImageWaiter takes timeout (default 300 seconds) and poll_interval (default 5 seconds).

Credits and failures

  • The generator never retries. If its request fails, the job may still have been accepted, so check your Magic Hour projects before generating again.
  • Waiter errors name the project, so you can run the waiter again with the same ID. A timeout doesn't cancel the job.
  • The API key only goes to api.magichour.ai. The downloader sends no key, and only downloads over HTTPS from videos.magichour.ai. No request follows redirects.

Saving pipelines

The components read the key from MAGIC_HOUR_API_KEY, and a saved pipeline stores only the variable's name. To load one, allow the module:

Pipeline.loads(saved_yaml, allowed_modules=["magic_hour_haystack.components"])

Development

pip install -e .
python -m unittest discover -s tests

The tests replace HTTP with a fake, so they spend no credits. Set HAYSTACK_TELEMETRY_ENABLED=false to stop Haystack sending usage data while you work.

License

MIT

Metadata

Release files for magic-hour-haystack 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for magic-hour-haystack 0.1.1
File Size Uploaded Provenance Actions
magic_hour_haystack-0.1.1.tar.gz 8.3 kB With provenance Details for magic_hour_haystack-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for magic-hour-haystack 0.1.1
File Interpreter ABI Platform Actions
magic_hour_haystack-0.1.1-py3-none-any.whl Python 3 none any Details for magic_hour_haystack-0.1.1-py3-none-any.whl

Total release size: 14.3 kB

Release files / magic_hour_haystack-0.1.1.tar.gz

Download URL magic_hour_haystack-0.1.1.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c7f32db5addf30d71308abbafcf09e917d26a1de0b0e8946ebdf20440980f8b5
BLAKE2b-256 checksum
How to use checksums
4d85601ec1ec02d43e68e549548cacfc351c37974a931f9bd43516af4171165f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / magic_hour_haystack-0.1.1-py3-none-any.whl

Download URL magic_hour_haystack-0.1.1-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
deebc5be69fda11d154b611eb8aed1956e7434cf7b3d53b12b12e931ffb8c126
BLAKE2b-256 checksum
How to use checksums
ce28e77d65446020afc9f276a3a49dac71d76851cb2f7f4ef9ac2d9bf0b2ebac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for magic-hour-haystack 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for magic_hour_haystack-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page