runapi-ideogram-v3 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/ideogram_v3/__init__.py +24 -0
- runapi/ideogram_v3/_validators.py +19 -0
- runapi/ideogram_v3/client.py +34 -0
- runapi/ideogram_v3/py.typed +0 -0
- runapi/ideogram_v3/resources/__init__.py +6 -0
- runapi/ideogram_v3/resources/edit_image.py +95 -0
- runapi/ideogram_v3/resources/reframe_image.py +78 -0
- runapi/ideogram_v3/resources/remix_image.py +117 -0
- runapi/ideogram_v3/resources/text_to_image.py +94 -0
- runapi/ideogram_v3/types.py +38 -0
- runapi_ideogram_v3-0.1.0.dist-info/METADATA +90 -0
- runapi_ideogram_v3-0.1.0.dist-info/RECORD +13 -0
- runapi_ideogram_v3-0.1.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Ideogram V3 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 IdeogramV3Client
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"IdeogramV3Client",
|
|
17
|
+
"AuthenticationError",
|
|
18
|
+
"RateLimitError",
|
|
19
|
+
"InsufficientCreditsError",
|
|
20
|
+
"NotFoundError",
|
|
21
|
+
"ValidationError",
|
|
22
|
+
"TaskFailedError",
|
|
23
|
+
"TaskTimeoutError",
|
|
24
|
+
]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Shared validators for Ideogram V3 resources."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Dict
|
|
6
|
+
|
|
7
|
+
from runapi.core import ValidationError
|
|
8
|
+
|
|
9
|
+
from .types import OUTPUT_COUNTS
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def validate_output_count(params: Dict[str, Any]) -> None:
|
|
13
|
+
output_count = params.get("output_count")
|
|
14
|
+
if output_count is None:
|
|
15
|
+
return
|
|
16
|
+
if not isinstance(output_count, bool) and output_count in OUTPUT_COUNTS:
|
|
17
|
+
return
|
|
18
|
+
joined = ", ".join(str(option) for option in OUTPUT_COUNTS)
|
|
19
|
+
raise ValidationError(f"Invalid output_count: {output_count}. Must be one of: {joined}")
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Ideogram V3 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.edit_image import EditImage
|
|
10
|
+
from .resources.reframe_image import ReframeImage
|
|
11
|
+
from .resources.remix_image import RemixImage
|
|
12
|
+
from .resources.text_to_image import TextToImage
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class IdeogramV3Client:
|
|
16
|
+
"""Ideogram V3 image generation client.
|
|
17
|
+
|
|
18
|
+
Example::
|
|
19
|
+
|
|
20
|
+
client = IdeogramV3Client(api_key="sk-...")
|
|
21
|
+
result = client.text_to_image.run(
|
|
22
|
+
model="ideogram-v3-text-to-image",
|
|
23
|
+
prompt="A cinematic lakeside at twilight",
|
|
24
|
+
)
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, api_key: Optional[str] = None, **options: Any) -> None:
|
|
28
|
+
resolved_api_key = resolve_api_key(api_key)
|
|
29
|
+
client_options = ClientOptions(api_key=resolved_api_key, **options)
|
|
30
|
+
http = client_options.http_client or HttpClient(client_options)
|
|
31
|
+
self.text_to_image = TextToImage(http)
|
|
32
|
+
self.edit_image = EditImage(http)
|
|
33
|
+
self.remix_image = RemixImage(http)
|
|
34
|
+
self.reframe_image = ReframeImage(http)
|
|
File without changes
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""Ideogram V3 edit-image resource (model: ideogram-v3-edit)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Dict
|
|
6
|
+
|
|
7
|
+
from runapi.core import Resource, ValidationError
|
|
8
|
+
|
|
9
|
+
from .._validators import validate_output_count
|
|
10
|
+
from ..types import (
|
|
11
|
+
CHARACTER_EDIT_MODEL,
|
|
12
|
+
CHARACTER_STYLES,
|
|
13
|
+
EDIT_MODEL,
|
|
14
|
+
RENDERING_SPEEDS,
|
|
15
|
+
CompletedIdeogramResponse,
|
|
16
|
+
IdeogramResponse,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class EditImage(Resource):
|
|
21
|
+
"""Inpaint an image with a mask using Ideogram V3 models."""
|
|
22
|
+
|
|
23
|
+
ENDPOINT = "/api/v1/ideogram_v3/edit_image"
|
|
24
|
+
RESPONSE_CLASS = IdeogramResponse
|
|
25
|
+
COMPLETED_RESPONSE_CLASS = CompletedIdeogramResponse
|
|
26
|
+
PROMPT_MAX_LENGTH = 5000
|
|
27
|
+
|
|
28
|
+
def run(self, **params: Any) -> Any:
|
|
29
|
+
"""Create an edit-image task and poll until it completes.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
**params: Edit-image parameters (model, prompt, source_image_url, mask_url, ...).
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
The completed (narrowed) response.
|
|
36
|
+
"""
|
|
37
|
+
task = self.create(**params)
|
|
38
|
+
return self._poll_until_complete(lambda: self.get(task.id))
|
|
39
|
+
|
|
40
|
+
def create(self, **params: Any) -> Any:
|
|
41
|
+
"""Create an edit-image task and return immediately with an ``id``.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
**params: Edit-image parameters (model, prompt, source_image_url, mask_url, ...).
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
The task creation result with an id.
|
|
48
|
+
"""
|
|
49
|
+
compacted = self._compact_params(params)
|
|
50
|
+
self._validate_params(compacted)
|
|
51
|
+
return self._request("post", self.ENDPOINT, body=compacted)
|
|
52
|
+
|
|
53
|
+
def get(self, id: str) -> Any:
|
|
54
|
+
"""Fetch the current status of an edit-image task.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
id: The task id.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
The current task status.
|
|
61
|
+
"""
|
|
62
|
+
return self._request("get", f"{self.ENDPOINT}/{id}")
|
|
63
|
+
|
|
64
|
+
def _validate_params(self, params: Dict[str, Any]) -> None:
|
|
65
|
+
model = params.get("model")
|
|
66
|
+
if not model:
|
|
67
|
+
raise ValidationError("model is required")
|
|
68
|
+
if model not in (EDIT_MODEL, CHARACTER_EDIT_MODEL):
|
|
69
|
+
raise ValidationError(
|
|
70
|
+
f"Invalid model: {model}. Must be {EDIT_MODEL} or {CHARACTER_EDIT_MODEL}"
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
prompt = params.get("prompt")
|
|
74
|
+
if not (isinstance(prompt, str) and prompt):
|
|
75
|
+
raise ValidationError("prompt is required")
|
|
76
|
+
if len(prompt) > self.PROMPT_MAX_LENGTH:
|
|
77
|
+
raise ValidationError(f"prompt must be at most {self.PROMPT_MAX_LENGTH} characters")
|
|
78
|
+
|
|
79
|
+
if not params.get("source_image_url"):
|
|
80
|
+
raise ValidationError("source_image_url is required")
|
|
81
|
+
if not params.get("mask_url"):
|
|
82
|
+
raise ValidationError("mask_url is required")
|
|
83
|
+
|
|
84
|
+
self._validate_optional(params, "rendering_speed", RENDERING_SPEEDS)
|
|
85
|
+
self._validate_character_fields(params, model)
|
|
86
|
+
|
|
87
|
+
def _validate_character_fields(self, params: Dict[str, Any], model: str) -> None:
|
|
88
|
+
refs = params.get("reference_image_urls")
|
|
89
|
+
if model == CHARACTER_EDIT_MODEL:
|
|
90
|
+
if not (isinstance(refs, list) and refs):
|
|
91
|
+
raise ValidationError("reference_image_urls is required")
|
|
92
|
+
self._validate_optional(params, "style", CHARACTER_STYLES)
|
|
93
|
+
elif refs or params.get("style"):
|
|
94
|
+
raise ValidationError(f"character edit fields are not supported for {model}")
|
|
95
|
+
validate_output_count(params)
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Ideogram V3 reframe-image resource (model: ideogram-v3-reframe)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Dict
|
|
6
|
+
|
|
7
|
+
from runapi.core import Resource, ValidationError
|
|
8
|
+
|
|
9
|
+
from .._validators import validate_output_count
|
|
10
|
+
from ..types import (
|
|
11
|
+
ASPECT_RATIOS,
|
|
12
|
+
REFRAME_MODEL,
|
|
13
|
+
RENDERING_SPEEDS,
|
|
14
|
+
STYLES,
|
|
15
|
+
CompletedIdeogramResponse,
|
|
16
|
+
IdeogramResponse,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ReframeImage(Resource):
|
|
21
|
+
"""Reframe a source image to a new aspect ratio with Ideogram V3."""
|
|
22
|
+
|
|
23
|
+
ENDPOINT = "/api/v1/ideogram_v3/reframe_image"
|
|
24
|
+
RESPONSE_CLASS = IdeogramResponse
|
|
25
|
+
COMPLETED_RESPONSE_CLASS = CompletedIdeogramResponse
|
|
26
|
+
|
|
27
|
+
def run(self, **params: Any) -> Any:
|
|
28
|
+
"""Create a reframe-image task and poll until it completes.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
**params: Reframe-image parameters (model, source_image_url, aspect_ratio, ...).
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
The completed (narrowed) response.
|
|
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 a reframe-image task and return immediately with an ``id``.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
**params: Reframe-image parameters (model, source_image_url, aspect_ratio, ...).
|
|
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 a reframe-image 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 not model:
|
|
66
|
+
raise ValidationError("model is required")
|
|
67
|
+
if model != REFRAME_MODEL:
|
|
68
|
+
raise ValidationError(f"Invalid model: {model}. Must be {REFRAME_MODEL}")
|
|
69
|
+
|
|
70
|
+
if not params.get("source_image_url"):
|
|
71
|
+
raise ValidationError("source_image_url is required")
|
|
72
|
+
if not params.get("aspect_ratio"):
|
|
73
|
+
raise ValidationError("aspect_ratio is required")
|
|
74
|
+
|
|
75
|
+
self._validate_optional(params, "aspect_ratio", ASPECT_RATIOS)
|
|
76
|
+
self._validate_optional(params, "rendering_speed", RENDERING_SPEEDS)
|
|
77
|
+
self._validate_optional(params, "style", STYLES)
|
|
78
|
+
validate_output_count(params)
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Ideogram V3 remix-image resource (model: ideogram-v3-remix)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Dict
|
|
6
|
+
|
|
7
|
+
from runapi.core import Resource, ValidationError
|
|
8
|
+
|
|
9
|
+
from .._validators import validate_output_count
|
|
10
|
+
from ..types import (
|
|
11
|
+
ASPECT_RATIOS,
|
|
12
|
+
CHARACTER_REMIX_MODEL,
|
|
13
|
+
CHARACTER_STYLES,
|
|
14
|
+
REMIX_MODEL,
|
|
15
|
+
RENDERING_SPEEDS,
|
|
16
|
+
STYLES,
|
|
17
|
+
CompletedIdeogramResponse,
|
|
18
|
+
IdeogramResponse,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class RemixImage(Resource):
|
|
23
|
+
"""Remix a source image with Ideogram V3 models."""
|
|
24
|
+
|
|
25
|
+
ENDPOINT = "/api/v1/ideogram_v3/remix_image"
|
|
26
|
+
RESPONSE_CLASS = IdeogramResponse
|
|
27
|
+
COMPLETED_RESPONSE_CLASS = CompletedIdeogramResponse
|
|
28
|
+
PROMPT_MAX_LENGTH = 5000
|
|
29
|
+
STRENGTH_MIN = 0.01
|
|
30
|
+
CHARACTER_REMIX_STRENGTH_MIN = 0.1
|
|
31
|
+
STRENGTH_MAX = 1.0
|
|
32
|
+
|
|
33
|
+
def run(self, **params: Any) -> Any:
|
|
34
|
+
"""Create a remix-image task and poll until it completes.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
**params: Remix-image parameters (model, prompt, source_image_url, ...).
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
The completed (narrowed) response.
|
|
41
|
+
"""
|
|
42
|
+
task = self.create(**params)
|
|
43
|
+
return self._poll_until_complete(lambda: self.get(task.id))
|
|
44
|
+
|
|
45
|
+
def create(self, **params: Any) -> Any:
|
|
46
|
+
"""Create a remix-image task and return immediately with an ``id``.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
**params: Remix-image parameters (model, prompt, source_image_url, ...).
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
The task creation result with an id.
|
|
53
|
+
"""
|
|
54
|
+
compacted = self._compact_params(params)
|
|
55
|
+
self._validate_params(compacted)
|
|
56
|
+
return self._request("post", self.ENDPOINT, body=compacted)
|
|
57
|
+
|
|
58
|
+
def get(self, id: str) -> Any:
|
|
59
|
+
"""Fetch the current status of a remix-image task.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
id: The task id.
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
The current task status.
|
|
66
|
+
"""
|
|
67
|
+
return self._request("get", f"{self.ENDPOINT}/{id}")
|
|
68
|
+
|
|
69
|
+
def _validate_params(self, params: Dict[str, Any]) -> None:
|
|
70
|
+
model = params.get("model")
|
|
71
|
+
if not model:
|
|
72
|
+
raise ValidationError("model is required")
|
|
73
|
+
if model not in (REMIX_MODEL, CHARACTER_REMIX_MODEL):
|
|
74
|
+
raise ValidationError(
|
|
75
|
+
f"Invalid model: {model}. Must be {REMIX_MODEL} or {CHARACTER_REMIX_MODEL}"
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
prompt = params.get("prompt")
|
|
79
|
+
if not (isinstance(prompt, str) and prompt):
|
|
80
|
+
raise ValidationError("prompt is required")
|
|
81
|
+
if len(prompt) > self.PROMPT_MAX_LENGTH:
|
|
82
|
+
raise ValidationError(f"prompt must be at most {self.PROMPT_MAX_LENGTH} characters")
|
|
83
|
+
|
|
84
|
+
if not params.get("source_image_url"):
|
|
85
|
+
raise ValidationError("source_image_url is required")
|
|
86
|
+
|
|
87
|
+
self._validate_optional(params, "rendering_speed", RENDERING_SPEEDS)
|
|
88
|
+
style_values = CHARACTER_STYLES if model == CHARACTER_REMIX_MODEL else STYLES
|
|
89
|
+
self._validate_optional(params, "style", style_values)
|
|
90
|
+
self._validate_optional(params, "aspect_ratio", ASPECT_RATIOS)
|
|
91
|
+
self._validate_character_fields(params, model)
|
|
92
|
+
validate_output_count(params)
|
|
93
|
+
self._validate_strength(params, model)
|
|
94
|
+
|
|
95
|
+
def _validate_character_fields(self, params: Dict[str, Any], model: str) -> None:
|
|
96
|
+
refs = params.get("reference_image_urls")
|
|
97
|
+
if model == CHARACTER_REMIX_MODEL:
|
|
98
|
+
if not (isinstance(refs, list) and refs):
|
|
99
|
+
raise ValidationError("reference_image_urls is required")
|
|
100
|
+
elif refs or params.get("style_reference_image_urls") or params.get("reference_mask_urls"):
|
|
101
|
+
raise ValidationError(f"character remix fields are not supported for {model}")
|
|
102
|
+
|
|
103
|
+
def _validate_strength(self, params: Dict[str, Any], model: str) -> None:
|
|
104
|
+
strength = params.get("strength")
|
|
105
|
+
if strength is None:
|
|
106
|
+
return
|
|
107
|
+
minimum = (
|
|
108
|
+
self.CHARACTER_REMIX_STRENGTH_MIN
|
|
109
|
+
if model == CHARACTER_REMIX_MODEL
|
|
110
|
+
else self.STRENGTH_MIN
|
|
111
|
+
)
|
|
112
|
+
try:
|
|
113
|
+
numeric = float(strength)
|
|
114
|
+
except (TypeError, ValueError):
|
|
115
|
+
numeric = None
|
|
116
|
+
if numeric is None or numeric < minimum or numeric > self.STRENGTH_MAX:
|
|
117
|
+
raise ValidationError(f"strength must be between {minimum} and {self.STRENGTH_MAX}")
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Ideogram V3 text-to-image resource (model: ideogram-v3-text-to-image)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Dict
|
|
6
|
+
|
|
7
|
+
from runapi.core import Resource, ValidationError
|
|
8
|
+
|
|
9
|
+
from .._validators import validate_output_count
|
|
10
|
+
from ..types import (
|
|
11
|
+
ASPECT_RATIOS,
|
|
12
|
+
CHARACTER_MODEL,
|
|
13
|
+
CHARACTER_STYLES,
|
|
14
|
+
GENERATION_MODEL,
|
|
15
|
+
RENDERING_SPEEDS,
|
|
16
|
+
STYLES,
|
|
17
|
+
CompletedIdeogramResponse,
|
|
18
|
+
IdeogramResponse,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class TextToImage(Resource):
|
|
23
|
+
"""Generate images from text prompts with Ideogram V3 models."""
|
|
24
|
+
|
|
25
|
+
ENDPOINT = "/api/v1/ideogram_v3/text_to_image"
|
|
26
|
+
RESPONSE_CLASS = IdeogramResponse
|
|
27
|
+
COMPLETED_RESPONSE_CLASS = CompletedIdeogramResponse
|
|
28
|
+
PROMPT_MAX_LENGTH = 5000
|
|
29
|
+
|
|
30
|
+
def run(self, **params: Any) -> Any:
|
|
31
|
+
"""Create a text-to-image task and poll until it completes.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
**params: Text-to-image parameters (model, prompt, ...).
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
The completed (narrowed) response.
|
|
38
|
+
"""
|
|
39
|
+
task = self.create(**params)
|
|
40
|
+
return self._poll_until_complete(lambda: self.get(task.id))
|
|
41
|
+
|
|
42
|
+
def create(self, **params: Any) -> Any:
|
|
43
|
+
"""Create a text-to-image task and return immediately with an ``id``.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
**params: Text-to-image parameters (model, prompt, ...).
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
The task creation result with an id.
|
|
50
|
+
"""
|
|
51
|
+
compacted = self._compact_params(params)
|
|
52
|
+
self._validate_params(compacted)
|
|
53
|
+
return self._request("post", self.ENDPOINT, body=compacted)
|
|
54
|
+
|
|
55
|
+
def get(self, id: str) -> Any:
|
|
56
|
+
"""Fetch the current status of a text-to-image task.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
id: The task id.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
The current task status.
|
|
63
|
+
"""
|
|
64
|
+
return self._request("get", f"{self.ENDPOINT}/{id}")
|
|
65
|
+
|
|
66
|
+
def _validate_params(self, params: Dict[str, Any]) -> None:
|
|
67
|
+
model = params.get("model")
|
|
68
|
+
if not model:
|
|
69
|
+
raise ValidationError("model is required")
|
|
70
|
+
if model not in (GENERATION_MODEL, CHARACTER_MODEL):
|
|
71
|
+
raise ValidationError(
|
|
72
|
+
f"Invalid model: {model}. Must be {GENERATION_MODEL} or {CHARACTER_MODEL}"
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
prompt = params.get("prompt")
|
|
76
|
+
if not (isinstance(prompt, str) and prompt):
|
|
77
|
+
raise ValidationError("prompt is required")
|
|
78
|
+
if len(prompt) > self.PROMPT_MAX_LENGTH:
|
|
79
|
+
raise ValidationError(f"prompt must be at most {self.PROMPT_MAX_LENGTH} characters")
|
|
80
|
+
|
|
81
|
+
self._validate_optional(params, "rendering_speed", RENDERING_SPEEDS)
|
|
82
|
+
style_values = CHARACTER_STYLES if model == CHARACTER_MODEL else STYLES
|
|
83
|
+
self._validate_optional(params, "style", style_values)
|
|
84
|
+
self._validate_optional(params, "aspect_ratio", ASPECT_RATIOS)
|
|
85
|
+
self._validate_character_refs(params, model)
|
|
86
|
+
validate_output_count(params)
|
|
87
|
+
|
|
88
|
+
def _validate_character_refs(self, params: Dict[str, Any], model: str) -> None:
|
|
89
|
+
refs = params.get("reference_image_urls")
|
|
90
|
+
if model == CHARACTER_MODEL:
|
|
91
|
+
if not (isinstance(refs, list) and refs):
|
|
92
|
+
raise ValidationError("reference_image_urls is required")
|
|
93
|
+
elif refs:
|
|
94
|
+
raise ValidationError(f"reference_image_urls is not supported for {model}")
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Ideogram V3 model constants, enums, and response models."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from runapi.core import BaseModel, TaskResponse, optional, required
|
|
6
|
+
|
|
7
|
+
GENERATION_MODEL = "ideogram-v3-text-to-image"
|
|
8
|
+
EDIT_MODEL = "ideogram-v3-edit"
|
|
9
|
+
REMIX_MODEL = "ideogram-v3-remix"
|
|
10
|
+
CHARACTER_MODEL = "ideogram-v3-character"
|
|
11
|
+
CHARACTER_EDIT_MODEL = "ideogram-v3-character-edit"
|
|
12
|
+
CHARACTER_REMIX_MODEL = "ideogram-v3-character-remix"
|
|
13
|
+
REFRAME_MODEL = "ideogram-v3-reframe"
|
|
14
|
+
|
|
15
|
+
RENDERING_SPEEDS = ["turbo", "balanced", "quality"]
|
|
16
|
+
STYLES = ["auto", "general", "realistic", "design"]
|
|
17
|
+
CHARACTER_STYLES = ["auto", "realistic", "fiction"]
|
|
18
|
+
ASPECT_RATIOS = ["1:1", "3:4", "9:16", "4:3", "16:9"]
|
|
19
|
+
OUTPUT_COUNTS = [1, 2, 3, 4]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Image(BaseModel):
|
|
23
|
+
url = optional(str)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class IdeogramResponse(TaskResponse):
|
|
27
|
+
"""Response for an Ideogram V3 image task."""
|
|
28
|
+
|
|
29
|
+
id = required(str)
|
|
30
|
+
status = optional(str, enum=lambda: TaskResponse.Status.ALL)
|
|
31
|
+
images = optional([lambda: Image])
|
|
32
|
+
error = optional(str)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class CompletedIdeogramResponse(IdeogramResponse):
|
|
36
|
+
"""Narrowed response from ``run()`` once polling observes ``status: completed``."""
|
|
37
|
+
|
|
38
|
+
images = required([lambda: Image])
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: runapi-ideogram-v3
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Ideogram V3 image generation client for RunAPI
|
|
5
|
+
Project-URL: Homepage, https://runapi.ai/models/ideogram-v3
|
|
6
|
+
Project-URL: Documentation, https://runapi.ai/docs#sdk-ideogram-v3
|
|
7
|
+
Author-email: RunAPI <contact@runapi.ai>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
Keywords: ai,edit-image,ideogram-v3,runapi,sdk,text-to-image
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Requires-Dist: runapi-core
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# Ideogram V3 Python SDK for RunAPI
|
|
15
|
+
|
|
16
|
+
The Ideogram V3 Python SDK is the language-specific package for Ideogram V3 on
|
|
17
|
+
RunAPI. Use it for text-to-image, edit-image, remix-image, and reframe-image
|
|
18
|
+
flows when your application needs JSON request bodies, task status lookup, and
|
|
19
|
+
consistent RunAPI errors in Python.
|
|
20
|
+
|
|
21
|
+
For model details, use https://runapi.ai/models/ideogram-v3; for API reference,
|
|
22
|
+
use https://runapi.ai/docs#ideogram-v3; for SDK docs, use
|
|
23
|
+
https://runapi.ai/docs#sdk-ideogram-v3.
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install runapi-ideogram-v3
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Quick start
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from runapi.ideogram_v3 import IdeogramV3Client
|
|
35
|
+
|
|
36
|
+
client = IdeogramV3Client() # reads RUNAPI_API_KEY, or pass api_key="sk-..."
|
|
37
|
+
|
|
38
|
+
task = client.text_to_image.create(
|
|
39
|
+
model="ideogram-v3-text-to-image",
|
|
40
|
+
prompt="A cinematic lakeside at twilight",
|
|
41
|
+
aspect_ratio="16:9",
|
|
42
|
+
rendering_speed="quality",
|
|
43
|
+
)
|
|
44
|
+
status = client.text_to_image.get(task.id)
|
|
45
|
+
|
|
46
|
+
edit = client.edit_image.create(
|
|
47
|
+
model="ideogram-v3-edit",
|
|
48
|
+
prompt="Replace the sky with aurora",
|
|
49
|
+
source_image_url="https://example.com/source.jpg",
|
|
50
|
+
mask_url="https://example.com/mask.png",
|
|
51
|
+
)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Use `create` to submit a task and return quickly, `get` to fetch the latest task
|
|
55
|
+
state, and `run` to create and poll until completion:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
result = client.text_to_image.run(
|
|
59
|
+
model="ideogram-v3-text-to-image",
|
|
60
|
+
prompt="A serene mountain lake at dawn",
|
|
61
|
+
)
|
|
62
|
+
print(result.images[0].url)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
In web request handlers, prefer `create` plus webhook or later `get` polling so a
|
|
66
|
+
worker is not held open.
|
|
67
|
+
|
|
68
|
+
RunAPI-generated file URLs are temporary. Download and store generated images in
|
|
69
|
+
your own durable storage within 7 days; do not treat returned URLs as long-term
|
|
70
|
+
assets.
|
|
71
|
+
|
|
72
|
+
## Language notes
|
|
73
|
+
|
|
74
|
+
Pass parameters as keyword arguments and catch the `runapi.ideogram_v3` error
|
|
75
|
+
classes when building image jobs or scripts. The available resources are
|
|
76
|
+
`text_to_image`, `edit_image`, `remix_image`, and `reframe_image`. Keep
|
|
77
|
+
`RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys
|
|
78
|
+
or callback secrets.
|
|
79
|
+
|
|
80
|
+
## Links
|
|
81
|
+
|
|
82
|
+
- Model page: https://runapi.ai/models/ideogram-v3
|
|
83
|
+
- SDK docs: https://runapi.ai/docs#sdk-ideogram-v3
|
|
84
|
+
- Product docs: https://runapi.ai/docs#ideogram-v3
|
|
85
|
+
- Pricing and rate limits: https://runapi.ai/models/ideogram-v3
|
|
86
|
+
- Full catalog: https://runapi.ai/models
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
Licensed under the Apache License, Version 2.0.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
runapi/ideogram_v3/__init__.py,sha256=OXomysVxiDUVqplhTwOGpEs9gxFQ0gy9ylPBWcw1RiA,473
|
|
2
|
+
runapi/ideogram_v3/_validators.py,sha256=Ofy4Kgwc6QS4ECIEPEOvW5YuGkkaELYMyX1hQPkV_L0,592
|
|
3
|
+
runapi/ideogram_v3/client.py,sha256=Vyga3YLbc2Brjajr6IPto63EzlGwR_t9JMP_w0lzjZM,1116
|
|
4
|
+
runapi/ideogram_v3/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
runapi/ideogram_v3/types.py,sha256=kAN7M22L3E4jPIUPGniQxAeVvPcx-WjoSmdUTSidH3E,1183
|
|
6
|
+
runapi/ideogram_v3/resources/__init__.py,sha256=FJw-9HOqQJkyju2Oeox64tBD0EsMHlhtkXbsIaNMXRQ,219
|
|
7
|
+
runapi/ideogram_v3/resources/edit_image.py,sha256=cZBBMslImP5dJhNilqzj_PucqlN1fOehc57lqMnHthw,3357
|
|
8
|
+
runapi/ideogram_v3/resources/reframe_image.py,sha256=dBZyWYd7KWRX1pQuY2B2gTOFiy0KEWCAwEtkiZL5piw,2537
|
|
9
|
+
runapi/ideogram_v3/resources/remix_image.py,sha256=lmtYuc_TBLSBz5JyZ0Ry8exLIuW_ENIaYM-3gvC3AX0,4237
|
|
10
|
+
runapi/ideogram_v3/resources/text_to_image.py,sha256=9HvgEupNSVEWxKkA4wKh1aAucHbZPX0DyoXytvV6c08,3266
|
|
11
|
+
runapi_ideogram_v3-0.1.0.dist-info/METADATA,sha256=mqmZsA0IRHSbReyIJcsANFG1iys5saQ3NRZ5S2gUNOw,2856
|
|
12
|
+
runapi_ideogram_v3-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
13
|
+
runapi_ideogram_v3-0.1.0.dist-info/RECORD,,
|