runapi-gpt-image 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,24 @@
1
+ """GPT Image client for RunAPI."""
2
+
3
+ from runapi.core import (
4
+ AuthenticationError,
5
+ InsufficientCreditsError,
6
+ NotFoundError,
7
+ RateLimitError,
8
+ TaskFailedError,
9
+ TaskTimeoutError,
10
+ ValidationError,
11
+ )
12
+
13
+ from .client import GptImageClient
14
+
15
+ __all__ = [
16
+ "GptImageClient",
17
+ "AuthenticationError",
18
+ "RateLimitError",
19
+ "InsufficientCreditsError",
20
+ "NotFoundError",
21
+ "ValidationError",
22
+ "TaskFailedError",
23
+ "TaskTimeoutError",
24
+ ]
@@ -0,0 +1,30 @@
1
+ """GPT Image client."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Optional
6
+
7
+ from runapi.core import ClientOptions, HttpClient, resolve_api_key
8
+
9
+ from .resources.edit_image import EditImage
10
+ from .resources.text_to_image import TextToImage
11
+
12
+
13
+ class GptImageClient:
14
+ """GPT Image text-to-image and edit-image client.
15
+
16
+ Example::
17
+
18
+ client = GptImageClient(api_key="sk-...")
19
+ result = client.text_to_image.run(
20
+ model="gpt-image-1.5", prompt="A futuristic cityscape",
21
+ aspect_ratio="1:1", quality="high",
22
+ )
23
+ """
24
+
25
+ def __init__(self, api_key: Optional[str] = None, **options: Any) -> None:
26
+ resolved_api_key = resolve_api_key(api_key)
27
+ client_options = ClientOptions(api_key=resolved_api_key, **options)
28
+ http = client_options.http_client or HttpClient(client_options)
29
+ self.text_to_image = TextToImage(http)
30
+ self.edit_image = EditImage(http)
File without changes
@@ -0,0 +1,4 @@
1
+ from .edit_image import EditImage
2
+ from .text_to_image import TextToImage
3
+
4
+ __all__ = ["TextToImage", "EditImage"]
@@ -0,0 +1,81 @@
1
+ """GPT Image edit-image resource."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Dict
6
+
7
+ from runapi.core import Resource, ValidationError
8
+
9
+ from ..types import (
10
+ ASPECT_RATIOS,
11
+ EDIT_MODELS,
12
+ QUALITY_VALUES,
13
+ CompletedEditImageResponse,
14
+ EditImageResponse,
15
+ )
16
+
17
+
18
+ class EditImage(Resource):
19
+ """Edit images from a prompt and source images with GPT Image models."""
20
+
21
+ ENDPOINT = "/api/v1/gpt_image/edit_image"
22
+
23
+ RESPONSE_CLASS = EditImageResponse
24
+ COMPLETED_RESPONSE_CLASS = CompletedEditImageResponse
25
+
26
+ def run(self, **params: Any) -> Any:
27
+ """Create an edit-image task and poll until it completes.
28
+
29
+ Args:
30
+ **params: Edit-image parameters (model, prompt, ...).
31
+
32
+ Returns:
33
+ The completed edit-image response.
34
+ """
35
+ task = self.create(**params)
36
+ return self._poll_until_complete(lambda: self.get(task.id))
37
+
38
+ def create(self, **params: Any) -> Any:
39
+ """Create an edit-image task and return immediately with an id.
40
+
41
+ Args:
42
+ **params: Edit-image parameters (model, prompt, ...).
43
+
44
+ Returns:
45
+ The task creation result with an id.
46
+ """
47
+ compacted = self._compact_params(params)
48
+ self._validate_params(compacted)
49
+ return self._request("post", self.ENDPOINT, body=compacted)
50
+
51
+ def get(self, id: str) -> Any:
52
+ """Fetch the current status of an edit-image task.
53
+
54
+ Args:
55
+ id: Task id.
56
+
57
+ Returns:
58
+ The current edit-image status.
59
+ """
60
+ return self._request("get", f"{self.ENDPOINT}/{id}")
61
+
62
+ def _validate_params(self, params: Dict[str, Any]) -> None:
63
+ if not params.get("model"):
64
+ raise ValidationError("model is required")
65
+ if not params.get("prompt"):
66
+ raise ValidationError("prompt is required")
67
+
68
+ model = params.get("model")
69
+ if model not in EDIT_MODELS:
70
+ raise ValidationError(f"Invalid model: {model}. Must be: {', '.join(EDIT_MODELS)}")
71
+
72
+ urls = params.get("source_image_urls")
73
+ if urls is None or (hasattr(urls, "__len__") and len(urls) == 0):
74
+ raise ValidationError("source_image_urls is required for image editing")
75
+
76
+ if not params.get("aspect_ratio"):
77
+ raise ValidationError("aspect_ratio is required")
78
+ self._validate_optional(params, "aspect_ratio", ASPECT_RATIOS)
79
+ if not params.get("quality"):
80
+ raise ValidationError("quality is required")
81
+ self._validate_optional(params, "quality", QUALITY_VALUES)
@@ -0,0 +1,77 @@
1
+ """GPT Image text-to-image resource."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Dict
6
+
7
+ from runapi.core import Resource, ValidationError
8
+
9
+ from ..types import (
10
+ ASPECT_RATIOS,
11
+ GENERATION_MODELS,
12
+ QUALITY_VALUES,
13
+ CompletedTextToImageResponse,
14
+ TextToImageResponse,
15
+ )
16
+
17
+
18
+ class TextToImage(Resource):
19
+ """Generate images from text prompts with GPT Image models."""
20
+
21
+ ENDPOINT = "/api/v1/gpt_image/text_to_image"
22
+
23
+ RESPONSE_CLASS = TextToImageResponse
24
+ COMPLETED_RESPONSE_CLASS = CompletedTextToImageResponse
25
+
26
+ def run(self, **params: Any) -> Any:
27
+ """Create a text-to-image task and poll until it completes.
28
+
29
+ Args:
30
+ **params: Text-to-image parameters (model, prompt, ...).
31
+
32
+ Returns:
33
+ The completed text-to-image response.
34
+ """
35
+ task = self.create(**params)
36
+ return self._poll_until_complete(lambda: self.get(task.id))
37
+
38
+ def create(self, **params: Any) -> Any:
39
+ """Create a text-to-image task and return immediately with an id.
40
+
41
+ Args:
42
+ **params: Text-to-image parameters (model, prompt, ...).
43
+
44
+ Returns:
45
+ The task creation result with an id.
46
+ """
47
+ compacted = self._compact_params(params)
48
+ self._validate_params(compacted)
49
+ return self._request("post", self.ENDPOINT, body=compacted)
50
+
51
+ def get(self, id: str) -> Any:
52
+ """Fetch the current status of a text-to-image task.
53
+
54
+ Args:
55
+ id: Task id.
56
+
57
+ Returns:
58
+ The current text-to-image status.
59
+ """
60
+ return self._request("get", f"{self.ENDPOINT}/{id}")
61
+
62
+ def _validate_params(self, params: Dict[str, Any]) -> None:
63
+ if not params.get("model"):
64
+ raise ValidationError("model is required")
65
+ if not params.get("prompt"):
66
+ raise ValidationError("prompt is required")
67
+
68
+ model = params.get("model")
69
+ if model not in GENERATION_MODELS:
70
+ raise ValidationError(f"Invalid model: {model}. Must be: {', '.join(GENERATION_MODELS)}")
71
+
72
+ if not params.get("aspect_ratio"):
73
+ raise ValidationError("aspect_ratio is required")
74
+ self._validate_optional(params, "aspect_ratio", ASPECT_RATIOS)
75
+ if not params.get("quality"):
76
+ raise ValidationError("quality is required")
77
+ self._validate_optional(params, "quality", QUALITY_VALUES)
@@ -0,0 +1,36 @@
1
+ """GPT Image model lists, enums, and response models."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from runapi.core import BaseModel, TaskResponse, optional, required
6
+
7
+ MODELS = ["gpt-image-1.5"]
8
+ GENERATION_MODELS = MODELS
9
+ EDIT_MODELS = MODELS
10
+
11
+ ASPECT_RATIOS = ["1:1", "2:3", "3:2"]
12
+ QUALITY_VALUES = ["medium", "high"]
13
+
14
+
15
+ class Image(BaseModel):
16
+ url = optional(str)
17
+
18
+
19
+ class TextToImageResponse(TaskResponse):
20
+ """Task status/result for GPT Image text-to-image."""
21
+ id = required(str)
22
+ status = optional(str, enum=lambda: TaskResponse.Status.ALL)
23
+ images = optional([lambda: Image])
24
+ error = optional(str)
25
+
26
+
27
+ EditImageResponse = TextToImageResponse
28
+
29
+
30
+ class CompletedTextToImageResponse(TextToImageResponse):
31
+ """Narrowed response from ``run()`` once polling observes completion."""
32
+
33
+ images = required([lambda: Image])
34
+
35
+
36
+ CompletedEditImageResponse = CompletedTextToImageResponse
@@ -0,0 +1,90 @@
1
+ Metadata-Version: 2.4
2
+ Name: runapi-gpt-image
3
+ Version: 0.1.0
4
+ Summary: GPT Image text-to-image and edit-image client for RunAPI
5
+ Project-URL: Homepage, https://runapi.ai/models/gpt-image
6
+ Project-URL: Documentation, https://runapi.ai/docs#sdk-gpt-image
7
+ Author-email: RunAPI <contact@runapi.ai>
8
+ License-Expression: Apache-2.0
9
+ Keywords: ai,edit-image,gpt-image,runapi,sdk,text-to-image
10
+ Requires-Python: >=3.9
11
+ Requires-Dist: runapi-core
12
+ Description-Content-Type: text/markdown
13
+
14
+ # GPT Image Python SDK for RunAPI
15
+
16
+ The GPT Image Python SDK is the language-specific package for GPT Image on
17
+ RunAPI. Use it for text-to-image and edit-image flows when your application needs
18
+ JSON request bodies, task status lookup, and consistent RunAPI errors in Python.
19
+
20
+ For model details, use https://runapi.ai/models/gpt-image; for API reference, use
21
+ https://runapi.ai/docs#gpt-image; for SDK docs, use https://runapi.ai/docs#sdk-gpt-image.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ pip install runapi-gpt-image
27
+ ```
28
+
29
+ ## Quick start
30
+
31
+ ```python
32
+ from runapi.gpt_image import GptImageClient
33
+
34
+ client = GptImageClient() # reads RUNAPI_API_KEY, or pass api_key="sk-..."
35
+
36
+ task = client.text_to_image.create(
37
+ model="gpt-image-1.5",
38
+ prompt="A futuristic cityscape at dusk, cinematic",
39
+ aspect_ratio="1:1",
40
+ quality="high",
41
+ )
42
+ status = client.text_to_image.get(task.id)
43
+
44
+ edit = client.edit_image.create(
45
+ model="gpt-image-1.5",
46
+ prompt="Transform into an oil painting",
47
+ source_image_urls=["https://example.com/source.jpg"],
48
+ aspect_ratio="1:1",
49
+ quality="high",
50
+ )
51
+ ```
52
+
53
+ Use `create` to submit a task and return quickly, `get` to fetch the latest task
54
+ state, and `run` to create and poll until completion:
55
+
56
+ ```python
57
+ result = client.text_to_image.run(
58
+ model="gpt-image-1.5",
59
+ prompt="A serene mountain lake at dawn",
60
+ aspect_ratio="3:2",
61
+ quality="high",
62
+ )
63
+ print(result.images[0].url)
64
+ ```
65
+
66
+ In web request handlers, prefer `create` plus webhook or later `get` polling so a
67
+ worker is not held open.
68
+
69
+ RunAPI-generated file URLs are temporary. Download and store generated images in
70
+ your own durable storage within 7 days; do not treat returned URLs as long-term
71
+ assets.
72
+
73
+ ## Language notes
74
+
75
+ Pass parameters as keyword arguments and catch the `runapi.gpt_image` error
76
+ classes when building image jobs or scripts. The available resources are
77
+ `text_to_image` and `edit_image`. Keep `RUNAPI_API_KEY` in the environment or
78
+ your secret manager; never commit API keys or callback secrets.
79
+
80
+ ## Links
81
+
82
+ - Model page: https://runapi.ai/models/gpt-image
83
+ - SDK docs: https://runapi.ai/docs#sdk-gpt-image
84
+ - Product docs: https://runapi.ai/docs#gpt-image
85
+ - Pricing and rate limits: https://runapi.ai/models/gpt-image
86
+ - Full catalog: https://runapi.ai/models
87
+
88
+ ## License
89
+
90
+ Licensed under the Apache License, Version 2.0.
@@ -0,0 +1,10 @@
1
+ runapi/gpt_image/__init__.py,sha256=wTzjjdwD4O_XtsOQ--K_cUEejxNrP5-J2ZFsC3x-VrE,467
2
+ runapi/gpt_image/client.py,sha256=EBENbQa5yoTterpZTS0T0DhyxMMR08jRkbv7GuXJr7A,946
3
+ runapi/gpt_image/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ runapi/gpt_image/types.py,sha256=qarlZACOYKDbLc7v1BLvQ_428ba41Ya2bmXa4meOcoc,895
5
+ runapi/gpt_image/resources/__init__.py,sha256=cWTZRb2Hewznm9agkhjkcKjEPbJO2YaQOW1fuixLjtw,113
6
+ runapi/gpt_image/resources/edit_image.py,sha256=EHhHplI805A0Ma7NtEzpAFuoCZQiUdpVCyMAU4OQRN8,2581
7
+ runapi/gpt_image/resources/text_to_image.py,sha256=PAPkVKOcCvsiDIJwkErlB9eGiLDoOuTCyaX7a4LjnkU,2416
8
+ runapi_gpt_image-0.1.0.dist-info/METADATA,sha256=jmmlwhDVWT-g7rxsjzJA2nQHsGiheG5fXHyrqzs7YMo,2785
9
+ runapi_gpt_image-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
10
+ runapi_gpt_image-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.30.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any