runapi-seedream 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
+ """Seedream 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 SeedreamClient
14
+
15
+ __all__ = [
16
+ "SeedreamClient",
17
+ "AuthenticationError",
18
+ "RateLimitError",
19
+ "InsufficientCreditsError",
20
+ "NotFoundError",
21
+ "ValidationError",
22
+ "TaskFailedError",
23
+ "TaskTimeoutError",
24
+ ]
@@ -0,0 +1,29 @@
1
+ """Seedream 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 SeedreamClient:
14
+ """Seedream text-to-image and edit-image client.
15
+
16
+ Example::
17
+
18
+ client = SeedreamClient(api_key="sk-...")
19
+ result = client.text_to_image.run(
20
+ model="seedream-v4-text-to-image", prompt="A neon city street"
21
+ )
22
+ """
23
+
24
+ def __init__(self, api_key: Optional[str] = None, **options: Any) -> None:
25
+ resolved_api_key = resolve_api_key(api_key)
26
+ client_options = ClientOptions(api_key=resolved_api_key, **options)
27
+ http = client_options.http_client or HttpClient(client_options)
28
+ self.text_to_image = TextToImage(http)
29
+ self.edit_image = EditImage(http)
@@ -0,0 +1,117 @@
1
+ # Code generated by SdkContractGenerator. DO NOT EDIT.
2
+
3
+ CONTRACT = {
4
+ "edit-image": {
5
+ "models": ["seedream-4.5-edit", "seedream-5-lite-edit", "seedream-v4-edit"],
6
+ "fields_by_model": {
7
+ "seedream-4.5-edit": {
8
+ "aspect_ratio": {
9
+ "enum": ["1:1", "4:3", "3:4", "16:9", "9:16", "2:3", "3:2", "21:9"],
10
+ "required": True
11
+ },
12
+ "output_count": {
13
+ "type": "integer"
14
+ },
15
+ "output_quality": {
16
+ "enum": ["basic", "high"],
17
+ "required": True
18
+ },
19
+ "seed": {
20
+ "type": "integer"
21
+ },
22
+ "source_image_urls": {
23
+ "required": True
24
+ }
25
+ },
26
+ "seedream-5-lite-edit": {
27
+ "aspect_ratio": {
28
+ "enum": ["1:1", "4:3", "3:4", "16:9", "9:16", "2:3", "3:2", "21:9"],
29
+ "required": True
30
+ },
31
+ "output_count": {
32
+ "type": "integer"
33
+ },
34
+ "output_quality": {
35
+ "enum": ["basic", "high"],
36
+ "required": True
37
+ },
38
+ "seed": {
39
+ "type": "integer"
40
+ },
41
+ "source_image_urls": {
42
+ "required": True
43
+ }
44
+ },
45
+ "seedream-v4-edit": {
46
+ "aspect_ratio": {
47
+ "enum": ["1:1", "4:3", "3:4", "3:2", "2:3", "16:9", "9:16", "21:9"]
48
+ },
49
+ "output_count": {
50
+ "enum": [1, 2, 3, 4, 5, 6],
51
+ "type": "integer"
52
+ },
53
+ "output_resolution": {
54
+ "enum": ["1k", "2k", "4k"]
55
+ },
56
+ "seed": {
57
+ "type": "integer"
58
+ },
59
+ "source_image_urls": {
60
+ "required": True
61
+ }
62
+ }
63
+ }
64
+ },
65
+ "text-to-image": {
66
+ "models": ["seedream-4.5-text-to-image", "seedream-5-lite-text-to-image", "seedream-v4-text-to-image"],
67
+ "fields_by_model": {
68
+ "seedream-4.5-text-to-image": {
69
+ "aspect_ratio": {
70
+ "enum": ["1:1", "4:3", "3:4", "16:9", "9:16", "2:3", "3:2", "21:9"],
71
+ "required": True
72
+ },
73
+ "output_count": {
74
+ "type": "integer"
75
+ },
76
+ "output_quality": {
77
+ "enum": ["basic", "high"],
78
+ "required": True
79
+ },
80
+ "seed": {
81
+ "type": "integer"
82
+ }
83
+ },
84
+ "seedream-5-lite-text-to-image": {
85
+ "aspect_ratio": {
86
+ "enum": ["1:1", "4:3", "3:4", "16:9", "9:16", "2:3", "3:2", "21:9"],
87
+ "required": True
88
+ },
89
+ "output_count": {
90
+ "type": "integer"
91
+ },
92
+ "output_quality": {
93
+ "enum": ["basic", "high"],
94
+ "required": True
95
+ },
96
+ "seed": {
97
+ "type": "integer"
98
+ }
99
+ },
100
+ "seedream-v4-text-to-image": {
101
+ "aspect_ratio": {
102
+ "enum": ["1:1", "4:3", "3:4", "3:2", "2:3", "16:9", "9:16", "21:9"]
103
+ },
104
+ "output_count": {
105
+ "enum": [1, 2, 3, 4, 5, 6],
106
+ "type": "integer"
107
+ },
108
+ "output_resolution": {
109
+ "enum": ["1k", "2k", "4k"]
110
+ },
111
+ "seed": {
112
+ "type": "integer"
113
+ }
114
+ }
115
+ }
116
+ }
117
+ }
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,92 @@
1
+ """Seedream 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 ..contract_gen import CONTRACT
10
+ from ..types import (
11
+ LITE_MODELS,
12
+ V4_MODELS,
13
+ CompletedEditImageResponse,
14
+ EditImageResponse,
15
+ )
16
+
17
+
18
+ class EditImage(Resource):
19
+ """Edit images from a prompt and source images with Seedream models."""
20
+
21
+ ENDPOINT = "/api/v1/seedream/edit_image"
22
+
23
+ RESPONSE_CLASS = EditImageResponse
24
+ COMPLETED_RESPONSE_CLASS = CompletedEditImageResponse
25
+
26
+ PROMPT_MAX_LENGTH = 3000
27
+ V4_PROMPT_MAX_LENGTH = 5000
28
+ PROMPT_MIN_LENGTH_LITE = 3
29
+
30
+ def run(self, **params: Any) -> Any:
31
+ """Edit an image and poll until it completes.
32
+
33
+ Args:
34
+ **params: image edit parameters (model, ...).
35
+
36
+ Returns:
37
+ The completed (narrowed) image edit 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 an image editing task and return immediately with an id.
44
+
45
+ Args:
46
+ **params: image edit parameters (model, ...).
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 an image editing task.
57
+
58
+ Args:
59
+ id: The task id returned by ``create``.
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
+ self._validate_contract(CONTRACT["edit-image"], params)
68
+
69
+ model = params.get("model")
70
+
71
+ prompt = params.get("prompt")
72
+ if not (isinstance(prompt, str) and prompt):
73
+ raise ValidationError("prompt is required")
74
+ max_length = self.V4_PROMPT_MAX_LENGTH if model in V4_MODELS else self.PROMPT_MAX_LENGTH
75
+ if len(prompt) > max_length:
76
+ raise ValidationError(f"prompt must be at most {max_length} characters")
77
+ if model in LITE_MODELS and len(prompt) < self.PROMPT_MIN_LENGTH_LITE:
78
+ raise ValidationError(
79
+ f"prompt must be between {self.PROMPT_MIN_LENGTH_LITE} and {self.PROMPT_MAX_LENGTH} characters"
80
+ )
81
+
82
+ if model in V4_MODELS:
83
+ self._validate_integer(params, "seed")
84
+
85
+ @staticmethod
86
+ def _validate_integer(params: Dict[str, Any], key: str) -> None:
87
+ value = params.get(key)
88
+ if value is None:
89
+ return
90
+ if isinstance(value, int) and not isinstance(value, bool):
91
+ return
92
+ raise ValidationError(f"{key} must be an integer")
@@ -0,0 +1,104 @@
1
+ """Seedream 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 ..contract_gen import CONTRACT
10
+ from ..types import (
11
+ LITE_MODELS,
12
+ V4_MODELS,
13
+ CompletedTextToImageResponse,
14
+ TextToImageResponse,
15
+ )
16
+
17
+
18
+ class TextToImage(Resource):
19
+ """Generate images from text prompts with Seedream models."""
20
+
21
+ ENDPOINT = "/api/v1/seedream/text_to_image"
22
+
23
+ RESPONSE_CLASS = TextToImageResponse
24
+ COMPLETED_RESPONSE_CLASS = CompletedTextToImageResponse
25
+
26
+ PROMPT_MAX_LENGTH = 3000
27
+ V4_PROMPT_MAX_LENGTH = 5000
28
+ PROMPT_MIN_LENGTH_LITE = 3
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, ...).
35
+
36
+ Returns:
37
+ The completed (narrowed) text-to-image 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, ...).
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 returned by ``create``.
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
+ self._validate_contract(CONTRACT["text-to-image"], params)
68
+
69
+ model = params.get("model")
70
+
71
+ prompt = params.get("prompt")
72
+ if not (isinstance(prompt, str) and prompt):
73
+ raise ValidationError("prompt is required")
74
+ max_length = self.V4_PROMPT_MAX_LENGTH if model in V4_MODELS else self.PROMPT_MAX_LENGTH
75
+ if len(prompt) > max_length:
76
+ raise ValidationError(f"prompt must be at most {max_length} characters")
77
+ if model in LITE_MODELS and len(prompt) < self.PROMPT_MIN_LENGTH_LITE:
78
+ raise ValidationError(
79
+ f"prompt must be between {self.PROMPT_MIN_LENGTH_LITE} and {self.PROMPT_MAX_LENGTH} characters"
80
+ )
81
+
82
+ if model in V4_MODELS:
83
+ self._validate_integer(params, "seed")
84
+
85
+ if self._field_present(params, "source_image_urls"):
86
+ raise ValidationError(f"source_image_urls is not supported for {model}")
87
+
88
+ @staticmethod
89
+ def _field_present(params: Dict[str, Any], key: str) -> bool:
90
+ value = params.get(key)
91
+ if value is None:
92
+ return False
93
+ if hasattr(value, "__len__"):
94
+ return len(value) > 0
95
+ return True
96
+
97
+ @staticmethod
98
+ def _validate_integer(params: Dict[str, Any], key: str) -> None:
99
+ value = params.get(key)
100
+ if value is None:
101
+ return
102
+ if isinstance(value, int) and not isinstance(value, bool):
103
+ return
104
+ raise ValidationError(f"{key} must be an integer")
@@ -0,0 +1,36 @@
1
+ """Seedream model lists, enums, and response models."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from runapi.core import BaseModel, TaskResponse, optional, required
6
+
7
+ # Model groupings used by bespoke prompt-length selection (per-model rule the
8
+ # contract cannot express). Model membership and field enums are validated by
9
+ # the generated CONTRACT.
10
+ LITE_MODELS = ["seedream-5-lite-text-to-image", "seedream-5-lite-edit"]
11
+ V4_MODELS = ["seedream-v4-text-to-image", "seedream-v4-edit"]
12
+
13
+
14
+ class Image(BaseModel):
15
+ url = optional(str)
16
+
17
+
18
+ class TextToImageResponse(TaskResponse):
19
+ """Seedream image task status response."""
20
+
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,78 @@
1
+ Metadata-Version: 2.4
2
+ Name: runapi-seedream
3
+ Version: 0.1.0
4
+ Summary: Seedream text-to-image and edit-image client for RunAPI
5
+ Project-URL: Homepage, https://runapi.ai/models/seedream
6
+ Project-URL: Documentation, https://runapi.ai/docs#sdk-seedream
7
+ Author-email: RunAPI <contact@runapi.ai>
8
+ License-Expression: Apache-2.0
9
+ Keywords: ai,edit-image,runapi,sdk,seedream,text-to-image
10
+ Requires-Python: >=3.9
11
+ Requires-Dist: runapi-core
12
+ Description-Content-Type: text/markdown
13
+
14
+ # Seedream API Python SDK for RunAPI
15
+
16
+ The seedream api Python SDK is the language-specific package for Seedream on RunAPI. Use this seedream api package for text-to-image, image editing, and creative production flows when your application needs JSON request bodies, task status lookup, and consistent RunAPI errors in Python.
17
+
18
+ This seedream api README is the Python package guide inside the public `seedream-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/seedream; for API reference, use https://runapi.ai/docs#seedream; for SDK docs, use https://runapi.ai/docs#sdk-seedream.
19
+
20
+ ## Install
21
+
22
+ ```bash
23
+ pip install runapi-seedream
24
+ ```
25
+
26
+ ## Quick start
27
+
28
+ ```python
29
+ from runapi.seedream import SeedreamClient
30
+
31
+ client = SeedreamClient() # reads RUNAPI_API_KEY, or pass api_key="sk-..."
32
+
33
+ task = client.text_to_image.create(
34
+ model="seedream-v4-text-to-image",
35
+ prompt="A precise product render of a glass teapot on white marble",
36
+ aspect_ratio="16:9",
37
+ output_resolution="2k",
38
+ output_count=3,
39
+ )
40
+ status = client.text_to_image.get(task.id)
41
+
42
+ edit = client.edit_image.create(
43
+ model="seedream-v4-edit",
44
+ prompt="Make it golden hour",
45
+ source_image_urls=["https://example.com/source.jpg"],
46
+ )
47
+ ```
48
+
49
+ Use `create` to submit a task and return quickly, `get` to fetch the latest task state, and `run` when a script should create and poll until completion:
50
+
51
+ ```python
52
+ result = client.text_to_image.run(
53
+ model="seedream-v4-text-to-image",
54
+ prompt="A serene mountain lake at dawn",
55
+ )
56
+ print(result.images[0].url)
57
+ ```
58
+
59
+ In web request handlers, prefer `create` plus webhook or later `get` polling so a worker is not held open.
60
+
61
+ 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.
62
+
63
+ ## Language notes
64
+
65
+ Pass parameters as keyword arguments and catch the `runapi.seedream` error classes when building image jobs or scripts. The available resources are `text_to_image` for text models and `edit_image` for editing models. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
66
+
67
+ ## Links
68
+
69
+ - Model page: https://runapi.ai/models/seedream
70
+ - SDK docs: https://runapi.ai/docs#sdk-seedream
71
+ - Product docs: https://runapi.ai/docs#seedream
72
+ - Pricing and rate limits: https://runapi.ai/models/seedream/v4-text-to-image
73
+ - Full catalog: https://runapi.ai/models
74
+ - Repository: https://github.com/runapi-ai/seedream-sdk
75
+
76
+ ## License
77
+
78
+ Licensed under the Apache License, Version 2.0.
@@ -0,0 +1,11 @@
1
+ runapi/seedream/__init__.py,sha256=BVqXWOILYMAKbUM-7nwcZiVieuX-V7R4V5tdMwLnNm0,466
2
+ runapi/seedream/client.py,sha256=QppM6kYDO2FJbQ8NTte8_Vwk1sgCQ-r8RchjY8SmIrA,903
3
+ runapi/seedream/contract_gen.py,sha256=oHsyW03OhP-WyuiP5MTBhwkxn9kNhvDwwj68aNWRTlI,3914
4
+ runapi/seedream/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ runapi/seedream/types.py,sha256=XmnQuhBuK7wT-FIpxzdrsxds1OK1l5gzftK1CYI1Obo,1050
6
+ runapi/seedream/resources/__init__.py,sha256=cWTZRb2Hewznm9agkhjkcKjEPbJO2YaQOW1fuixLjtw,113
7
+ runapi/seedream/resources/edit_image.py,sha256=RL4iWEB7zIwh06zNm7TpGksGa4MbL4Np2ohW9gRtmtE,2894
8
+ runapi/seedream/resources/text_to_image.py,sha256=bruWUZQIrpmLnZGhDrO8wi3cNnjGDw552sW9IwG1uk0,3331
9
+ runapi_seedream-0.1.0.dist-info/METADATA,sha256=MeQgXNbtgghXIFJLYu6idFpAZ9ilR4IBg5dYuhlgnVg,3106
10
+ runapi_seedream-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
11
+ runapi_seedream-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