runapi-ideogram-v3 0.2.1__tar.gz → 0.3.0__tar.gz

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.
@@ -1,18 +1,18 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: runapi-ideogram-v3
3
- Version: 0.2.1
3
+ Version: 0.3.0
4
4
  Summary: RunAPI Ideogram V3 SDK for text-to-image, image remix, reframe, and edit workflows in JavaScript, Python, Ruby, Go, Java, and PHP
5
5
  Project-URL: Homepage, https://runapi.ai/models/ideogram-v3
6
6
  Project-URL: Documentation, https://runapi.ai/docs/resources/sdks
7
7
  Project-URL: Source, https://github.com/runapi-ai/ideogram-v3-sdk
8
8
  Project-URL: Issues, https://github.com/runapi-ai/ideogram-v3-sdk/issues
9
9
  Project-URL: Changelog, https://github.com/runapi-ai/ideogram-v3-sdk/blob/main/CHANGELOG.md
10
- Project-URL: Release Notes, https://github.com/runapi-ai/ideogram-v3-sdk/releases/tag/python%2Fv0.2.1
10
+ Project-URL: Release Notes, https://github.com/runapi-ai/ideogram-v3-sdk/releases/tag/python%2Fv0.3.0
11
11
  Author-email: RunAPI <contact@runapi.ai>
12
12
  License-Expression: Apache-2.0
13
13
  Keywords: api,golang,gradle,ideogram-api,ideogram-v3,image-api,image-generation,java,maven,python,ruby,runapi,runapi-ai,sdk,text-to-image,typescript
14
14
  Requires-Python: >=3.9
15
- Requires-Dist: runapi-core>=0.3.3
15
+ Requires-Dist: runapi-core~=0.10.0
16
16
  Description-Content-Type: text/markdown
17
17
 
18
18
  # Ideogram V3 API Python SDK for RunAPI
@@ -4,14 +4,14 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "runapi-ideogram-v3"
7
- version = "0.2.1"
7
+ version = "0.3.0"
8
8
  description = "RunAPI Ideogram V3 SDK for text-to-image, image remix, reframe, and edit workflows in JavaScript, Python, Ruby, Go, Java, and PHP"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
11
11
  license = "Apache-2.0"
12
12
  authors = [{ name = "RunAPI", email = "contact@runapi.ai" }]
13
13
  keywords = ["runapi", "runapi-ai", "ideogram-v3", "api", "sdk", "typescript", "python", "ruby", "golang", "java", "maven", "gradle", "image-generation", "text-to-image", "image-api", "ideogram-api"]
14
- dependencies = ["runapi-core>=0.3.3"]
14
+ dependencies = ["runapi-core~=0.10.0"]
15
15
 
16
16
  [project.urls]
17
17
  Homepage = "https://runapi.ai/models/ideogram-v3"
@@ -19,7 +19,7 @@ Documentation = "https://runapi.ai/docs/resources/sdks"
19
19
  Source = "https://github.com/runapi-ai/ideogram-v3-sdk"
20
20
  Issues = "https://github.com/runapi-ai/ideogram-v3-sdk/issues"
21
21
  Changelog = "https://github.com/runapi-ai/ideogram-v3-sdk/blob/main/CHANGELOG.md"
22
- "Release Notes" = "https://github.com/runapi-ai/ideogram-v3-sdk/releases/tag/python%2Fv0.2.1"
22
+ "Release Notes" = "https://github.com/runapi-ai/ideogram-v3-sdk/releases/tag/python%2Fv0.3.0"
23
23
 
24
24
  [tool.hatch.build.targets.wheel]
25
25
  packages = ["src/runapi"]
@@ -2,13 +2,11 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import Any, Dict, Optional
5
+ from typing import Any, Optional
6
6
 
7
- from runapi.core import Resource, ValidationError, RequestOptions
7
+ from runapi.core import Resource, RequestOptions
8
8
 
9
- from ..contract_gen import CONTRACT
10
9
  from ..types import (
11
- CHARACTER_EDIT_MODEL,
12
10
  CompletedIdeogramResponse,
13
11
  IdeogramResponse,
14
12
  )
@@ -20,7 +18,6 @@ class EditImage(Resource):
20
18
  ENDPOINT = "/api/v1/ideogram_v3/edit_image"
21
19
  RESPONSE_CLASS = IdeogramResponse
