spicyapi 0.1.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,7 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .ruff_cache/
spicyapi-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SpicyAPI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,159 @@
1
+ Metadata-Version: 2.5
2
+ Name: spicyapi
3
+ Version: 0.1.0
4
+ Summary: Official Python client for SpicyAPI — image, video and text generation behind one API.
5
+ Project-URL: Homepage, https://spicyapi.ai
6
+ Project-URL: Documentation, https://docs.spicyapi.ai
7
+ Project-URL: Source, https://github.com/Spicy-API/spicy-python
8
+ Project-URL: Issues, https://spicyapi.ai/contact
9
+ Author: SpicyAPI
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: ai,api-client,image-generation,spicyapi,video-generation
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Multimedia :: Graphics
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.11
23
+ Description-Content-Type: text/markdown
24
+
25
+ <div align="center">
26
+
27
+ # spicyapi
28
+
29
+ **Official Python SDK for [SpicyAPI](https://spicyapi.ai)** — image, video and text models behind one API.
30
+
31
+ [Get a key](https://spicyapi.ai) · [Models](https://spicyapi.ai/models) · [Docs](https://docs.spicyapi.ai) · [Status](https://status.spicyapi.ai)
32
+
33
+ </div>
34
+
35
+ ---
36
+
37
+ One endpoint in front of 83 model families across 121 callable endpoints, billed in USD per request
38
+ rather than in credits. Media generation is asynchronous and quotable before you spend; text models
39
+ speak the OpenAI, Anthropic and Gemini wire formats.
40
+
41
+ ```bash
42
+ pip install spicyapi
43
+ ```
44
+
45
+ Requires Python 3.11+. **No runtime dependencies**: this package goes into your dependency tree, and
46
+ every constraint it adds is one more chance of a conflict.
47
+
48
+ ## Generate something
49
+
50
+ ```python
51
+ import os, uuid
52
+ from spicyapi import SpicyClient, output_assets
53
+
54
+ client = SpicyClient() # reads SPICY_API_KEY from the environment
55
+
56
+ model = client.get_model("MODEL_ID_FROM_CATALOG") # copy a real id from list_models()
57
+ quote = client.quote_task(model=model["model"], input_data={"prompt": "a lantern in fog"})
58
+ print(quote["estimatedCost"], quote["maxCharge"]) # decide before you spend
59
+
60
+ task = client.create_task(
61
+ model=model["model"],
62
+ input_data={"prompt": "a lantern in fog"},
63
+ idempotency_key=str(uuid.uuid4()),
64
+ quote_id=quote["quoteId"],
65
+ expected_cost=quote["estimatedCost"],
66
+ )
67
+ final = client.wait_for_terminal(task["taskId"])
68
+ for asset in output_assets(final): # module-level helper, not a method
69
+ print(asset["url"])
70
+ ```
71
+
72
+ Build the `input` from that model's own `inputSchema` — every model has different fields, and
73
+ `list_models(include_schema=True)` returns them.
74
+
75
+ ## Start from a local file
76
+
77
+ Image-to-video, face swap and image editing all need your material on our side first. Upload returns
78
+ a `spicy://` URI; that is what goes into `input`.
79
+
80
+ ```python
81
+ uploaded = client.upload_file("/path/to/reference.png")
82
+ task = client.create_task(
83
+ model="MODEL_ID_FROM_CATALOG",
84
+ input_data={"image": uploaded["uri"], "prompt": "slow dolly in"},
85
+ idempotency_key=str(uuid.uuid4()),
86
+ )
87
+ ```
88
+
89
+ ## Webhooks
90
+
91
+ `verify_webhook` is a module-level function, so a request handler can use it without building a
92
+ client. It compares in constant time and checks the timestamp only after the signature is valid.
93
+
94
+ ```python
95
+ from spicyapi import verify_webhook
96
+
97
+ delivery = verify_webhook(
98
+ raw_body=request.body, # the exact bytes, before any parsing
99
+ signature=request.headers["X-Webhook-Signature"],
100
+ timestamp=request.headers["X-Webhook-Timestamp"],
101
+ payload_version=request.headers["X-Webhook-Payload-Version"],
102
+ secret=os.environ["SPICY_WEBHOOK_SECRET"],
103
+ )
104
+ ```
105
+
106
+ Verify the raw bytes. Re-serialising the parsed JSON changes them, and the signature will never match.
107
+
108
+ ## Two things that will save you money
109
+
110
+ **Keep one idempotency key per submission.** Reuse it for every resend of that submission, including
111
+ after a timeout or a dropped connection. A lost response does not prove the task was not created — a
112
+ fresh key turns an unknown outcome into a second paid task.
113
+
114
+ **A task that succeeds is charged, even if the result disappoints.** Quote first when the price
115
+ matters; `quote_task` reserves nothing.
116
+
117
+ ## What this package does not do
118
+
119
+ **Text models.** They speak the OpenAI, Anthropic and Google Gemini wire formats, so the official
120
+ libraries for those already work — point them at `https://api.spicyapi.ai/v1` with the same key.
121
+ Wrapping them here would add nothing.
122
+
123
+ **Browser, mobile and desktop apps.** Never ship this key inside an application: a key compiled into
124
+ a client is a public key. Call from your server, or put
125
+ `@spicyapi/proxy` in front.
126
+
127
+ ## Errors
128
+
129
+ Every failure raises `SpicyApiError` with `status`, `code`, `request_id` and `retry_after_seconds`.
130
+ Branch on `code`, never on the message text — messages are translated, codes are not.
131
+
132
+ `503` is shared by three different business codes, so reading the HTTP status alone is not enough:
133
+
134
+ | code | meaning | what to do |
135
+ | --- | --- | --- |
136
+ | `40003` | uploaded bytes do not match their ticket | upload again |
137
+ | `40004` | no deployment serves that parameter combination | change the parameter named in the message |
138
+ | `40901` | the price moved before the task was created | quote again, keep the same idempotency key |
139
+ | `503` | a dependency is briefly unavailable | back off by `Retry-After` |
140
+ | `50301` | the model has no usable deployment or price right now | do not hammer; refresh the catalogue |
141
+ | `50302` | a synchronous generation failed upstream and was refunded | retry with a **new** idempotency key |
142
+
143
+ `err.recovery` carries the same guidance at runtime.
144
+
145
+ ## Links
146
+
147
+ - [Documentation](https://docs.spicyapi.ai)
148
+ - [API reference](https://docs.spicyapi.ai/docs/api-reference)
149
+ - [Source](https://github.com/Spicy-API/spicy-python)
150
+
151
+ ---
152
+
153
+ <div align="center">
154
+ <sub>
155
+
156
+ Also available in [TypeScript](https://github.com/Spicy-API/spicy-sdk) · **Python** · [Go](https://github.com/Spicy-API/spicy-go) · [PHP](https://github.com/Spicy-API/spicy-php) · [Java](https://github.com/Spicy-API/spicy-java)
157
+
158
+ </sub>
159
+ </div>
@@ -0,0 +1,135 @@
1
+ <div align="center">
2
+
3
+ # spicyapi
4
+
5
+ **Official Python SDK for [SpicyAPI](https://spicyapi.ai)** — image, video and text models behind one API.
6
+
7
+ [Get a key](https://spicyapi.ai) · [Models](https://spicyapi.ai/models) · [Docs](https://docs.spicyapi.ai) · [Status](https://status.spicyapi.ai)
8
+
9
+ </div>
10
+
11
+ ---
12
+
13
+ One endpoint in front of 83 model families across 121 callable endpoints, billed in USD per request
14
+ rather than in credits. Media generation is asynchronous and quotable before you spend; text models
15
+ speak the OpenAI, Anthropic and Gemini wire formats.
16
+
17
+ ```bash
18
+ pip install spicyapi
19
+ ```
20
+
21
+ Requires Python 3.11+. **No runtime dependencies**: this package goes into your dependency tree, and
22
+ every constraint it adds is one more chance of a conflict.
23
+
24
+ ## Generate something
25
+
26
+ ```python
27
+ import os, uuid
28
+ from spicyapi import SpicyClient, output_assets
29
+
30
+ client = SpicyClient() # reads SPICY_API_KEY from the environment
31
+
32
+ model = client.get_model("MODEL_ID_FROM_CATALOG") # copy a real id from list_models()
33
+ quote = client.quote_task(model=model["model"], input_data={"prompt": "a lantern in fog"})
34
+ print(quote["estimatedCost"], quote["maxCharge"]) # decide before you spend
35
+
36
+ task = client.create_task(
37
+ model=model["model"],
38
+ input_data={"prompt": "a lantern in fog"},
39
+ idempotency_key=str(uuid.uuid4()),
40
+ quote_id=quote["quoteId"],
41
+ expected_cost=quote["estimatedCost"],
42
+ )
43
+ final = client.wait_for_terminal(task["taskId"])
44
+ for asset in output_assets(final): # module-level helper, not a method
45
+ print(asset["url"])
46
+ ```
47
+
48
+ Build the `input` from that model's own `inputSchema` — every model has different fields, and
49
+ `list_models(include_schema=True)` returns them.
50
+
51
+ ## Start from a local file
52
+
53
+ Image-to-video, face swap and image editing all need your material on our side first. Upload returns
54
+ a `spicy://` URI; that is what goes into `input`.
55
+
56
+ ```python
57
+ uploaded = client.upload_file("/path/to/reference.png")
58
+ task = client.create_task(
59
+ model="MODEL_ID_FROM_CATALOG",
60
+ input_data={"image": uploaded["uri"], "prompt": "slow dolly in"},
61
+ idempotency_key=str(uuid.uuid4()),
62
+ )
63
+ ```
64
+
65
+ ## Webhooks
66
+
67
+ `verify_webhook` is a module-level function, so a request handler can use it without building a
68
+ client. It compares in constant time and checks the timestamp only after the signature is valid.
69
+
70
+ ```python
71
+ from spicyapi import verify_webhook
72
+
73
+ delivery = verify_webhook(
74
+ raw_body=request.body, # the exact bytes, before any parsing
75
+ signature=request.headers["X-Webhook-Signature"],
76
+ timestamp=request.headers["X-Webhook-Timestamp"],
77
+ payload_version=request.headers["X-Webhook-Payload-Version"],
78
+ secret=os.environ["SPICY_WEBHOOK_SECRET"],
79
+ )
80
+ ```
81
+
82
+ Verify the raw bytes. Re-serialising the parsed JSON changes them, and the signature will never match.
83
+
84
+ ## Two things that will save you money
85
+
86
+ **Keep one idempotency key per submission.** Reuse it for every resend of that submission, including
87
+ after a timeout or a dropped connection. A lost response does not prove the task was not created — a
88
+ fresh key turns an unknown outcome into a second paid task.
89
+
90
+ **A task that succeeds is charged, even if the result disappoints.** Quote first when the price
91
+ matters; `quote_task` reserves nothing.
92
+
93
+ ## What this package does not do
94
+
95
+ **Text models.** They speak the OpenAI, Anthropic and Google Gemini wire formats, so the official
96
+ libraries for those already work — point them at `https://api.spicyapi.ai/v1` with the same key.
97
+ Wrapping them here would add nothing.
98
+
99
+ **Browser, mobile and desktop apps.** Never ship this key inside an application: a key compiled into
100
+ a client is a public key. Call from your server, or put
101
+ `@spicyapi/proxy` in front.
102
+
103
+ ## Errors
104
+
105
+ Every failure raises `SpicyApiError` with `status`, `code`, `request_id` and `retry_after_seconds`.
106
+ Branch on `code`, never on the message text — messages are translated, codes are not.
107
+
108
+ `503` is shared by three different business codes, so reading the HTTP status alone is not enough:
109
+
110
+ | code | meaning | what to do |
111
+ | --- | --- | --- |
112
+ | `40003` | uploaded bytes do not match their ticket | upload again |
113
+ | `40004` | no deployment serves that parameter combination | change the parameter named in the message |
114
+ | `40901` | the price moved before the task was created | quote again, keep the same idempotency key |
115
+ | `503` | a dependency is briefly unavailable | back off by `Retry-After` |
116
+ | `50301` | the model has no usable deployment or price right now | do not hammer; refresh the catalogue |
117
+ | `50302` | a synchronous generation failed upstream and was refunded | retry with a **new** idempotency key |
118
+
119
+ `err.recovery` carries the same guidance at runtime.
120
+
121
+ ## Links
122
+
123
+ - [Documentation](https://docs.spicyapi.ai)
124
+ - [API reference](https://docs.spicyapi.ai/docs/api-reference)
125
+ - [Source](https://github.com/Spicy-API/spicy-python)
126
+
127
+ ---
128
+
129
+ <div align="center">
130
+ <sub>
131
+
132
+ Also available in [TypeScript](https://github.com/Spicy-API/spicy-sdk) · **Python** · [Go](https://github.com/Spicy-API/spicy-go) · [PHP](https://github.com/Spicy-API/spicy-php) · [Java](https://github.com/Spicy-API/spicy-java)
133
+
134
+ </sub>
135
+ </div>
@@ -0,0 +1,50 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "spicyapi"
7
+ dynamic = ["version"]
8
+ description = "Official Python client for SpicyAPI — image, video and text generation behind one API."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.11"
12
+ authors = [{ name = "SpicyAPI" }]
13
+ keywords = ["spicyapi", "image-generation", "video-generation", "ai", "api-client"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ "Topic :: Multimedia :: Graphics",
22
+ "Topic :: Software Development :: Libraries :: Python Modules",
23
+ "Typing :: Typed",
24
+ ]
25
+ # 运行时零依赖是刻意的:这个包会被塞进别人已有的依赖树,多一个约束就多一次冲突。
26
+ dependencies = []
27
+
28
+ [project.urls]
29
+ Homepage = "https://spicyapi.ai"
30
+ Documentation = "https://docs.spicyapi.ai"
31
+ Source = "https://github.com/Spicy-API/spicy-python"
32
+ Issues = "https://spicyapi.ai/contact"
33
+
34
+ [tool.hatch.version]
35
+ # 版本号的唯一出处是 _client.py(__init__.py 只是把它再导出一次)。
36
+ # 写两处必然漂移,而漂移的表现是 PyPI 上的版本与 __version__ 对不上。
37
+ path = "src/spicyapi/_client.py"
38
+
39
+ [tool.hatch.build.targets.wheel]
40
+ packages = ["src/spicyapi"]
41
+
42
+ [tool.hatch.build.targets.sdist]
43
+ include = ["src/spicyapi", "tests", "README.md", "LICENSE"]
44
+
45
+ [tool.ruff]
46
+ line-length = 100
47
+ target-version = "py311"
48
+
49
+ [tool.ruff.lint]
50
+ select = ["E", "F", "I", "UP", "B", "SIM"]
@@ -0,0 +1,42 @@
1
+ """Official SpicyAPI client for Python.
2
+
3
+ The public surface is re-exported here, so ``from spicyapi import SpicyClient``
4
+ is the only import most programs need.
5
+ """
6
+
7
+ from ._client import (
8
+ ACTIVE_STATES,
9
+ API_BASE_URL,
10
+ TERMINAL_STATES,
11
+ SpicyApiError,
12
+ SpicyClient,
13
+ SpicyTimeoutError,
14
+ SpicyUploadError,
15
+ SpicyWebhookError,
16
+ compute_webhook_signature,
17
+ is_terminal,
18
+ output_assets,
19
+ output_text,
20
+ verify_webhook,
21
+ )
22
+
23
+ __all__ = [
24
+ "ACTIVE_STATES",
25
+ "API_BASE_URL",
26
+ "TERMINAL_STATES",
27
+ "SpicyApiError",
28
+ "SpicyClient",
29
+ "SpicyTimeoutError",
30
+ "compute_webhook_signature",
31
+ "SpicyUploadError",
32
+ "SpicyWebhookError",
33
+ "is_terminal",
34
+ "output_assets",
35
+ "output_text",
36
+ "verify_webhook",
37
+ ]
38
+
39
+ # 版本号的唯一出处是 _client.py,这里只是把它再导出一次,pyproject 也从那里读。
40
+ # 写两处必然漂移,而漂移的表现是 PyPI 上的版本与 __version__ 对不上——排查时
41
+ # 最误导人的那种。
42
+ from ._client import __version__ as __version__