runapi-z-image 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.
- runapi/z_image/__init__.py +24 -0
- runapi/z_image/client.py +27 -0
- runapi/z_image/contract_gen.py +19 -0
- runapi/z_image/py.typed +0 -0
- runapi/z_image/resources/__init__.py +3 -0
- runapi/z_image/resources/text_to_image.py +58 -0
- runapi/z_image/types.py +24 -0
- runapi_z_image-0.1.0.dist-info/METADATA +80 -0
- runapi_z_image-0.1.0.dist-info/RECORD +10 -0
- runapi_z_image-0.1.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Z-Image 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 ZImageClient
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"ZImageClient",
|
|
17
|
+
"AuthenticationError",
|
|
18
|
+
"RateLimitError",
|
|
19
|
+
"InsufficientCreditsError",
|
|
20
|
+
"NotFoundError",
|
|
21
|
+
"ValidationError",
|
|
22
|
+
"TaskFailedError",
|
|
23
|
+
"TaskTimeoutError",
|
|
24
|
+
]
|
runapi/z_image/client.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Z-Image 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.text_to_image import TextToImage
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ZImageClient:
|
|
13
|
+
"""Z-Image text-to-image client.
|
|
14
|
+
|
|
15
|
+
Example::
|
|
16
|
+
|
|
17
|
+
client = ZImageClient(api_key="sk-...")
|
|
18
|
+
result = client.text_to_image.run(
|
|
19
|
+
model="z-image", prompt="A neon city street", aspect_ratio="1:1"
|
|
20
|
+
)
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def __init__(self, api_key: Optional[str] = None, **options: Any) -> None:
|
|
24
|
+
resolved_api_key = resolve_api_key(api_key)
|
|
25
|
+
client_options = ClientOptions(api_key=resolved_api_key, **options)
|
|
26
|
+
http = client_options.http_client or HttpClient(client_options)
|
|
27
|
+
self.text_to_image = TextToImage(http)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
CONTRACT = {
|
|
2
|
+
"text-to-image": {
|
|
3
|
+
"models": ["z-image"],
|
|
4
|
+
"fields_by_model": {
|
|
5
|
+
"z-image": {
|
|
6
|
+
"aspect_ratio": {
|
|
7
|
+
"enum": ["1:1", "4:3", "3:4", "16:9", "9:16"],
|
|
8
|
+
"required": True
|
|
9
|
+
},
|
|
10
|
+
"prompt": {
|
|
11
|
+
"required": True,
|
|
12
|
+
"min": 1,
|
|
13
|
+
"max": 1000,
|
|
14
|
+
"length": True
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
runapi/z_image/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""Z-Image text-to-image resource."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from runapi.core import Resource
|
|
8
|
+
|
|
9
|
+
from ..contract_gen import CONTRACT
|
|
10
|
+
from ..types import (
|
|
11
|
+
CompletedTextToImageResponse,
|
|
12
|
+
TextToImageResponse,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TextToImage(Resource):
|
|
17
|
+
"""Generate images from text prompts with Z-Image."""
|
|
18
|
+
|
|
19
|
+
ENDPOINT = "/api/v1/z_image/text_to_image"
|
|
20
|
+
|
|
21
|
+
RESPONSE_CLASS = TextToImageResponse
|
|
22
|
+
COMPLETED_RESPONSE_CLASS = CompletedTextToImageResponse
|
|
23
|
+
|
|
24
|
+
def run(self, **params: Any) -> Any:
|
|
25
|
+
"""Create a text-to-image task and poll until it completes.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
**params: text-to-image parameters (model, ...).
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
The completed (narrowed) text-to-image response.
|
|
32
|
+
"""
|
|
33
|
+
task = self.create(**params)
|
|
34
|
+
return self._poll_until_complete(lambda: self.get(task.id))
|
|
35
|
+
|
|
36
|
+
def create(self, **params: Any) -> Any:
|
|
37
|
+
"""Create a text-to-image task and return immediately with an id.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
**params: text-to-image parameters (model, ...).
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
The task creation result with an id.
|
|
44
|
+
"""
|
|
45
|
+
compacted = self._compact_params(params)
|
|
46
|
+
self._validate_contract(CONTRACT["text-to-image"], compacted)
|
|
47
|
+
return self._request("post", self.ENDPOINT, body=compacted)
|
|
48
|
+
|
|
49
|
+
def get(self, id: str) -> Any:
|
|
50
|
+
"""Fetch the current status of a text-to-image task.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
id: The task id returned by ``create``.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
The current task status.
|
|
57
|
+
"""
|
|
58
|
+
return self._request("get", f"{self.ENDPOINT}/{id}")
|
runapi/z_image/types.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Z-Image response models."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from runapi.core import BaseModel, TaskResponse, optional, required
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Image(BaseModel):
|
|
9
|
+
url = optional(str)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TextToImageResponse(TaskResponse):
|
|
13
|
+
"""Z-Image text-to-image task status response."""
|
|
14
|
+
|
|
15
|
+
id = required(str)
|
|
16
|
+
status = optional(str, enum=lambda: TaskResponse.Status.ALL)
|
|
17
|
+
images = optional([lambda: Image])
|
|
18
|
+
error = optional(str)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class CompletedTextToImageResponse(TextToImageResponse):
|
|
22
|
+
"""Narrowed response from ``run()`` once polling observes completion."""
|
|
23
|
+
|
|
24
|
+
images = required([lambda: Image])
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: runapi-z-image
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Z-Image text-to-image client for RunAPI
|
|
5
|
+
Project-URL: Homepage, https://runapi.ai/models/z-image
|
|
6
|
+
Project-URL: Documentation, https://runapi.ai/docs#sdk-z-image
|
|
7
|
+
Author-email: RunAPI <contact@runapi.ai>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
Keywords: ai,runapi,sdk,text-to-image,z-image
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Requires-Dist: runapi-core
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# Z-Image Python SDK for RunAPI
|
|
15
|
+
|
|
16
|
+
The Z-Image Python SDK is the language-specific package for Z-Image on RunAPI.
|
|
17
|
+
Use it for text-to-image flows when your application needs JSON request bodies,
|
|
18
|
+
task status lookup, and consistent RunAPI errors in Python.
|
|
19
|
+
|
|
20
|
+
For model details, use https://runapi.ai/models/z-image; for API reference, use
|
|
21
|
+
https://runapi.ai/docs#z-image; for SDK docs, use https://runapi.ai/docs#sdk-z-image.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install runapi-z-image
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick start
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from runapi.z_image import ZImageClient
|
|
33
|
+
|
|
34
|
+
client = ZImageClient() # reads RUNAPI_API_KEY, or pass api_key="sk-..."
|
|
35
|
+
|
|
36
|
+
task = client.text_to_image.create(
|
|
37
|
+
model="z-image",
|
|
38
|
+
prompt="A neon city street after rain, cinematic",
|
|
39
|
+
aspect_ratio="16:9",
|
|
40
|
+
)
|
|
41
|
+
status = client.text_to_image.get(task.id)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Use `create` to submit a task and return quickly, `get` to fetch the latest task
|
|
45
|
+
state, and `run` to create and poll until completion:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
result = client.text_to_image.run(
|
|
49
|
+
model="z-image",
|
|
50
|
+
prompt="A serene mountain lake at dawn",
|
|
51
|
+
aspect_ratio="1:1",
|
|
52
|
+
)
|
|
53
|
+
print(result.images[0].url)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
In web request handlers, prefer `create` plus webhook or later `get` polling so a
|
|
57
|
+
worker is not held open.
|
|
58
|
+
|
|
59
|
+
RunAPI-generated file URLs are temporary. Download and store generated images in
|
|
60
|
+
your own durable storage within 7 days; do not treat returned URLs as long-term
|
|
61
|
+
assets.
|
|
62
|
+
|
|
63
|
+
## Language notes
|
|
64
|
+
|
|
65
|
+
Pass parameters as keyword arguments and catch the `runapi.z_image` error
|
|
66
|
+
classes when building image jobs or scripts. The available resource is
|
|
67
|
+
`text_to_image`. Keep `RUNAPI_API_KEY` in the environment or your secret
|
|
68
|
+
manager; never commit API keys or callback secrets.
|
|
69
|
+
|
|
70
|
+
## Links
|
|
71
|
+
|
|
72
|
+
- Model page: https://runapi.ai/models/z-image
|
|
73
|
+
- SDK docs: https://runapi.ai/docs#sdk-z-image
|
|
74
|
+
- Product docs: https://runapi.ai/docs#z-image
|
|
75
|
+
- Pricing and rate limits: https://runapi.ai/models/z-image
|
|
76
|
+
- Full catalog: https://runapi.ai/models
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
Licensed under the Apache License, Version 2.0.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
runapi/z_image/__init__.py,sha256=APr5DEvPMYp-gfPEEnnHRT0NJjAYcmd34KKjN4HF8LM,461
|
|
2
|
+
runapi/z_image/client.py,sha256=8qJzCHKLyGehuLPfutBCGeqReOl7iH1_wVW3GYl3iP8,798
|
|
3
|
+
runapi/z_image/contract_gen.py,sha256=Zp2gXXQ2z82MXiyq8YuWZ6Dl02_BZc_BfvyVO0LhEik,492
|
|
4
|
+
runapi/z_image/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
runapi/z_image/types.py,sha256=EzLli3j-_U5MbQgdmehKq4wNRVUWyVRjuX5Sr7y31l8,613
|
|
6
|
+
runapi/z_image/resources/__init__.py,sha256=PVNSBebEM1p0giM6WFUmykEPetVG6grJU12v0t8iZD0,66
|
|
7
|
+
runapi/z_image/resources/text_to_image.py,sha256=MgKPcD-ygsLt7ZEE8XAEFPJ9zle03znJ6M4djsRqFHE,1626
|
|
8
|
+
runapi_z_image-0.1.0.dist-info/METADATA,sha256=sfecsN9fVURNeCLXdRd5oJbBcZZ3Y1oN_whsr91MZWc,2423
|
|
9
|
+
runapi_z_image-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
10
|
+
runapi_z_image-0.1.0.dist-info/RECORD,,
|