22
20
  COMPLETED_RESPONSE_CLASS = CompletedIdeogramResponse
23
- PROMPT_MAX_LENGTH = 5000
24
21
 
25
22
  def run(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
26
23
  """Create an edit-image task and poll until it completes.
@@ -44,7 +41,6 @@ class EditImage(Resource):
44
41
  The task creation result with an id.
45
42
  """
46
43
  compacted = self._compact_params(params)
47
- self._validate_params(compacted)
48
44
  return self._request("post", self.ENDPOINT, body=compacted, options=options)
49
45
 
50
46
  def get(self, id: str, options: Optional[RequestOptions] = None) -> Any:
@@ -57,26 +53,3 @@ class EditImage(Resource):
57
53
  The current task status.
58
54
  """
59
55
  return self._request("get", f"{self.ENDPOINT}/{id}", options=options)
60
-
61
- def _validate_params(self, params: Dict[str, Any]) -> None:
62
- self._validate_contract(CONTRACT["edit-image"], params)
63
- model = params.get("model")
64
-
65
- prompt = params.get("prompt")
66
- if not (isinstance(prompt, str) and prompt):
67
- raise ValidationError("prompt is required")
68
- if len(prompt) > self.PROMPT_MAX_LENGTH:
69
- raise ValidationError(f"prompt must be at most {self.PROMPT_MAX_LENGTH} characters")
70
-
71
- if not params.get("mask_url"):
72
- raise ValidationError("mask_url is required")
73
-
74
- self._validate_character_fields(params, model)
75
-
76
- def _validate_character_fields(self, params: Dict[str, Any], model: str) -> None:
77
- refs = params.get("reference_image_urls")
78
- if model == CHARACTER_EDIT_MODEL:
79
- if not (isinstance(refs, list) and refs):
80
- raise ValidationError("reference_image_urls is required")
81
- elif refs or params.get("style"):
82
- raise ValidationError(f"character edit fields are not supported for {model}")
@@ -2,11 +2,10 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import Any, Dict, Optional
5
+ from typing import Any, Optional
6
6
 
7
- from runapi.core import Resource, ValidationError, RequestOptions
7
+ from runapi.core import Resource, RequestOptions
8
8
 
9
- from ..contract_gen import CONTRACT
10
9
  from ..types import (
11
10
  CompletedIdeogramResponse,
12
11
  IdeogramResponse,
@@ -42,7 +41,6 @@ class ReframeImage(Resource):
42
41
  The task creation result with an id.
43
42
  """
44
43
  compacted = self._compact_params(params)
45
- self._validate_params(compacted)
46
44
  return self._request("post", self.ENDPOINT, body=compacted, options=options)
47
45
 
48
46
  def get(self, id: str, options: Optional[RequestOptions] = None) -> Any:
@@ -55,9 +53,3 @@ class ReframeImage(Resource):
55
53
  The current task status.
56
54
  """
57
55
  return self._request("get", f"{self.ENDPOINT}/{id}", options=options)
58
-
59
- def _validate_params(self, params: Dict[str, Any]) -> None:
60
- self._validate_contract(CONTRACT["reframe-image"], params)
61
-
62
- if not params.get("aspect_ratio"):
63
- raise ValidationError("aspect_ratio is required")
@@ -0,0 +1,55 @@
1
+ """Ideogram V3 remix-image resource (model: ideogram-v3-remix)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Optional
6
+
7
+ from runapi.core import Resource, RequestOptions
8
+
9
+ from ..types import (
10
+ CompletedIdeogramResponse,
11
+ IdeogramResponse,
12
+ )
13
+
14
+
15
+ class RemixImage(Resource):
16
+ """Remix a source image with Ideogram V3 models."""
17
+
18
+ ENDPOINT = "/api/v1/ideogram_v3/remix_image"
19
+ RESPONSE_CLASS = IdeogramResponse
20
+ COMPLETED_RESPONSE_CLASS = CompletedIdeogramResponse
21
+
22
+ def run(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
23
+ """Create a remix-image task and poll until it completes.
24
+
25
+ Args:
26
+ **params: Remix-image parameters (model, prompt, source_image_url, ...).
27
+
28
+ Returns:
29
+ The completed (narrowed) response.
30
+ """
31
+ task = self.create(options=options, **params)
32
+ return self._poll_until_complete(lambda: self.get(task.id, options=options))
33
+
34
+ def create(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
35
+ """Create a remix-image task and return immediately with an ``id``.
36
+
37
+ Args:
38
+ **params: Remix-image parameters (model, prompt, source_image_url, ...).
39
+
40
+ Returns:
41
+ The task creation result with an id.
42
+ """
43
+ compacted = self._compact_params(params)
44
+ return self._request("post", self.ENDPOINT, body=compacted, options=options)
45
+
46
+ def get(self, id: str, options: Optional[RequestOptions] = None) -> Any:
47
+ """Fetch the current status of a remix-image task.
48
+
49
+ Args:
50
+ id: The task id.
51
+
52
+ Returns:
53
+ The current task status.
54
+ """
55
+ return self._request("get", f"{self.ENDPOINT}/{id}", options=options)
@@ -2,13 +2,11 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import Any, Dict, Optional
5
+ from typing import Any, Optional
6
6
 
7
- from runapi.core import Resource, ValidationError, RequestOptions
7
+ from runapi.core import Resource, RequestOptions
8
8
 
9
- from ..contract_gen import CONTRACT
10
9
  from ..types import (
11
- CHARACTER_MODEL,
12
10
  CompletedIdeogramResponse,
13
11
  IdeogramResponse,
14
12
  )
@@ -20,7 +18,6 @@ class TextToImage(Resource):
20
18
  ENDPOINT = "/api/v1/ideogram_v3/text_to_image"
21
19
  RESPONSE_CLASS = IdeogramResponse
22
20
  COMPLETED_RESPONSE_CLASS = CompletedIdeogramResponse
23
- PROMPT_MAX_LENGTH = 5000
24
21
 
25
22
  def run(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
26
23
  """Create a text-to-image task and poll until it completes.
@@ -44,7 +41,6 @@ class TextToImage(Resource):
44
41
  The task creation result with an id.
45
42
  """
46
43
  compacted = self._compact_params(params)
47
- self._validate_params(compacted)
48
44
  return self._request("post", self.ENDPOINT, body=compacted, options=options)
49
45
 
50
46
  def get(self, id: str, options: Optional[RequestOptions] = None) -> Any:
@@ -57,23 +53,3 @@ class TextToImage(Resource):
57
53
  The current task status.
58
54
  """
59
55
  return self._request("get", f"{self.ENDPOINT}/{id}", options=options)
60
-
61
- def _validate_params(self, params: Dict[str, Any]) -> None:
62
- self._validate_contract(CONTRACT["text-to-image"], params)
63
- model = params.get("model")
64
-
65
- prompt = params.get("prompt")
66
- if not (isinstance(prompt, str) and prompt):
67
- raise ValidationError("prompt is required")
68
- if len(prompt) > self.PROMPT_MAX_LENGTH:
69
- raise ValidationError(f"prompt must be at most {self.PROMPT_MAX_LENGTH} characters")
70
-
71
- self._validate_character_refs(params, model)
72
-
73
- def _validate_character_refs(self, params: Dict[str, Any], model: str) -> None:
74
- refs = params.get("reference_image_urls")
75
- if model == CHARACTER_MODEL:
76
- if not (isinstance(refs, list) and refs):
77
- raise ValidationError("reference_image_urls is required")
78
- elif refs:
79
- raise ValidationError(f"reference_image_urls is not supported for {model}")
@@ -1,7 +1,7 @@
1
1
  import pytest
2
2
 
3
3
  from runapi.core import config
4
- from runapi.core.errors import AuthenticationError, ValidationError
4
+ from runapi.core.errors import AuthenticationError
5
5
  from runapi.ideogram_v3 import IdeogramV3Client
6
6
  from runapi.ideogram_v3.resources.edit_image import EditImage
7
7
  from runapi.ideogram_v3.resources.reframe_image import ReframeImage
@@ -88,8 +88,7 @@ def test_text_to_image_create_posts_compacted_body():
88
88
  "post",
89
89
  "/api/v1/ideogram_v3/text_to_image",
90
90
  {"model": "ideogram-v3-text-to-image", "prompt": "hello world", "aspect_ratio": "1:1"},
91
- ),
92
- ]
91
+ )]
93
92
  assert isinstance(result, IdeogramResponse)
94
93
 
95
94
 
@@ -117,10 +116,8 @@ def test_edit_image_create_posts_body():
117
116
  "model": "ideogram-v3-edit",
118
117
  "prompt": "add aurora",
119
118
  "source_image_url": "https://x/a.png",
120
- "mask_url": "https://x/m.png",
121
- },
122
- ),
123
- ]
119
+ "mask_url": "https://x/m.png"},
120
+ )]
124
121
 
125
122
 
126
123
  def test_remix_image_create_posts_body():
@@ -140,10 +137,8 @@ def test_remix_image_create_posts_body():
140
137
  "model": "ideogram-v3-remix",
141
138
  "prompt": "remix it",
142
139
  "source_image_url": "https://x/a.png",
143
- "strength": 0.5,
144
- },
145
- ),
146
- ]
140
+ "strength": 0.5},
141
+ )]
147
142
 
148
143
 
149
144
  def test_remix_image_get_fetches_by_id():
@@ -168,10 +163,8 @@ def test_reframe_image_create_posts_body():
168
163
  {
169
164
  "model": "ideogram-v3-reframe",
170
165
  "source_image_url": "https://x/a.png",
171
- "aspect_ratio": "16:9",
172
- },
173
- ),
174
- ]
166
+ "aspect_ratio": "16:9"},
167
+ )]
175
168
 
176
169
 
177
170
  def test_reframe_image_get_fetches_by_id():
@@ -187,7 +180,7 @@ def test_reframe_image_get_fetches_by_id():
187
180
  def test_text_to_image_run_narrows_completed_type():
188
181
  fake = FakeHttp(
189
182
  {"id": "t1", "status": "pending"},
190
- {"id": "t1", "status": "completed", "images": [{"url": "https://x/y.png"}]},
183
+ {"id": "t1", "status": "completed", "usage": {"cost": 0.05}, "images": [{"url": "https://x/y.png"}]},
191
184
  )
192
185
  client = IdeogramV3Client(api_key="k", http_client=fake)
193
186
  result = client.text_to_image.run(
@@ -200,7 +193,7 @@ def test_text_to_image_run_narrows_completed_type():
200
193
  def test_reframe_image_run_narrows_completed_type():
201
194
  fake = FakeHttp(
202
195
  {"id": "t1", "status": "pending"},
203
- {"id": "t1", "status": "completed", "images": [{"url": "https://x/r.png"}]},
196
+ {"id": "t1", "status": "completed", "usage": {"cost": 0.05}, "images": [{"url": "https://x/r.png"}]},
204
197
  )
205
198
  client = IdeogramV3Client(api_key="k", http_client=fake)
206
199
  result = client.reframe_image.run(
@@ -208,160 +201,3 @@ def test_reframe_image_run_narrows_completed_type():
208
201
  )
209
202
  assert isinstance(result, CompletedIdeogramResponse)
210
203
  assert result.images[0].url == "https://x/r.png"
211
-
212
-
213
- # --- validation: model + shared --------------------------------------------
214
-
215
-
216
- def test_text_to_image_rejects_unknown_model():
217
- client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
218
- with pytest.raises(
219
- ValidationError,
220
- match="model must be one of: ideogram-v3-character, ideogram-v3-text-to-image",
221
- ):
222
- client.text_to_image.create(model="nope", prompt="hi there")
223
-
224
-
225
- def test_text_to_image_requires_prompt():
226
- client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
227
- with pytest.raises(ValidationError, match="prompt is required"):
228
- client.text_to_image.create(model="ideogram-v3-text-to-image")
229
-
230
-
231
- def test_text_to_image_rejects_invalid_style_enum():
232
- client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
233
- with pytest.raises(
234
- ValidationError, match="style must be one of: auto, general, realistic, design"
235
- ):
236
- client.text_to_image.create(
237
- model="ideogram-v3-text-to-image", prompt="hi there", style="bogus"
238
- )
239
-
240
-
241
- def test_text_to_image_output_count_enum():
242
- client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
243
- with pytest.raises(ValidationError, match="output_count must be one of: 1, 2, 3, 4"):
244
- client.text_to_image.create(
245
- model="ideogram-v3-text-to-image", prompt="hi there", output_count=9
246
- )
247
-
248
-
249
- def test_character_model_requires_reference_image_urls():
250
- client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
251
- with pytest.raises(ValidationError, match="reference_image_urls is required"):
252
- client.text_to_image.create(model="ideogram-v3-character", prompt="hi there")
253
-
254
-
255
- def test_text_to_image_rejects_reference_image_urls_for_base_model():
256
- client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
257
- with pytest.raises(
258
- ValidationError, match="reference_image_urls is not supported for ideogram-v3-text-to-image"
259
- ):
260
- client.text_to_image.create(
261
- model="ideogram-v3-text-to-image",
262
- prompt="hi there",
263
- reference_image_urls=["https://x/a.png"],
264
- )
265
-
266
-
267
- # --- validation: edit ------------------------------------------------------
268
-
269
-
270
- def test_edit_requires_source_and_mask():
271
- client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
272
- with pytest.raises(ValidationError, match="source_image_url is required"):
273
- client.edit_image.create(
274
- model="ideogram-v3-edit", prompt="x", mask_url="https://x/m.png"
275
- )
276
- with pytest.raises(ValidationError, match="mask_url is required"):
277
- client.edit_image.create(
278
- model="ideogram-v3-edit", prompt="x", source_image_url="https://x/a.png"
279
- )
280
-
281
-
282
- def test_edit_rejects_character_fields_for_base_model():
283
- client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
284
- with pytest.raises(
285
- ValidationError, match="character edit fields are not supported for ideogram-v3-edit"
286
- ):
287
- client.edit_image.create(
288
- model="ideogram-v3-edit",
289
- prompt="x",
290
- source_image_url="https://x/a.png",
291
- mask_url="https://x/m.png",
292
- style="auto",
293
- )
294
-
295
-
296
- # --- validation: remix -----------------------------------------------------
297
-
298
-
299
- def test_remix_requires_source_image_url():
300
- client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
301
- with pytest.raises(ValidationError, match="source_image_url is required"):
302
- client.remix_image.create(model="ideogram-v3-remix", prompt="x")
303
-
304
-
305
- def test_remix_strength_out_of_range():
306
- client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
307
- with pytest.raises(ValidationError, match="strength must be between 0.01 and 1.0"):
308
- client.remix_image.create(
309
- model="ideogram-v3-remix",
310
- prompt="x",
311
- source_image_url="https://x/a.png",
312
- strength=2,
313
- )
314
-
315
-
316
- def test_remix_character_strength_min_differs():
317
- client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
318
- with pytest.raises(ValidationError, match="strength must be between 0.1 and 1.0"):
319
- client.remix_image.create(
320
- model="ideogram-v3-character-remix",
321
- prompt="x",
322
- source_image_url="https://x/a.png",
323
- reference_image_urls=["https://x/r.png"],
324
- strength=0.05,
325
- )
326
-
327
-
328
- def test_remix_rejects_character_fields_for_base_model():
329
- client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
330
- with pytest.raises(
331
- ValidationError, match="character remix fields are not supported for ideogram-v3-remix"
332
- ):
333
- client.remix_image.create(
334
- model="ideogram-v3-remix",
335
- prompt="x",
336
- source_image_url="https://x/a.png",
337
- reference_image_urls=["https://x/r.png"],
338
- )
339
-
340
-
341
- # --- validation: reframe ---------------------------------------------------
342
-
343
-
344
- def test_reframe_rejects_unknown_model():
345
- client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
346
- with pytest.raises(ValidationError, match="model must be one of: ideogram-v3-reframe"):
347
- client.reframe_image.create(
348
- model="ideogram-v3-remix", source_image_url="https://x/a.png", aspect_ratio="1:1"
349
- )
350
-
351
-
352
- def test_reframe_requires_aspect_ratio():
353
- client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
354
- with pytest.raises(ValidationError, match="aspect_ratio is required"):
355
- client.reframe_image.create(
356
- model="ideogram-v3-reframe", source_image_url="https://x/a.png"
357
- )
358
-
359
-
360
- def test_reframe_rejects_invalid_aspect_ratio_enum():
361
- client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
362
- with pytest.raises(
363
- ValidationError, match="aspect_ratio must be one of: 1:1, 3:4, 9:16, 4:3, 16:9"
364
- ):
365
- client.reframe_image.create(
366
- model="ideogram-v3-reframe", source_image_url="https://x/a.png", aspect_ratio="21:9"
367
- )
@@ -1,169 +0,0 @@
1
- CONTRACT = {
2
- "edit-image": {
3
- "models": ["ideogram-v3-character-edit", "ideogram-v3-edit"],
4
- "fields_by_model": {
5
- "ideogram-v3-character-edit": {
6
- "mask_url": {
7
- "required": True
8
- },
9
- "output_count": {
10
- "enum": [1, 2, 3, 4],
11
- "type": "integer"
12
- },
13
- "reference_image_urls": {
14
- "required": True
15
- },
16
- "rendering_speed": {
17
- "enum": ["turbo", "balanced", "quality"]
18
- },
19
- "seed": {
20
- "type": "integer"
21
- },
22
- "source_image_url": {
23
- "required": True
24
- },
25
- "style": {
26
- "enum": ["auto", "realistic", "fiction"]
27
- }
28
- },
29
- "ideogram-v3-edit": {
30
- "mask_url": {
31
- "required": True
32
- },
33
- "output_count": {
34
- "enum": [1, 2, 3, 4],
35
- "type": "integer"
36
- },
37
- "rendering_speed": {
38
- "enum": ["turbo", "balanced", "quality"]
39
- },
40
- "seed": {
41
- "type": "integer"
42
- },
43
- "source_image_url": {
44
- "required": True
45
- }
46
- }
47
- }
48
- },
49
- "reframe-image": {
50
- "models": ["ideogram-v3-reframe"],
51
- "fields_by_model": {
52
- "ideogram-v3-reframe": {
53
- "aspect_ratio": {
54
- "enum": ["1:1", "3:4", "9:16", "4:3", "16:9"]
55
- },
56
- "output_count": {
57
- "enum": [1, 2, 3, 4],
58
- "type": "integer"
59
- },
60
- "rendering_speed": {
61
- "enum": ["turbo", "balanced", "quality"]
62
- },
63
- "seed": {
64
- "type": "integer"
65
- },
66
- "source_image_url": {
67
- "required": True
68
- },
69
- "style": {
70
- "enum": ["auto", "general", "realistic", "design"]
71
- }
72
- }
73
- }
74
- },
75
- "remix-image": {
76
- "models": ["ideogram-v3-character-remix", "ideogram-v3-remix"],
77
- "fields_by_model": {
78
- "ideogram-v3-character-remix": {
79
- "aspect_ratio": {
80
- "enum": ["1:1", "3:4", "9:16", "4:3", "16:9"]
81
- },
82
- "output_count": {
83
- "enum": [1, 2, 3, 4],
84
- "type": "integer"
85
- },
86
- "reference_image_urls": {
87
- "required": True
88
- },
89
- "rendering_speed": {
90
- "enum": ["turbo", "balanced", "quality"]
91
- },
92
- "seed": {
93
- "type": "integer"
94
- },
95
- "source_image_url": {
96
- "required": True
97
- },
98
- "style": {
99
- "enum": ["auto", "realistic", "fiction"]
100
- }
101
- },
102
- "ideogram-v3-remix": {
103
- "aspect_ratio": {
104
- "enum": ["1:1", "3:4", "9:16", "4:3", "16:9"]
105
- },
106
- "output_count": {
107
- "enum": [1, 2, 3, 4],
108
- "type": "integer"
109
- },
110
- "rendering_speed": {
111
- "enum": ["turbo", "balanced", "quality"]
112
- },
113
- "seed": {
114
- "type": "integer"
115
- },
116
- "source_image_url": {
117
- "required": True
118
- },
119
- "style": {
120
- "enum": ["auto", "general", "realistic", "design"]
121
- }
122
- }
123
- }
124
- },
125
- "text-to-image": {
126
- "models": ["ideogram-v3-character", "ideogram-v3-text-to-image"],
127
- "fields_by_model": {
128
- "ideogram-v3-character": {
129
- "aspect_ratio": {
130
- "enum": ["1:1", "3:4", "9:16", "4:3", "16:9"]
131
- },
132
- "output_count": {
133
- "enum": [1, 2, 3, 4],
134
- "type": "integer"
135
- },
136
- "reference_image_urls": {
137
- "required": True
138
- },
139
- "rendering_speed": {
140
- "enum": ["turbo", "balanced", "quality"]
141
- },
142
- "seed": {
143
- "type": "integer"
144
- },
145
- "style": {
146
- "enum": ["auto", "realistic", "fiction"]
147
- }
148
- },
149
- "ideogram-v3-text-to-image": {
150
- "aspect_ratio": {
151
- "enum": ["1:1", "3:4", "9:16", "4:3", "16:9"]
152
- },
153
- "output_count": {
154
- "enum": [1, 2, 3, 4],
155
- "type": "integer"
156
- },
157
- "rendering_speed": {
158
- "enum": ["turbo", "balanced", "quality"]
159
- },
160
- "seed": {
161
- "type": "integer"
162
- },
163
- "style": {
164
- "enum": ["auto", "general", "realistic", "design"]
165
- }
166
- }
167
- }
168
- }
169
- }
@@ -1,99 +0,0 @@
1
- """Ideogram V3 remix-image resource (model: ideogram-v3-remix)."""
2
-
3
- from __future__ import annotations
4
-
5
- from typing import Any, Dict, Optional
6
-
7
- from runapi.core import Resource, ValidationError, RequestOptions
8
-
9
- from ..contract_gen import CONTRACT
10
- from ..types import (
11
- CHARACTER_REMIX_MODEL,
12
- CompletedIdeogramResponse,
13
- IdeogramResponse,
14
- )
15
-
16
-
17
- class RemixImage(Resource):
18
- """Remix a source image with Ideogram V3 models."""
19
-
20
- ENDPOINT = "/api/v1/ideogram_v3/remix_image"
21
- RESPONSE_CLASS = IdeogramResponse
22
- COMPLETED_RESPONSE_CLASS = CompletedIdeogramResponse
23
- PROMPT_MAX_LENGTH = 5000
24
- STRENGTH_MIN = 0.01
25
- CHARACTER_REMIX_STRENGTH_MIN = 0.1
26
- STRENGTH_MAX = 1.0
27
-
28
- def run(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
29
- """Create a remix-image task and poll until it completes.
30
-
31
- Args:
32
- **params: Remix-image parameters (model, prompt, source_image_url, ...).
33
-
34
- Returns:
35
- The completed (narrowed) response.
36
- """
37
- task = self.create(options=options, **params)
38
- return self._poll_until_complete(lambda: self.get(task.id, options=options))
39
-
40
- def create(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
41
- """Create a remix-image task and return immediately with an ``id``.
42
-
43
- Args:
44
- **params: Remix-image parameters (model, prompt, source_image_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, options=options)
52
-
53
- def get(self, id: str, options: Optional[RequestOptions] = None) -> Any:
54
- """Fetch the current status of a remix-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}", options=options)
63
-
64
- def _validate_params(self, params: Dict[str, Any]) -> None:
65
- self._validate_contract(CONTRACT["remix-image"], params)
66
- model = params.get("model")
67
-
68
- prompt = params.get("prompt")
69
- if not (isinstance(prompt, str) and prompt):
70
- raise ValidationError("prompt is required")
71
- if len(prompt) > self.PROMPT_MAX_LENGTH:
72
- raise ValidationError(f"prompt must be at most {self.PROMPT_MAX_LENGTH} characters")
73
-
74
- self._validate_character_fields(params, model)
75
- self._validate_strength(params, model)
76
-
77
- def _validate_character_fields(self, params: Dict[str, Any], model: str) -> None:
78
- refs = params.get("reference_image_urls")
79
- if model == CHARACTER_REMIX_MODEL:
80
- if not (isinstance(refs, list) and refs):
81
- raise ValidationError("reference_image_urls is required")
82
- elif refs or params.get("style_reference_image_urls") or params.get("reference_mask_urls"):
83
- raise ValidationError(f"character remix fields are not supported for {model}")
84
-
85
- def _validate_strength(self, params: Dict[str, Any], model: str) -> None:
86
- strength = params.get("strength")
87
- if strength is None:
88
- return
89
- minimum = (
90
- self.CHARACTER_REMIX_STRENGTH_MIN
91
- if model == CHARACTER_REMIX_MODEL
92
- else self.STRENGTH_MIN
93
- )
94
- try:
95
- numeric = float(strength)
96
- except (TypeError, ValueError):
97
- numeric = None
98
- if numeric is None or numeric < minimum or numeric > self.STRENGTH_MAX:
99
- raise ValidationError(f"strength must be between {minimum} and {self.STRENGTH_MAX}")