runapi-ideogram-v3 0.1.0__tar.gz → 0.2.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.
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.4
2
+ Name: runapi-ideogram-v3
3
+ Version: 0.2.0
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
+ Project-URL: Homepage, https://runapi.ai/models/ideogram-v3
6
+ Project-URL: Documentation, https://runapi.ai/docs#sdk-ideogram-v3
7
+ Project-URL: Source, https://github.com/runapi-ai/ideogram-v3-sdk
8
+ Project-URL: Issues, https://github.com/runapi-ai/ideogram-v3-sdk/issues
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.0
11
+ Author-email: RunAPI <contact@runapi.ai>
12
+ License-Expression: Apache-2.0
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
+ Requires-Python: >=3.9
15
+ Requires-Dist: runapi-core>=0.3.0
16
+ Description-Content-Type: text/markdown
17
+
18
+ # Ideogram V3 API Python SDK for RunAPI
19
+
20
+ The Ideogram V3 Python SDK is the language-specific package for Ideogram V3 on RunAPI. Use this package for image generation, image editing, and creative production workflows when your application needs request bodies, task status lookup, and consistent RunAPI errors in Python.
21
+
22
+ This README is the Python package guide inside the public `ideogram-v3-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/ideogram-v3; for API reference, use https://runapi.ai/docs#ideogram-v3; for SDK docs, use https://runapi.ai/docs#sdk-ideogram-v3.
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ pip install runapi-ideogram-v3
28
+ ```
29
+
30
+ ## Quick start
31
+
32
+ ```python
33
+ from runapi.ideogram_v3 import IdeogramV3Client
34
+
35
+ client = IdeogramV3Client() # reads RUNAPI_API_KEY, or pass api_key="sk-..."
36
+
37
+ task = client.text_to_image.create(
38
+ model="ideogram-v3-text-to-image",
39
+ prompt="A cinematic lakeside at twilight",
40
+ aspect_ratio="16:9",
41
+ rendering_speed="quality",
42
+ )
43
+ status = client.text_to_image.get(task.id)
44
+
45
+ edit = client.edit_image.create(
46
+ model="ideogram-v3-edit",
47
+ prompt="Replace the sky with aurora",
48
+ source_image_url="https://cdn.runapi.ai/public/samples/image.jpg",
49
+ mask_url="https://cdn.runapi.ai/public/samples/mask.png",
50
+ )
51
+ ```
52
+
53
+ Use `create` to submit a task and return quickly, `get` to fetch the latest task state, and `run` to create and poll until completion:
54
+
55
+ ```python
56
+ result = client.text_to_image.run(
57
+ model="ideogram-v3-text-to-image",
58
+ prompt="A serene mountain lake at dawn",
59
+ )
60
+ print(result.images[0].url)
61
+ ```
62
+
63
+ In web request handlers, prefer `create` plus webhook or later `get` polling so a worker is not held open.
64
+
65
+ RunAPI-generated file URLs are temporary. Download and store generated images, videos, audio, or other files in your own durable storage within 7 days; do not treat returned URLs as long-term assets.
66
+
67
+ ## Language notes
68
+
69
+ Pass parameters as keyword arguments and catch the `runapi.ideogram_v3` error classes when building image jobs or scripts. The available resources are `text_to_image`, `edit_image`, `remix_image`, and `reframe_image`. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
70
+
71
+ ## Links
72
+
73
+ - Model page: https://runapi.ai/models/ideogram-v3
74
+ - SDK docs: https://runapi.ai/docs#sdk-ideogram-v3
75
+ - Product docs: https://runapi.ai/docs#ideogram-v3
76
+ - Pricing and rate limits: https://runapi.ai/models/ideogram-v3/text-to-image
77
+ - Provider comparison: https://runapi.ai/providers/ideogram
78
+ - Full catalog: https://runapi.ai/models
79
+ - Repository: https://github.com/runapi-ai/ideogram-v3-sdk
80
+
81
+ ## License
82
+
83
+ Licensed under the Apache License, Version 2.0.
@@ -0,0 +1,66 @@
1
+ # Ideogram V3 API Python SDK for RunAPI
2
+
3
+ The Ideogram V3 Python SDK is the language-specific package for Ideogram V3 on RunAPI. Use this package for image generation, image editing, and creative production workflows when your application needs request bodies, task status lookup, and consistent RunAPI errors in Python.
4
+
5
+ This README is the Python package guide inside the public `ideogram-v3-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/ideogram-v3; for API reference, use https://runapi.ai/docs#ideogram-v3; for SDK docs, use https://runapi.ai/docs#sdk-ideogram-v3.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pip install runapi-ideogram-v3
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```python
16
+ from runapi.ideogram_v3 import IdeogramV3Client
17
+
18
+ client = IdeogramV3Client() # reads RUNAPI_API_KEY, or pass api_key="sk-..."
19
+
20
+ task = client.text_to_image.create(
21
+ model="ideogram-v3-text-to-image",
22
+ prompt="A cinematic lakeside at twilight",
23
+ aspect_ratio="16:9",
24
+ rendering_speed="quality",
25
+ )
26
+ status = client.text_to_image.get(task.id)
27
+
28
+ edit = client.edit_image.create(
29
+ model="ideogram-v3-edit",
30
+ prompt="Replace the sky with aurora",
31
+ source_image_url="https://cdn.runapi.ai/public/samples/image.jpg",
32
+ mask_url="https://cdn.runapi.ai/public/samples/mask.png",
33
+ )
34
+ ```
35
+
36
+ Use `create` to submit a task and return quickly, `get` to fetch the latest task state, and `run` to create and poll until completion:
37
+
38
+ ```python
39
+ result = client.text_to_image.run(
40
+ model="ideogram-v3-text-to-image",
41
+ prompt="A serene mountain lake at dawn",
42
+ )
43
+ print(result.images[0].url)
44
+ ```
45
+
46
+ In web request handlers, prefer `create` plus webhook or later `get` polling so a worker is not held open.
47
+
48
+ RunAPI-generated file URLs are temporary. Download and store generated images, videos, audio, or other files in your own durable storage within 7 days; do not treat returned URLs as long-term assets.
49
+
50
+ ## Language notes
51
+
52
+ Pass parameters as keyword arguments and catch the `runapi.ideogram_v3` error classes when building image jobs or scripts. The available resources are `text_to_image`, `edit_image`, `remix_image`, and `reframe_image`. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
53
+
54
+ ## Links
55
+
56
+ - Model page: https://runapi.ai/models/ideogram-v3
57
+ - SDK docs: https://runapi.ai/docs#sdk-ideogram-v3
58
+ - Product docs: https://runapi.ai/docs#ideogram-v3
59
+ - Pricing and rate limits: https://runapi.ai/models/ideogram-v3/text-to-image
60
+ - Provider comparison: https://runapi.ai/providers/ideogram
61
+ - Full catalog: https://runapi.ai/models
62
+ - Repository: https://github.com/runapi-ai/ideogram-v3-sdk
63
+
64
+ ## License
65
+
66
+ Licensed under the Apache License, Version 2.0.
@@ -0,0 +1,34 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "runapi-ideogram-v3"
7
+ version = "0.2.0"
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
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "Apache-2.0"
12
+ authors = [{ name = "RunAPI", email = "contact@runapi.ai" }]
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.0"]
15
+
16
+ [project.urls]
17
+ Homepage = "https://runapi.ai/models/ideogram-v3"
18
+ Documentation = "https://runapi.ai/docs#sdk-ideogram-v3"
19
+ Source = "https://github.com/runapi-ai/ideogram-v3-sdk"
20
+ Issues = "https://github.com/runapi-ai/ideogram-v3-sdk/issues"
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.0"
23
+
24
+ [tool.hatch.build.targets.wheel]
25
+ packages = ["src/runapi"]
26
+
27
+ [tool.uv]
28
+ package = true
29
+
30
+ [dependency-groups]
31
+ dev = ["pytest>=8"]
32
+
33
+ [tool.runapi]
34
+ slug = "ideogram-v3"
@@ -4,7 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  from typing import Any, Optional
6
6
 
7
- from runapi.core import ClientOptions, HttpClient, resolve_api_key
7
+ from runapi.core import ProviderClient
8
8
 
9
9
  from .resources.edit_image import EditImage
10
10
  from .resources.reframe_image import ReframeImage
@@ -12,7 +12,7 @@ from .resources.remix_image import RemixImage
12
12
  from .resources.text_to_image import TextToImage
13
13
 
14
14
 
15
- class IdeogramV3Client:
15
+ class IdeogramV3Client(ProviderClient):
16
16
  """Ideogram V3 image generation client.
17
17
 
18
18
  Example::
@@ -25,9 +25,8 @@ class IdeogramV3Client:
25
25
  """
26
26
 
27
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)
28
+ super().__init__(api_key, **options)
29
+ http = self._http
31
30
  self.text_to_image = TextToImage(http)
32
31
  self.edit_image = EditImage(http)
33
32
  self.remix_image = RemixImage(http)
@@ -0,0 +1,169 @@
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
+ }
@@ -2,16 +2,13 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import Any, Dict
5
+ from typing import Any, Dict, Optional
6
6
 
7
- from runapi.core import Resource, ValidationError
7
+ from runapi.core import Resource, ValidationError, RequestOptions
8
8
 
9
- from .._validators import validate_output_count
9
+ from ..contract_gen import CONTRACT
10
10
  from ..types import (
11
11
  CHARACTER_EDIT_MODEL,
12
- CHARACTER_STYLES,
13
- EDIT_MODEL,
14
- RENDERING_SPEEDS,
15
12
  CompletedIdeogramResponse,
16
13
  IdeogramResponse,
17
14
  )
@@ -25,7 +22,7 @@ class EditImage(Resource):
25
22
  COMPLETED_RESPONSE_CLASS = CompletedIdeogramResponse
26
23
  PROMPT_MAX_LENGTH = 5000
27
24
 
28
- def run(self, **params: Any) -> Any:
25
+ def run(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
29
26
  """Create an edit-image task and poll until it completes.
30
27
 
31
28
  Args:
@@ -34,10 +31,10 @@ class EditImage(Resource):
34
31
  Returns:
35
32
  The completed (narrowed) response.
36
33
  """
37
- task = self.create(**params)
38
- return self._poll_until_complete(lambda: self.get(task.id))
34
+ task = self.create(options=options, **params)
35
+ return self._poll_until_complete(lambda: self.get(task.id, options=options))
39
36
 
40
- def create(self, **params: Any) -> Any:
37
+ def create(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
41
38
  """Create an edit-image task and return immediately with an ``id``.
42
39
 
43
40
  Args:
@@ -48,9 +45,9 @@ class EditImage(Resource):
48
45
  """
49
46
  compacted = self._compact_params(params)
50
47
  self._validate_params(compacted)
51
- return self._request("post", self.ENDPOINT, body=compacted)
48
+ return self._request("post", self.ENDPOINT, body=compacted, options=options)
52
49
 
53
- def get(self, id: str) -> Any:
50
+ def get(self, id: str, options: Optional[RequestOptions] = None) -> Any:
54
51
  """Fetch the current status of an edit-image task.
55
52
 
56
53
  Args:
@@ -59,16 +56,11 @@ class EditImage(Resource):
59
56
  Returns:
60
57
  The current task status.
61
58
  """
62
- return self._request("get", f"{self.ENDPOINT}/{id}")
59
+ return self._request("get", f"{self.ENDPOINT}/{id}", options=options)
63
60
 
64
61
  def _validate_params(self, params: Dict[str, Any]) -> None:
62
+ self._validate_contract(CONTRACT["edit-image"], params)
65
63
  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
64
 
73
65
  prompt = params.get("prompt")
74
66
  if not (isinstance(prompt, str) and prompt):
@@ -76,12 +68,9 @@ class EditImage(Resource):
76
68
  if len(prompt) > self.PROMPT_MAX_LENGTH:
77
69
  raise ValidationError(f"prompt must be at most {self.PROMPT_MAX_LENGTH} characters")
78
70
 
79
- if not params.get("source_image_url"):
80
- raise ValidationError("source_image_url is required")
81
71
  if not params.get("mask_url"):
82
72
  raise ValidationError("mask_url is required")
83
73
 
84
- self._validate_optional(params, "rendering_speed", RENDERING_SPEEDS)
85
74
  self._validate_character_fields(params, model)
86
75
 
87
76
  def _validate_character_fields(self, params: Dict[str, Any], model: str) -> None:
@@ -89,7 +78,5 @@ class EditImage(Resource):
89
78
  if model == CHARACTER_EDIT_MODEL:
90
79
  if not (isinstance(refs, list) and refs):
91
80
  raise ValidationError("reference_image_urls is required")
92
- self._validate_optional(params, "style", CHARACTER_STYLES)
93
81
  elif refs or params.get("style"):
94
82
  raise ValidationError(f"character edit fields are not supported for {model}")
95
- validate_output_count(params)
@@ -2,16 +2,12 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import Any, Dict
5
+ from typing import Any, Dict, Optional
6
6
 
7
- from runapi.core import Resource, ValidationError
7
+ from runapi.core import Resource, ValidationError, RequestOptions
8
8
 
9
- from .._validators import validate_output_count
9
+ from ..contract_gen import CONTRACT
10
10
  from ..types import (
11
- ASPECT_RATIOS,
12
- REFRAME_MODEL,
13
- RENDERING_SPEEDS,
14
- STYLES,
15
11
  CompletedIdeogramResponse,
16
12
  IdeogramResponse,
17
13
  )
@@ -24,7 +20,7 @@ class ReframeImage(Resource):
24
20
  RESPONSE_CLASS = IdeogramResponse
25
21
  COMPLETED_RESPONSE_CLASS = CompletedIdeogramResponse
26
22
 
27
- def run(self, **params: Any) -> Any:
23
+ def run(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
28
24
  """Create a reframe-image task and poll until it completes.
29
25
 
30
26
  Args:
@@ -33,10 +29,10 @@ class ReframeImage(Resource):
33
29
  Returns:
34
30
  The completed (narrowed) response.
35
31
  """
36
- task = self.create(**params)
37
- return self._poll_until_complete(lambda: self.get(task.id))
32
+ task = self.create(options=options, **params)
33
+ return self._poll_until_complete(lambda: self.get(task.id, options=options))
38
34
 
39
- def create(self, **params: Any) -> Any:
35
+ def create(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
40
36
  """Create a reframe-image task and return immediately with an ``id``.
41
37
 
42
38
  Args:
@@ -47,9 +43,9 @@ class ReframeImage(Resource):
47
43
  """
48
44
  compacted = self._compact_params(params)
49
45
  self._validate_params(compacted)
50
- return self._request("post", self.ENDPOINT, body=compacted)
46
+ return self._request("post", self.ENDPOINT, body=compacted, options=options)
51
47
 
52
- def get(self, id: str) -> Any:
48
+ def get(self, id: str, options: Optional[RequestOptions] = None) -> Any:
53
49
  """Fetch the current status of a reframe-image task.
54
50
 
55
51
  Args:
@@ -58,21 +54,10 @@ class ReframeImage(Resource):
58
54
  Returns:
59
55
  The current task status.
60
56
  """
61
- return self._request("get", f"{self.ENDPOINT}/{id}")
57
+ return self._request("get", f"{self.ENDPOINT}/{id}", options=options)
62
58
 
63
59
  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")
60
+ self._validate_contract(CONTRACT["reframe-image"], params)
61
+
72
62
  if not params.get("aspect_ratio"):
73
63
  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)
@@ -2,18 +2,13 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import Any, Dict
5
+ from typing import Any, Dict, Optional
6
6
 
7
- from runapi.core import Resource, ValidationError
7
+ from runapi.core import Resource, ValidationError, RequestOptions
8
8
 
9
- from .._validators import validate_output_count
9
+ from ..contract_gen import CONTRACT
10
10
  from ..types import (
11
- ASPECT_RATIOS,
12
11
  CHARACTER_REMIX_MODEL,
13
- CHARACTER_STYLES,
14
- REMIX_MODEL,
15
- RENDERING_SPEEDS,
16
- STYLES,
17
12
  CompletedIdeogramResponse,
18
13
  IdeogramResponse,
19
14
  )
@@ -30,7 +25,7 @@ class RemixImage(Resource):
30
25
  CHARACTER_REMIX_STRENGTH_MIN = 0.1
31
26
  STRENGTH_MAX = 1.0
32
27
 
33
- def run(self, **params: Any) -> Any:
28
+ def run(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
34
29
  """Create a remix-image task and poll until it completes.
35
30
 
36
31
  Args:
@@ -39,10 +34,10 @@ class RemixImage(Resource):
39
34
  Returns:
40
35
  The completed (narrowed) response.
41
36
  """
42
- task = self.create(**params)
43
- return self._poll_until_complete(lambda: self.get(task.id))
37
+ task = self.create(options=options, **params)
38
+ return self._poll_until_complete(lambda: self.get(task.id, options=options))
44
39
 
45
- def create(self, **params: Any) -> Any:
40
+ def create(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
46
41
  """Create a remix-image task and return immediately with an ``id``.
47
42
 
48
43
  Args:
@@ -53,9 +48,9 @@ class RemixImage(Resource):
53
48
  """
54
49
  compacted = self._compact_params(params)
55
50
  self._validate_params(compacted)
56
- return self._request("post", self.ENDPOINT, body=compacted)
51
+ return self._request("post", self.ENDPOINT, body=compacted, options=options)
57
52
 
58
- def get(self, id: str) -> Any:
53
+ def get(self, id: str, options: Optional[RequestOptions] = None) -> Any:
59
54
  """Fetch the current status of a remix-image task.
60
55
 
61
56
  Args:
@@ -64,16 +59,11 @@ class RemixImage(Resource):
64
59
  Returns:
65
60
  The current task status.
66
61
  """
67
- return self._request("get", f"{self.ENDPOINT}/{id}")
62
+ return self._request("get", f"{self.ENDPOINT}/{id}", options=options)
68
63
 
69
64
  def _validate_params(self, params: Dict[str, Any]) -> None:
65
+ self._validate_contract(CONTRACT["remix-image"], params)
70
66
  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
67
 
78
68
  prompt = params.get("prompt")
79
69
  if not (isinstance(prompt, str) and prompt):
@@ -81,15 +71,7 @@ class RemixImage(Resource):
81
71
  if len(prompt) > self.PROMPT_MAX_LENGTH:
82
72
  raise ValidationError(f"prompt must be at most {self.PROMPT_MAX_LENGTH} characters")
83
73
 
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
74
  self._validate_character_fields(params, model)
92
- validate_output_count(params)
93
75
  self._validate_strength(params, model)
94
76
 
95
77
  def _validate_character_fields(self, params: Dict[str, Any], model: str) -> None:
@@ -2,18 +2,13 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import Any, Dict
5
+ from typing import Any, Dict, Optional
6
6
 
7
- from runapi.core import Resource, ValidationError
7
+ from runapi.core import Resource, ValidationError, RequestOptions
8
8
 
9
- from .._validators import validate_output_count
9
+ from ..contract_gen import CONTRACT
10
10
  from ..types import (
11
- ASPECT_RATIOS,
12
11
  CHARACTER_MODEL,
13
- CHARACTER_STYLES,
14
- GENERATION_MODEL,
15
- RENDERING_SPEEDS,
16
- STYLES,
17
12
  CompletedIdeogramResponse,
18
13
  IdeogramResponse,
19
14
  )
@@ -27,7 +22,7 @@ class TextToImage(Resource):
27
22
  COMPLETED_RESPONSE_CLASS = CompletedIdeogramResponse
28
23
  PROMPT_MAX_LENGTH = 5000
29
24
 
30
- def run(self, **params: Any) -> Any:
25
+ def run(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
31
26
  """Create a text-to-image task and poll until it completes.
32
27
 
33
28
  Args:
@@ -36,10 +31,10 @@ class TextToImage(Resource):
36
31
  Returns:
37
32
  The completed (narrowed) response.
38
33
  """
39
- task = self.create(**params)
40
- return self._poll_until_complete(lambda: self.get(task.id))
34
+ task = self.create(options=options, **params)
35
+ return self._poll_until_complete(lambda: self.get(task.id, options=options))
41
36
 
42
- def create(self, **params: Any) -> Any:
37
+ def create(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
43
38
  """Create a text-to-image task and return immediately with an ``id``.
44
39
 
45
40
  Args:
@@ -50,9 +45,9 @@ class TextToImage(Resource):
50
45
  """
51
46
  compacted = self._compact_params(params)
52
47
  self._validate_params(compacted)
53
- return self._request("post", self.ENDPOINT, body=compacted)
48
+ return self._request("post", self.ENDPOINT, body=compacted, options=options)
54
49
 
55
- def get(self, id: str) -> Any:
50
+ def get(self, id: str, options: Optional[RequestOptions] = None) -> Any:
56
51
  """Fetch the current status of a text-to-image task.
57
52
 
58
53
  Args:
@@ -61,16 +56,11 @@ class TextToImage(Resource):
61
56
  Returns:
62
57
  The current task status.
63
58
  """
64
- return self._request("get", f"{self.ENDPOINT}/{id}")
59
+ return self._request("get", f"{self.ENDPOINT}/{id}", options=options)
65
60
 
66
61
  def _validate_params(self, params: Dict[str, Any]) -> None:
62
+ self._validate_contract(CONTRACT["text-to-image"], params)
67
63
  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
64
 
75
65
  prompt = params.get("prompt")
76
66
  if not (isinstance(prompt, str) and prompt):
@@ -78,12 +68,7 @@ class TextToImage(Resource):
78
68
  if len(prompt) > self.PROMPT_MAX_LENGTH:
79
69
  raise ValidationError(f"prompt must be at most {self.PROMPT_MAX_LENGTH} characters")
80
70
 
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
71
  self._validate_character_refs(params, model)
86
- validate_output_count(params)
87
72
 
88
73
  def _validate_character_refs(self, params: Dict[str, Any], model: str) -> None:
89
74
  refs = params.get("reference_image_urls")
@@ -4,19 +4,9 @@ from __future__ import annotations
4
4
 
5
5
  from runapi.core import BaseModel, TaskResponse, optional, required
6
6
 
7
- GENERATION_MODEL = "ideogram-v3-text-to-image"
8
- EDIT_MODEL = "ideogram-v3-edit"
9
- REMIX_MODEL = "ideogram-v3-remix"
10
7
  CHARACTER_MODEL = "ideogram-v3-character"
11
8
  CHARACTER_EDIT_MODEL = "ideogram-v3-character-edit"
12
9
  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
10
 
21
11
 
22
12
  class Image(BaseModel):
@@ -215,7 +215,10 @@ def test_reframe_image_run_narrows_completed_type():
215
215
 
216
216
  def test_text_to_image_rejects_unknown_model():
217
217
  client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
218
- with pytest.raises(ValidationError, match="Invalid model: nope"):
218
+ with pytest.raises(
219
+ ValidationError,
220
+ match="model must be one of: ideogram-v3-character, ideogram-v3-text-to-image",
221
+ ):
219
222
  client.text_to_image.create(model="nope", prompt="hi there")
220
223
 
221
224
 
@@ -227,7 +230,9 @@ def test_text_to_image_requires_prompt():
227
230
 
228
231
  def test_text_to_image_rejects_invalid_style_enum():
229
232
  client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
230
- with pytest.raises(ValidationError, match="Invalid style: bogus"):
233
+ with pytest.raises(
234
+ ValidationError, match="style must be one of: auto, general, realistic, design"
235
+ ):
231
236
  client.text_to_image.create(
232
237
  model="ideogram-v3-text-to-image", prompt="hi there", style="bogus"
233
238
  )
@@ -235,7 +240,7 @@ def test_text_to_image_rejects_invalid_style_enum():
235
240
 
236
241
  def test_text_to_image_output_count_enum():
237
242
  client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
238
- with pytest.raises(ValidationError, match="Invalid output_count: 9"):
243
+ with pytest.raises(ValidationError, match="output_count must be one of: 1, 2, 3, 4"):
239
244
  client.text_to_image.create(
240
245
  model="ideogram-v3-text-to-image", prompt="hi there", output_count=9
241
246
  )
@@ -265,7 +270,9 @@ def test_text_to_image_rejects_reference_image_urls_for_base_model():
265
270
  def test_edit_requires_source_and_mask():
266
271
  client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
267
272
  with pytest.raises(ValidationError, match="source_image_url is required"):
268
- client.edit_image.create(model="ideogram-v3-edit", prompt="x")
273
+ client.edit_image.create(
274
+ model="ideogram-v3-edit", prompt="x", mask_url="https://x/m.png"
275
+ )
269
276
  with pytest.raises(ValidationError, match="mask_url is required"):
270
277
  client.edit_image.create(
271
278
  model="ideogram-v3-edit", prompt="x", source_image_url="https://x/a.png"
@@ -336,7 +343,7 @@ def test_remix_rejects_character_fields_for_base_model():
336
343
 
337
344
  def test_reframe_rejects_unknown_model():
338
345
  client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
339
- with pytest.raises(ValidationError, match="Must be ideogram-v3-reframe"):
346
+ with pytest.raises(ValidationError, match="model must be one of: ideogram-v3-reframe"):
340
347
  client.reframe_image.create(
341
348
  model="ideogram-v3-remix", source_image_url="https://x/a.png", aspect_ratio="1:1"
342
349
  )
@@ -352,7 +359,9 @@ def test_reframe_requires_aspect_ratio():
352
359
 
353
360
  def test_reframe_rejects_invalid_aspect_ratio_enum():
354
361
  client = IdeogramV3Client(api_key="k", http_client=FakeHttp())
355
- with pytest.raises(ValidationError, match="Invalid aspect_ratio: 21:9"):
362
+ with pytest.raises(
363
+ ValidationError, match="aspect_ratio must be one of: 1:1, 3:4, 9:16, 4:3, 16:9"
364
+ ):
356
365
  client.reframe_image.create(
357
366
  model="ideogram-v3-reframe", source_image_url="https://x/a.png", aspect_ratio="21:9"
358
367
  )
@@ -1,29 +0,0 @@
1
- # Build artifacts
2
- dist/
3
- build/
4
- *.egg-info/
5
- *.egg
6
-
7
- # Bytecode
8
- __pycache__/
9
- *.py[cod]
10
-
11
- # Virtual environments
12
- .venv/
13
- venv/
14
-
15
- # uv
16
- uv.lock
17
-
18
- # Test / type caches
19
- .pytest_cache/
20
- .mypy_cache/
21
- .ruff_cache/
22
- .coverage
23
- htmlcov/
24
-
25
- # IDE / OS
26
- .idea/
27
- .vscode/
28
- *.swp
29
- .DS_Store
@@ -1,90 +0,0 @@
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.
@@ -1,77 +0,0 @@
1
- # Ideogram V3 Python SDK for RunAPI
2
-
3
- The Ideogram V3 Python SDK is the language-specific package for Ideogram V3 on
4
- RunAPI. Use it for text-to-image, edit-image, remix-image, and reframe-image
5
- flows when your application needs JSON request bodies, task status lookup, and
6
- consistent RunAPI errors in Python.
7
-
8
- For model details, use https://runapi.ai/models/ideogram-v3; for API reference,
9
- use https://runapi.ai/docs#ideogram-v3; for SDK docs, use
10
- https://runapi.ai/docs#sdk-ideogram-v3.
11
-
12
- ## Install
13
-
14
- ```bash
15
- pip install runapi-ideogram-v3
16
- ```
17
-
18
- ## Quick start
19
-
20
- ```python
21
- from runapi.ideogram_v3 import IdeogramV3Client
22
-
23
- client = IdeogramV3Client() # reads RUNAPI_API_KEY, or pass api_key="sk-..."
24
-
25
- task = client.text_to_image.create(
26
- model="ideogram-v3-text-to-image",
27
- prompt="A cinematic lakeside at twilight",
28
- aspect_ratio="16:9",
29
- rendering_speed="quality",
30
- )
31
- status = client.text_to_image.get(task.id)
32
-
33
- edit = client.edit_image.create(
34
- model="ideogram-v3-edit",
35
- prompt="Replace the sky with aurora",
36
- source_image_url="https://example.com/source.jpg",
37
- mask_url="https://example.com/mask.png",
38
- )
39
- ```
40
-
41
- Use `create` to submit a task and return quickly, `get` to fetch the latest task
42
- state, and `run` to create and poll until completion:
43
-
44
- ```python
45
- result = client.text_to_image.run(
46
- model="ideogram-v3-text-to-image",
47
- prompt="A serene mountain lake at dawn",
48
- )
49
- print(result.images[0].url)
50
- ```
51
-
52
- In web request handlers, prefer `create` plus webhook or later `get` polling so a
53
- worker is not held open.
54
-
55
- RunAPI-generated file URLs are temporary. Download and store generated images in
56
- your own durable storage within 7 days; do not treat returned URLs as long-term
57
- assets.
58
-
59
- ## Language notes
60
-
61
- Pass parameters as keyword arguments and catch the `runapi.ideogram_v3` error
62
- classes when building image jobs or scripts. The available resources are
63
- `text_to_image`, `edit_image`, `remix_image`, and `reframe_image`. Keep
64
- `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys
65
- or callback secrets.
66
-
67
- ## Links
68
-
69
- - Model page: https://runapi.ai/models/ideogram-v3
70
- - SDK docs: https://runapi.ai/docs#sdk-ideogram-v3
71
- - Product docs: https://runapi.ai/docs#ideogram-v3
72
- - Pricing and rate limits: https://runapi.ai/models/ideogram-v3
73
- - Full catalog: https://runapi.ai/models
74
-
75
- ## License
76
-
77
- Licensed under the Apache License, Version 2.0.
@@ -1,30 +0,0 @@
1
- [build-system]
2
- requires = ["hatchling"]
3
- build-backend = "hatchling.build"
4
-
5
- [project]
6
- name = "runapi-ideogram-v3"
7
- version = "0.1.0"
8
- description = "Ideogram V3 image generation client for RunAPI"
9
- readme = "README.md"
10
- requires-python = ">=3.9"
11
- license = "Apache-2.0"
12
- authors = [{ name = "RunAPI", email = "contact@runapi.ai" }]
13
- keywords = ["runapi", "ideogram-v3", "text-to-image", "edit-image", "ai", "sdk"]
14
- dependencies = ["runapi-core"]
15
-
16
- [project.urls]
17
- Homepage = "https://runapi.ai/models/ideogram-v3"
18
- Documentation = "https://runapi.ai/docs#sdk-ideogram-v3"
19
-
20
- [tool.hatch.build.targets.wheel]
21
- packages = ["src/runapi"]
22
-
23
- [tool.uv]
24
- package = true
25
-
26
- [tool.uv.sources]
27
- runapi-core = { path = "../runapi-core", editable = true }
28
-
29
- [dependency-groups]
30
- dev = ["pytest>=8"]
@@ -1,19 +0,0 @@
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}")