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_retriesother than 0, and the example proxy config setsnum_retries: 0. Don't add fallbacks or retry middleware for this model. - After acceptance, errors name the project. Resume with
magic_hour_project_idinstead 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.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| magic_hour_litellm-0.1.2.tar.gz | 9.6 kB | With provenance | Details for magic_hour_litellm-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| magic_hour_litellm-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for magic_hour_litellm-0.1.2-py3-none-any.whl |
Total release size: 17.1 kB
Release files / magic_hour_litellm-0.1.2.tar.gz
| Download URL | magic_hour_litellm-0.1.2.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0efb7884cce5dfec90af3bbe8ffe5c7e376248a3922ebbd4fdbda297c50cc7f6
|
|
BLAKE2b-256 checksum How to use checksums |
d0a079bc7aaa99c3d410d27eddeb91af219d7b9e1e9d50ba4844d73306cac376
|
| 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 28, 2026.
Transparency logRelease files / magic_hour_litellm-0.1.2-py3-none-any.whl
| Download URL | magic_hour_litellm-0.1.2-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aaa2a43b3eeaf52a2a786b8677197a8b450a0eb4bd961d3696c54a7f57ddf8ea
|
|
BLAKE2b-256 checksum How to use checksums |
3f8d6c23525b6922eef90b701476eafc07c02064f7d05c3eb83e0d0b83ae137e
|
| 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 28, 2026.
Transparency logSecurity for magic-hour-litellm 0.1.2
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.
Attestation for magic_hour_litellm-0.1.2.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 28, 2026.
Transparency logA 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.