langchain-magic-hour
LangChain tools for Magic Hour: AI text-to-video, image-to-video and image generation behind one API key. Models include Sora 2, Veo 3.1, Kling 3.0, Seedance, MiniMax H3, WAN 2.2, LTX 2.3 (video) and GPT-image, Nano Banana Pro, Seedream, Flux, Z-Image (image).
Built on the official magic_hour Python SDK. Sync and async. Works with langchain.agents.create_agent, LangGraph, or any LangChain tool-calling model.
Install
pip install langchain-magic-hour
# or
uv add langchain-magic-hour
Get a free API key at https://magichour.ai/developer (400 credits on signup + 100/day, no card) and export it:
export MAGIC_HOUR_API_KEY="mh_..."
Quickstart
from langchain_magic_hour import MagicHourTextToVideoTool, MagicHourToolkit
tool = MagicHourTextToVideoTool(download_dir="outputs") # download_dir is optional
print(
tool.invoke(
{"prompt": "a corgi surfing at golden hour", "model": "wan-2.2", "duration_seconds": 5}
)
)
# {"project_id": "...", "status": "complete", "model": "wan-2.2", "video_url": "https://...", "credits_charged": 120, ...}
# In an agent (pip install "langchain[anthropic]")
from langchain.agents import create_agent
agent = create_agent(model="claude-sonnet-4-6", tools=MagicHourToolkit().get_tools())
result = agent.invoke(
{
"messages": [
{
"role": "user",
"content": "Make a 5s clip of rain on a window, then a 16:9 poster image of the same scene.",
}
]
}
)
print(result["messages"][-1].content)
Tools
| Tool | name |
Inputs | Returns (JSON string) |
|---|---|---|---|
MagicHourTextToVideoTool |
magic_hour_text_to_video |
prompt, model="wan-2.2", duration_seconds=5, resolution="480p", aspect_ratio="16:9", audio, name |
project_id, status, video_url, video_urls, credits_charged, width, height, fps |
MagicHourImageToVideoTool |
magic_hour_image_to_video |
image_url_or_path (https URL or local file, uploaded automatically), prompt, model, duration_seconds, resolution, audio, name |
same as above |
MagicHourImageGenerationTool |
magic_hour_generate_image |
prompt, model="default", image_count=1, aspect_ratio="1:1", name |
project_id, status, image_urls, credits_charged |
MagicHourToolkit |
– | same constructor options | get_tools() returns all three |
Constructor options (all tools and the toolkit): api_key (defaults to MAGIC_HOUR_API_KEY), download_dir (download outputs locally and add downloaded_paths to the result; off by default), wait_for_completion=True (poll until done), timeout.
Errors (bad model/duration, insufficient credits, API errors) are returned as {"status": "error", "error": {...}} so an agent can recover instead of crashing. Failed jobs are auto-refunded by Magic Hour.
Video models
| Model | Durations (s) | Credits / sec | Notes |
|---|---|---|---|
wan-2.2 |
3-10, 15 | 24 | Free tier (default) |
ltx-2.3 |
1-10, 15, 20, 25, 30 | 24 | Free tier |
minimax-h3 |
1-10, 15, 20, 25, 30 | 24 | Free tier, max 1080p |
seedance-1.5 |
4-12 | 30 | |
kling-2.6 |
5, 10 | 36 | |
kling-3.0 |
3-15 | 48 | |
veo3.1-lite |
4, 6, 8, 16 ... 56 | 48 | |
veo3.1 / veo3.1-audio |
4, 6, 8, 16 ... 56 | 96 | native audio |
sora-2 |
4, 8, 12, 24, 36, 48, 60 | 120 | max 720p |
seedance-2.0-mini / seedance-2.0 |
4-15 | 96 / 120 | max 720p |
seedance-2.5 |
4-30 | 120 | max 720p |
Resolutions: 480p, 720p, 1080p. Aspect ratios: 16:9, 9:16, 1:1. A 5s 480p wan-2.2 clip costs 120 credits.
Image models: default, gpt-image-2, nano-banana-pro, seedream-5-pro, flux-2-klein, z-image-turbo, qwen-edit.
The model table is informational; unknown model ids are passed straight to the API so new models work without upgrading.
Async
result = await tool.ainvoke({"prompt": "..."})
Live example
examples/agent_demo.py runs the toolkit against the real API (needs MAGIC_HOUR_API_KEY):
uv run --with "langchain[anthropic]" examples/agent_demo.py
Development
uv sync --all-groups
uv run pytest # offline, SDK is mocked
uv build
Links
- Magic Hour API docs: https://docs.magichour.ai
- LangChain integration guide: docs/langchain-integration.md
- Other Magic Hour integrations: Vercel AI SDK provider (
magic-hour-ai-provideron npm), ComfyUI nodes, MCP server
MIT License.
Metadata
Release files for langchain-magic-hour 0.1.0
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 |
|---|---|---|---|---|
| langchain_magic_hour-0.1.0.tar.gz | 15.2 kB | Without provenance | Details for langchain_magic_hour-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_magic_hour-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for langchain_magic_hour-0.1.0-py3-none-any.whl |
Total release size: 28.2 kB
Release files / langchain_magic_hour-0.1.0.tar.gz
| Download URL | langchain_magic_hour-0.1.0.tar.gz |
|---|---|
| Size | 15.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7435a26144a28be870cf910af3e67db3f7e78fd32ed1e4fc5d319ba976ca3a5a
|
|
BLAKE2b-256 checksum How to use checksums |
47bb1601207447b2650f313bc3b0894445d93adde8b60cb273f862c84212f409
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / langchain_magic_hour-0.1.0-py3-none-any.whl
| Download URL | langchain_magic_hour-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
473d743447dbfb8804bea765b1a6791bcf9f3b62771d90c30e2c2b9ce11a7c4e
|
|
BLAKE2b-256 checksum How to use checksums |
e6317ceb94ccda636298479e6aefd65278ba09f32f68410f7dc6cf88d3683613
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for langchain-magic-hour 0.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.