Skip to main content

Magic Hour for LiteLLM

Generate images with Magic Hour through LiteLLM, from the SDK or the OpenAI-compatible proxy. It's a LiteLLM custom provider, not one built into LiteLLM.

It supports one model, z-image-turbo, and one square image per call.

Install

pip install magic-hour-litellm

Requires Python 3.10 or newer and LiteLLM 1.82 or newer. Set MAGIC_HOUR_API_KEY to a key from your Magic Hour developer dashboard.

SDK

from magic_hour_litellm import image_generation

image = image_generation(
    model="magichour/z-image-turbo",
    prompt="A blue ceramic mug on a warm white background",
    magic_hour_resolution="1k",
)
print(image.data[0].url)
print(image.data[0].provider_specific_fields)  # project_id, credits_charged, expires_at

await aimage_generation(...) takes the same arguments. Use these functions rather than litellm.image_generation: LiteLLM drops image options before calling a custom provider, and these pass them through. A plain litellm.image_generation call fails before any request.

Argument Values
model magichour/z-image-turbo
prompt Non-empty text
magic_hour_resolution 640px (default), 1k, 2k: the longest edge, not exact dimensions
magic_hour_project_id An accepted project to resume, without creating a new one
timeout Seconds to wait, up to 600 (the default)
n, size, response_format Only 1, auto and url

Anything else fails before a request is sent.

Proxy

pip install magic-hour-litellm 'litellm[proxy]' prisma
export LITELLM_MASTER_KEY='<a private proxy key>'
litellm --config examples/proxy.yaml --host 127.0.0.1 --port 4000

examples/proxy.yaml registers the provider and the magic_hour_litellm.proxy_hook callback, which passes the image options through. Keep the hook enabled. Without it, requests fail rather than lose their options. The hook covers the magic-hour-image model name. For another name, configure MagicHourProxyHook(model_names=(...)) in your own config module.

LiteLLM's proxy imports Prisma when it rejects a request, even with no database, which is why it's in the install line.

Call it with any OpenAI client. See examples/openai_client.py.

Credits and failures

Each new image is a paid Magic Hour job. The provider sends the create request once, then only polls that project.

  • Don't retry creates. The SDK functions refuse num_retries other than 0, and the example proxy config sets num_retries: 0. Don't add fallbacks or retry middleware for this model.
  • After acceptance, errors name the project. Resume with magic_hour_project_id instead of generating again. A timeout doesn't cancel the job.
  • If a create fails before returning an ID, the job may still have been accepted. Check your Magic Hour projects before creating again.
  • Download URLs expire. Resuming the same project returns a fresh one.

Errors don't include prompts, keys, signed URLs or response bodies. LiteLLM's own logging may, so configure it for your setup.

Development

pip install -e . 'litellm[proxy]'
python -m unittest discover -s tests

The tests replace HTTP with a fake, so they spend no credits.

License

MIT

Metadata

Release files for magic-hour-litellm 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-litellm 0.1.1
File Size Uploaded Provenance Actions
magic_hour_litellm-0.1.1.tar.gz 9.6 kB With provenance Details for magic_hour_litellm-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 17.0 kB

Release files / magic_hour_litellm-0.1.1.tar.gz

Download URL magic_hour_litellm-0.1.1.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d73b06f18e4f7c1f3ce0de542574a8264ac605c7831b3279027120bc840d54f2
BLAKE2b-256 checksum
How to use checksums
8ee584258658d634e5fe095620ebd661846910ac45360ece08af58dcc6003d9e
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_litellm-0.1.1-py3-none-any.whl

Download URL magic_hour_litellm-0.1.1-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c7e1826c418df013b1796f25d6f3a4f60ee21adfbaaa0049ba7a9862c16e8f41
BLAKE2b-256 checksum
How to use checksums
2a370c4b0133e44e1cee71d3b2fdf42421a24ac6877035a24c32e26ea08e36b6
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-litellm 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_litellm-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