runapi-hailuo 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,24 @@
1
+ """Hailuo client for RunAPI."""
2
+
3
+ from runapi.core import (
4
+ AuthenticationError,
5
+ InsufficientCreditsError,
6
+ NotFoundError,
7
+ RateLimitError,
8
+ TaskFailedError,
9
+ TaskTimeoutError,
10
+ ValidationError,
11
+ )
12
+
13
+ from .client import HailuoClient
14
+
15
+ __all__ = [
16
+ "HailuoClient",
17
+ "AuthenticationError",
18
+ "RateLimitError",
19
+ "InsufficientCreditsError",
20
+ "NotFoundError",
21
+ "ValidationError",
22
+ "TaskFailedError",
23
+ "TaskTimeoutError",
24
+ ]
@@ -0,0 +1,29 @@
1
+ """Hailuo client."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Optional
6
+
7
+ from runapi.core import ClientOptions, HttpClient, resolve_api_key
8
+
9
+ from .resources.image_to_video import ImageToVideo
10
+ from .resources.text_to_video import TextToVideo
11
+
12
+
13
+ class HailuoClient:
14
+ """Hailuo text-to-video and image-to-video client.
15
+
16
+ Example::
17
+
18
+ client = HailuoClient(api_key="sk-...")
19
+ result = client.text_to_video.run(
20
+ model="hailuo-02-text-to-video-standard", prompt="A neon city street"
21
+ )
22
+ """
23
+
24
+ def __init__(self, api_key: Optional[str] = None, **options: Any) -> None:
25
+ resolved_api_key = resolve_api_key(api_key)
26
+ client_options = ClientOptions(api_key=resolved_api_key, **options)
27
+ http = client_options.http_client or HttpClient(client_options)
28
+ self.text_to_video = TextToVideo(http)
29
+ self.image_to_video = ImageToVideo(http)
runapi/hailuo/py.typed ADDED
File without changes
@@ -0,0 +1,4 @@
1
+ from .image_to_video import ImageToVideo
2
+ from .text_to_video import TextToVideo
3
+
4
+ __all__ = ["TextToVideo", "ImageToVideo"]
@@ -0,0 +1,102 @@
1
+ """Hailuo image-to-video resource."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Dict, Sequence
6
+
7
+ from runapi.core import Resource, ValidationError
8
+
9
+ from ..types import (
10
+ DURATIONS,
11
+ IMAGE_02_RESOLUTIONS,
12
+ IMAGE_23_RESOLUTIONS,
13
+ IMAGE_TO_VIDEO_MODELS,
14
+ CompletedVideoTaskResponse,
15
+ VideoTaskResponse,
16
+ )
17
+
18
+
19
+ class ImageToVideo(Resource):
20
+ """Generate videos from a source image with Hailuo models."""
21
+
22
+ ENDPOINT = "/api/v1/hailuo/image_to_video"
23
+
24
+ RESPONSE_CLASS = VideoTaskResponse
25
+ COMPLETED_RESPONSE_CLASS = CompletedVideoTaskResponse
26
+
27
+ def run(self, **params: Any) -> Any:
28
+ """Create an image-to-video task and poll until it completes.
29
+
30
+ Args:
31
+ **params: Image-to-video parameters (model, prompt, ...).
32
+
33
+ Returns:
34
+ The completed task with videos.
35
+ """
36
+ task = self.create(**params)
37
+ return self._poll_until_complete(lambda: self.get(task.id))
38
+
39
+ def create(self, **params: Any) -> Any:
40
+ """Create an image-to-video task and return immediately with an ``id``.
41
+
42
+ Args:
43
+ **params: Image-to-video parameters (model, prompt, ...).
44
+
45
+ Returns:
46
+ The task creation result with an id.
47
+ """
48
+ compacted = self._compact_params(params)
49
+ self._validate_params(compacted)
50
+ return self._request("post", self.ENDPOINT, body=compacted)
51
+
52
+ def get(self, id: str) -> Any:
53
+ """Fetch the current status of an image-to-video task.
54
+
55
+ Args:
56
+ id: The task id.
57
+
58
+ Returns:
59
+ The current task status.
60
+ """
61
+ return self._request("get", f"{self.ENDPOINT}/{id}")
62
+
63
+ def _validate_params(self, params: Dict[str, Any]) -> None:
64
+ model = params.get("model")
65
+ if model not in IMAGE_TO_VIDEO_MODELS:
66
+ raise ValidationError("model is required")
67
+ if not params.get("prompt"):
68
+ raise ValidationError("prompt is required")
69
+ if not params.get("first_frame_image_url"):
70
+ raise ValidationError("first_frame_image_url is required")
71
+
72
+ duration_seconds = params.get("duration_seconds")
73
+ output_resolution = params.get("output_resolution")
74
+
75
+ if duration_seconds and duration_seconds not in DURATIONS:
76
+ raise ValidationError(
77
+ f"duration_seconds must be one of: {', '.join(str(d) for d in DURATIONS)}"
78
+ )
79
+
80
+ if model == "hailuo-02-image-to-video-pro":
81
+ if duration_seconds:
82
+ raise ValidationError(f"duration_seconds is not supported for {model}")
83
+ if output_resolution:
84
+ raise ValidationError(f"output_resolution is not supported for {model}")
85
+ elif model == "hailuo-02-image-to-video-standard":
86
+ if output_resolution:
87
+ self._validate_output_resolution(output_resolution, IMAGE_02_RESOLUTIONS)
88
+ else:
89
+ if output_resolution:
90
+ self._validate_output_resolution(output_resolution, IMAGE_23_RESOLUTIONS)
91
+ if params.get("last_frame_image_url"):
92
+ raise ValidationError(f"last_frame_image_url is not supported for {model}")
93
+ if params.get("prompt_optimizer"):
94
+ raise ValidationError(f"prompt_optimizer is not supported for {model}")
95
+ if duration_seconds == 10 and str(output_resolution) == "1080p":
96
+ raise ValidationError("1080p does not support 10-second duration")
97
+
98
+ @staticmethod
99
+ def _validate_output_resolution(output_resolution: Any, allowed: Sequence[str]) -> None:
100
+ if str(output_resolution) in allowed:
101
+ return
102
+ raise ValidationError(f"output_resolution must be one of: {', '.join(allowed)}")
@@ -0,0 +1,77 @@
1
+ """Hailuo text-to-video resource."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Dict
6
+
7
+ from runapi.core import Resource, ValidationError
8
+
9
+ from ..types import (
10
+ DURATIONS,
11
+ TEXT_TO_VIDEO_MODELS,
12
+ CompletedVideoTaskResponse,
13
+ VideoTaskResponse,
14
+ )
15
+
16
+
17
+ class TextToVideo(Resource):
18
+ """Generate videos from text prompts with Hailuo models."""
19
+
20
+ ENDPOINT = "/api/v1/hailuo/text_to_video"
21
+
22
+ RESPONSE_CLASS = VideoTaskResponse
23
+ COMPLETED_RESPONSE_CLASS = CompletedVideoTaskResponse
24
+
25
+ def run(self, **params: Any) -> Any:
26
+ """Create a text-to-video task and poll until it completes.
27
+
28
+ Args:
29
+ **params: Text-to-video parameters (model, prompt, ...).
30
+
31
+ Returns:
32
+ The completed task with videos.
33
+ """
34
+ task = self.create(**params)
35
+ return self._poll_until_complete(lambda: self.get(task.id))
36
+
37
+ def create(self, **params: Any) -> Any:
38
+ """Create a text-to-video task and return immediately with an ``id``.
39
+
40
+ Args:
41
+ **params: Text-to-video parameters (model, prompt, ...).
42
+
43
+ Returns:
44
+ The task creation result with an id.
45
+ """
46
+ compacted = self._compact_params(params)
47
+ self._validate_params(compacted)
48
+ return self._request("post", self.ENDPOINT, body=compacted)
49
+
50
+ def get(self, id: str) -> Any:
51
+ """Fetch the current status of a text-to-video task.
52
+
53
+ Args:
54
+ id: The task id.
55
+
56
+ Returns:
57
+ The current task status.
58
+ """
59
+ return self._request("get", f"{self.ENDPOINT}/{id}")
60
+
61
+ def _validate_params(self, params: Dict[str, Any]) -> None:
62
+ model = params.get("model")
63
+ if model not in TEXT_TO_VIDEO_MODELS:
64
+ raise ValidationError("model is required")
65
+ if not params.get("prompt"):
66
+ raise ValidationError("prompt is required")
67
+
68
+ duration_seconds = params.get("duration_seconds")
69
+ if not duration_seconds:
70
+ return
71
+
72
+ if duration_seconds not in DURATIONS:
73
+ raise ValidationError(
74
+ f"duration_seconds must be one of: {', '.join(str(d) for d in DURATIONS)}"
75
+ )
76
+ if model == "hailuo-02-text-to-video-pro":
77
+ raise ValidationError(f"duration_seconds is not supported for {model}")
runapi/hailuo/types.py ADDED
@@ -0,0 +1,38 @@
1
+ """Hailuo model lists, enums, and response models."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from runapi.core import BaseModel, TaskResponse, optional, required
6
+
7
+ TEXT_TO_VIDEO_MODELS = [
8
+ "hailuo-02-text-to-video-pro",
9
+ "hailuo-02-text-to-video-standard",
10
+ ]
11
+ IMAGE_TO_VIDEO_MODELS = [
12
+ "hailuo-02-image-to-video-pro",
13
+ "hailuo-02-image-to-video-standard",
14
+ "hailuo-2.3-image-to-video-pro",
15
+ "hailuo-2.3-image-to-video-standard",
16
+ ]
17
+ DURATIONS = [6, 10]
18
+ IMAGE_02_RESOLUTIONS = ["512p", "768p"]
19
+ IMAGE_23_RESOLUTIONS = ["768p", "1080p"]
20
+
21
+
22
+ class MediaUrl(BaseModel):
23
+ url = optional(str)
24
+
25
+
26
+ class VideoTaskResponse(TaskResponse):
27
+ """Response for a video generation task."""
28
+
29
+ id = required(str)
30
+ status = optional(str, enum=lambda: TaskResponse.Status.ALL)
31
+ videos = optional([lambda: MediaUrl])
32
+ error = optional(str)
33
+
34
+
35
+ class CompletedVideoTaskResponse(VideoTaskResponse):
36
+ """Narrowed response from ``run()`` once polling observes completion."""
37
+
38
+ videos = required([lambda: MediaUrl])
@@ -0,0 +1,84 @@
1
+ Metadata-Version: 2.4
2
+ Name: runapi-hailuo
3
+ Version: 0.1.0
4
+ Summary: Hailuo text-to-video and image-to-video client for RunAPI
5
+ Project-URL: Homepage, https://runapi.ai/models/hailuo
6
+ Project-URL: Documentation, https://runapi.ai/docs#sdk-hailuo
7
+ Author-email: RunAPI <contact@runapi.ai>
8
+ License-Expression: Apache-2.0
9
+ Keywords: ai,hailuo,image-to-video,runapi,sdk,text-to-video
10
+ Requires-Python: >=3.9
11
+ Requires-Dist: runapi-core
12
+ Description-Content-Type: text/markdown
13
+
14
+ # Hailuo Python SDK for RunAPI
15
+
16
+ The Hailuo Python SDK is the language-specific package for Hailuo on RunAPI. Use
17
+ it for text-to-video and image-to-video flows when your application needs JSON
18
+ request bodies, task status lookup, and consistent RunAPI errors in Python.
19
+
20
+ For model details, use https://runapi.ai/models/hailuo; for API reference, use
21
+ https://runapi.ai/docs#hailuo; for SDK docs, use https://runapi.ai/docs#sdk-hailuo.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ pip install runapi-hailuo
27
+ ```
28
+
29
+ ## Quick start
30
+
31
+ ```python
32
+ from runapi.hailuo import HailuoClient
33
+
34
+ client = HailuoClient() # reads RUNAPI_API_KEY, or pass api_key="sk-..."
35
+
36
+ task = client.text_to_video.create(
37
+ model="hailuo-02-text-to-video-standard",
38
+ prompt="A cinematic drone shot over a coastal city at dusk",
39
+ )
40
+ status = client.text_to_video.get(task.id)
41
+
42
+ video = client.image_to_video.create(
43
+ model="hailuo-2.3-image-to-video-standard",
44
+ prompt="Slowly zoom in as the waves roll",
45
+ first_frame_image_url="https://example.com/source.jpg",
46
+ )
47
+ ```
48
+
49
+ Use `create` to submit a task and return quickly, `get` to fetch the latest task
50
+ state, and `run` to create and poll until completion:
51
+
52
+ ```python
53
+ result = client.text_to_video.run(
54
+ model="hailuo-02-text-to-video-standard",
55
+ prompt="A futuristic cityscape at dusk",
56
+ )
57
+ print(result.videos[0].url)
58
+ ```
59
+
60
+ In web request handlers, prefer `create` plus webhook or later `get` polling so a
61
+ worker is not held open.
62
+
63
+ RunAPI-generated file URLs are temporary. Download and store generated videos in
64
+ your own durable storage within 7 days; do not treat returned URLs as long-term
65
+ assets.
66
+
67
+ ## Language notes
68
+
69
+ Pass parameters as keyword arguments and catch the `runapi.hailuo` error classes
70
+ when building video jobs or scripts. The available resources are `text_to_video`
71
+ and `image_to_video`. Keep `RUNAPI_API_KEY` in the environment or your secret
72
+ manager; never commit API keys or callback secrets.
73
+
74
+ ## Links
75
+
76
+ - Model page: https://runapi.ai/models/hailuo
77
+ - SDK docs: https://runapi.ai/docs#sdk-hailuo
78
+ - Product docs: https://runapi.ai/docs#hailuo
79
+ - Pricing and rate limits: https://runapi.ai/models/hailuo/02-text-to-video-pro
80
+ - Full catalog: https://runapi.ai/models
81
+
82
+ ## License
83
+
84
+ Licensed under the Apache License, Version 2.0.
@@ -0,0 +1,10 @@
1
+ runapi/hailuo/__init__.py,sha256=934UgjSynpl4-4LeHqt7GJ3PpG0XPwXYnAYsxb3sdLw,460
2
+ runapi/hailuo/client.py,sha256=mEsGR7YM7lQPDBOusfx-O3SoGZsoV83KOj7XgxUSatc,920
3
+ runapi/hailuo/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ runapi/hailuo/types.py,sha256=KJzS6-rr1bJiwyygPH-UmDgc7LX9OQYooa6BHAYZ3go,1021
5
+ runapi/hailuo/resources/__init__.py,sha256=bDddoII8kEYzVtRfQU41VL-sRs_XNon92hWM2GYo40U,123
6
+ runapi/hailuo/resources/image_to_video.py,sha256=u8P41kiAuAJCKjVSczVYnD71SqcyWpbIaQzdhIHM6S4,3745
7
+ runapi/hailuo/resources/text_to_video.py,sha256=kz46GfnqN6-Bps1CTrpjcMC3G7LGCkfvT0kMAzzET6w,2329
8
+ runapi_hailuo-0.1.0.dist-info/METADATA,sha256=lFpVFh4FG_sXHa2JYnmvbUj2Mzbxo37YxCUsIqFi5t0,2709
9
+ runapi_hailuo-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
10
+ runapi_hailuo-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.30.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any