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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_magic_hour-0.1.0.tar.gz.
File metadata
- Download URL: langchain_magic_hour-0.1.0.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7435a26144a28be870cf910af3e67db3f7e78fd32ed1e4fc5d319ba976ca3a5a
|
|
| MD5 |
6cb965d5e6a7cb7fb992e8d0f01f1b3c
|
|
| BLAKE2b-256 |
47bb1601207447b2650f313bc3b0894445d93adde8b60cb273f862c84212f409
|
File details
Details for the file langchain_magic_hour-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_magic_hour-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
473d743447dbfb8804bea765b1a6791bcf9f3b62771d90c30e2c2b9ce11a7c4e
|
|
| MD5 |
94c9d1f29e036d4eb7ebae1342cf809a
|
|
| BLAKE2b-256 |
e6317ceb94ccda636298479e6aefd65278ba09f32f68410f7dc6cf88d3683613
|