sference-sdk 0.3.1__tar.gz → 0.4.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.
- {sference_sdk-0.3.1 → sference_sdk-0.4.0}/PKG-INFO +102 -14
- {sference_sdk-0.3.1 → sference_sdk-0.4.0}/README.md +99 -11
- {sference_sdk-0.3.1 → sference_sdk-0.4.0}/pyproject.toml +3 -3
- sference_sdk-0.4.0/sference_sdk/__init__.py +157 -0
- sference_sdk-0.4.0/sference_sdk/_base.py +341 -0
- sference_sdk-0.4.0/sference_sdk/async_client.py +500 -0
- sference_sdk-0.4.0/sference_sdk/client.py +496 -0
- sference_sdk-0.4.0/sference_sdk/models.py +643 -0
- sference_sdk-0.3.1/sference_sdk/__init__.py +0 -52
- sference_sdk-0.3.1/sference_sdk/async_client.py +0 -370
- sference_sdk-0.3.1/sference_sdk/client.py +0 -490
- sference_sdk-0.3.1/sference_sdk/models.py +0 -354
- {sference_sdk-0.3.1 → sference_sdk-0.4.0}/.gitignore +0 -0
- {sference_sdk-0.3.1 → sference_sdk-0.4.0}/LICENSE +0 -0
- {sference_sdk-0.3.1 → sference_sdk-0.4.0}/sference_sdk/checkpoint.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: sference-sdk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Python SDK for the sference batch API
|
|
5
5
|
Project-URL: Homepage, https://sference.com
|
|
6
6
|
Project-URL: Repository, https://github.com/s-ference/sference
|
|
@@ -14,20 +14,20 @@ Classifier: Intended Audience :: Developers
|
|
|
14
14
|
Classifier: Operating System :: OS Independent
|
|
15
15
|
Classifier: Programming Language :: Python :: 3
|
|
16
16
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
19
|
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
21
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
22
|
Classifier: Typing :: Typed
|
|
23
|
-
Requires-Python: >=3.
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
24
|
Requires-Dist: httpx>=0.28.1
|
|
25
25
|
Requires-Dist: pydantic>=2.12.5
|
|
26
26
|
Description-Content-Type: text/markdown
|
|
27
27
|
|
|
28
28
|
# sference Python SDK
|
|
29
29
|
|
|
30
|
-
Installable package: `sference-sdk` (import: `sference_sdk`). Used by the `sference` CLI and your own automation.
|
|
30
|
+
Installable package: `sference-sdk` (import: `sference_sdk`), Python 3.11+. Used by the `sference` CLI and your own automation.
|
|
31
31
|
|
|
32
32
|
## Install
|
|
33
33
|
|
|
@@ -62,9 +62,9 @@ Inner `body` accepts **chat completions** (`messages`) or **Responses** (`input`
|
|
|
62
62
|
Example `workload.jsonl`:
|
|
63
63
|
|
|
64
64
|
```jsonl
|
|
65
|
-
{"custom_id":"example-1","method":"POST","url":"/v1/chat/completions","body":{"model":"
|
|
66
|
-
{"custom_id":"example-2","method":"POST","url":"/v1/chat/completions","body":{"model":"
|
|
67
|
-
{"custom_id":"example-3","method":"POST","url":"/v1/responses","body":{"model":"
|
|
65
|
+
{"custom_id":"example-1","method":"POST","url":"/v1/chat/completions","body":{"model":"deepseek-ai/DeepSeek-V4.1-Flash-1017","messages":[{"role":"user","content":"Say hello in exactly one word."}]}}
|
|
66
|
+
{"custom_id":"example-2","method":"POST","url":"/v1/chat/completions","body":{"model":"deepseek-ai/DeepSeek-V4.1-Flash-1017","messages":[{"role":"system","content":"You reply with one short sentence only."},{"role":"user","content":"What is 2+2?"}]}}
|
|
67
|
+
{"custom_id":"example-3","method":"POST","url":"/v1/responses","body":{"model":"deepseek-ai/DeepSeek-V4.1-Flash-1017","input":[{"role":"user","content":"Reply with one word."}],"max_output_tokens":32}}
|
|
68
68
|
```
|
|
69
69
|
|
|
70
70
|
### Batches (sync)
|
|
@@ -78,10 +78,10 @@ client = SferenceClient(api_key="sk_...")
|
|
|
78
78
|
|
|
79
79
|
batch = client.submit_batch(
|
|
80
80
|
input_file="./workload.jsonl",
|
|
81
|
-
model="
|
|
81
|
+
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
|
|
82
82
|
window="24h",
|
|
83
83
|
)
|
|
84
|
-
done = client.wait_for_completion(batch.id
|
|
84
|
+
done = client.wait_for_completion(batch.id) # polls until terminal; pass timeout= to bound it
|
|
85
85
|
results = client.get_results(done.id)
|
|
86
86
|
by_id = results.index_by_custom_id()
|
|
87
87
|
print(by_id["row-a"].completion_text)
|
|
@@ -102,7 +102,7 @@ req = InferenceRequest.chat(
|
|
|
102
102
|
custom_id="row-a",
|
|
103
103
|
user_content="Summarize this.",
|
|
104
104
|
system_content="One sentence only.",
|
|
105
|
-
model="
|
|
105
|
+
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
|
|
106
106
|
temperature=0,
|
|
107
107
|
)
|
|
108
108
|
batch = client.submit_batch(requests=[req], window="24h")
|
|
@@ -120,7 +120,7 @@ from sference_sdk import SferenceClient
|
|
|
120
120
|
client = SferenceClient(api_key="sk_...")
|
|
121
121
|
|
|
122
122
|
created = client.create_response(
|
|
123
|
-
model="
|
|
123
|
+
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
|
|
124
124
|
input=[{"role": "user", "content": "Hello"}],
|
|
125
125
|
metadata={"completion_window": "24h"},
|
|
126
126
|
)
|
|
@@ -129,6 +129,94 @@ row = client.get_response(created.id)
|
|
|
129
129
|
|
|
130
130
|
For a stream, add `stream_id` inside `metadata` next to `completion_window`.
|
|
131
131
|
|
|
132
|
+
`create_response` also takes `tools`, `tool_choice`, `reasoning`, `include`, `text`, `prompt_cache_key` and `max_queue_wait_s`. Two options matter for cost and reliability:
|
|
133
|
+
|
|
134
|
+
- `service_tier="flex"` gives discounted tokens in exchange for lower scheduling priority (pair it with `background=True`); `"priority"` is scheduled ahead of default traffic and billed at a premium. `response.service_tier` is the tier actually served.
|
|
135
|
+
- `idempotency_key="..."` lets you retry a create after a network error without running the request twice.
|
|
136
|
+
|
|
137
|
+
### Streaming output (SSE)
|
|
138
|
+
|
|
139
|
+
For interactive use, `stream_response` takes the same options as `create_response` and yields events while the model generates. This is HTTP streaming of one response, unrelated to sference streams (`create_stream`), which group many responses. The events follow the OpenAI Responses streaming format:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
for event in client.stream_response(
|
|
143
|
+
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
|
|
144
|
+
input="Write a haiku about queues.",
|
|
145
|
+
):
|
|
146
|
+
if event.type == "response.output_text.delta":
|
|
147
|
+
print(event.delta, end="", flush=True)
|
|
148
|
+
elif event.type in ("response.completed", "response.incomplete", "response.failed"):
|
|
149
|
+
final = event.response # full Response with output and usage
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Reasoning arrives as `response.reasoning_summary_text.delta` events. If the server fails mid-stream, iteration raises `ApiError`. Stopping iteration early disconnects, which cancels the generation. `AsyncSferenceClient.stream_response` works the same way with `async for`.
|
|
153
|
+
|
|
154
|
+
### Models, usage and billing
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
models = client.list_models() # typed catalog: modality, pricing, capabilities, retires_on
|
|
158
|
+
live = [m.id for m in models.data if not m.retires_on]
|
|
159
|
+
|
|
160
|
+
client.get_billing_balance().credit_balance_micros # micro-USD
|
|
161
|
+
client.get_usage_summary(days=7).summary.total_cost_micros
|
|
162
|
+
client.get_usage_by_key(month="2026-11").items # spend per API key
|
|
163
|
+
page = client.list_billing_transactions(limit=50) # next page: starting_after=page.next_starting_after
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Batches, streams and completion events also report cost in micro-USD (`total_cost_micros`, `cost_micros`).
|
|
167
|
+
|
|
168
|
+
### Errors
|
|
169
|
+
|
|
170
|
+
Every non-2xx response raises `sference_sdk.ApiError` with `status_code`, `type`, `code`, `message` and the raw `body`:
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
from sference_sdk import ApiError
|
|
174
|
+
|
|
175
|
+
try:
|
|
176
|
+
client.create_response(model="deepseek-ai/DeepSeek-V4.1-Flash-1017", input="hi")
|
|
177
|
+
except ApiError as err:
|
|
178
|
+
if err.status_code == 429:
|
|
179
|
+
... # back off and retry
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Timeouts
|
|
183
|
+
|
|
184
|
+
Most calls time out after 30 seconds. Calls that the server keeps open while it works get longer waits that sit just above the server's own limits, so you get the server's error (a 408 or 504, or a failed stream event) instead of a client-side timeout. A blocking `create_response` waits up to 31 minutes, `stream_response` up to 6 minutes between events, and `create_decision` 45 seconds. Passing `timeout=` to the client sets one timeout for every call instead.
|
|
185
|
+
|
|
186
|
+
### Decisions (realtime classification)
|
|
187
|
+
|
|
188
|
+
`POST /v1/decisions` answers up to 64 questions about one `state` (text or any JSON value) in a single call. Pick a model with `modality == "decisions"` from `list_models()`. Question types: `choice` (pick one label), `score` (ordinal scale, index 0 = lowest) and `noul` (probability of true). Billed on input tokens only, including image tokens.
|
|
189
|
+
|
|
190
|
+
Both clients accept `images=["data:image/png;base64,..."]` or
|
|
191
|
+
`images=[{"content_type": "image/jpeg", "base64": "..."}]` (also available as
|
|
192
|
+
`sference_sdk.DecisionImage`). Images precede the state in array order and travel
|
|
193
|
+
inline without separate uploads. Clef accepts up to 4 PNG/JPEG/WebP images,
|
|
194
|
+
4 MiB and 16 megapixels each, 8 MiB total decoded bytes, with a 13 MiB request
|
|
195
|
+
body limit. Remote URLs are not accepted. Accepted images are EXIF-oriented and
|
|
196
|
+
downscaled to at most 2,097,152 pixels before inference; usage counts the resulting
|
|
197
|
+
image tokens. The 16-megapixel limit applies to the original uploaded image.
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
from sference_sdk import ChoiceQuestion, NoulQuestion, ScoreQuestion, SferenceClient
|
|
201
|
+
|
|
202
|
+
client = SferenceClient(api_key="sk_...")
|
|
203
|
+
|
|
204
|
+
decision = client.create_decision(
|
|
205
|
+
model="Cloudflare/clef",
|
|
206
|
+
state="I was charged twice this month, please refund me.",
|
|
207
|
+
questions={
|
|
208
|
+
"route": ChoiceQuestion(criteria={"billing": "Payments and invoices", "support": "Everything else"}),
|
|
209
|
+
"urgency": ScoreQuestion(criteria=["Low", "Medium", "High"]),
|
|
210
|
+
"refund": NoulQuestion(instructions="Does the customer ask for a refund?"),
|
|
211
|
+
},
|
|
212
|
+
)
|
|
213
|
+
decision.answers["route"].choice # "billing"
|
|
214
|
+
decision.answers["urgency"].score # 0..2, expected value over the scale
|
|
215
|
+
decision.answers["refund"].noul # probability of true
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Questions may also be plain dicts (`{"type": "noul"}`). `429` means no decision capacity right now and is safe to retry; `504` means the deadline passed and nothing was charged.
|
|
219
|
+
|
|
132
220
|
### OpenAI Python SDK (`openai` package)
|
|
133
221
|
|
|
134
222
|
If you already use the official OpenAI client, point it at sference’s **`/v1`** endpoint and the same API key (with `responses:read` and `responses:write`).
|
|
@@ -151,7 +239,7 @@ async def main() -> None:
|
|
|
151
239
|
)
|
|
152
240
|
|
|
153
241
|
response = await client.responses.create(
|
|
154
|
-
model="
|
|
242
|
+
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
|
|
155
243
|
input=[{"role": "user", "content": "Hello, world!"}],
|
|
156
244
|
background=True,
|
|
157
245
|
)
|
|
@@ -183,7 +271,7 @@ async def main() -> None:
|
|
|
183
271
|
async with AsyncSferenceClient(api_key="sk_...") as client:
|
|
184
272
|
batch = await client.submit_batch(
|
|
185
273
|
input_file="./workload.jsonl",
|
|
186
|
-
model="
|
|
274
|
+
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
|
|
187
275
|
window="24h",
|
|
188
276
|
)
|
|
189
277
|
done = await client.wait_for_completion(batch.id, poll_interval=2.0, timeout=3600.0)
|
|
@@ -212,7 +300,7 @@ async def main() -> None:
|
|
|
212
300
|
async with AsyncSferenceClient(api_key="sk_...") as client:
|
|
213
301
|
stream = await client.create_stream(name="sdk-demo", window="24h")
|
|
214
302
|
await client.create_response(
|
|
215
|
-
model="
|
|
303
|
+
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
|
|
216
304
|
input=[{"role": "user", "content": "Hello"}],
|
|
217
305
|
metadata={"stream_id": stream.id, "completion_window": "24h"},
|
|
218
306
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# sference Python SDK
|
|
2
2
|
|
|
3
|
-
Installable package: `sference-sdk` (import: `sference_sdk`). Used by the `sference` CLI and your own automation.
|
|
3
|
+
Installable package: `sference-sdk` (import: `sference_sdk`), Python 3.11+. Used by the `sference` CLI and your own automation.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -35,9 +35,9 @@ Inner `body` accepts **chat completions** (`messages`) or **Responses** (`input`
|
|
|
35
35
|
Example `workload.jsonl`:
|
|
36
36
|
|
|
37
37
|
```jsonl
|
|
38
|
-
{"custom_id":"example-1","method":"POST","url":"/v1/chat/completions","body":{"model":"
|
|
39
|
-
{"custom_id":"example-2","method":"POST","url":"/v1/chat/completions","body":{"model":"
|
|
40
|
-
{"custom_id":"example-3","method":"POST","url":"/v1/responses","body":{"model":"
|
|
38
|
+
{"custom_id":"example-1","method":"POST","url":"/v1/chat/completions","body":{"model":"deepseek-ai/DeepSeek-V4.1-Flash-1017","messages":[{"role":"user","content":"Say hello in exactly one word."}]}}
|
|
39
|
+
{"custom_id":"example-2","method":"POST","url":"/v1/chat/completions","body":{"model":"deepseek-ai/DeepSeek-V4.1-Flash-1017","messages":[{"role":"system","content":"You reply with one short sentence only."},{"role":"user","content":"What is 2+2?"}]}}
|
|
40
|
+
{"custom_id":"example-3","method":"POST","url":"/v1/responses","body":{"model":"deepseek-ai/DeepSeek-V4.1-Flash-1017","input":[{"role":"user","content":"Reply with one word."}],"max_output_tokens":32}}
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
### Batches (sync)
|
|
@@ -51,10 +51,10 @@ client = SferenceClient(api_key="sk_...")
|
|
|
51
51
|
|
|
52
52
|
batch = client.submit_batch(
|
|
53
53
|
input_file="./workload.jsonl",
|
|
54
|
-
model="
|
|
54
|
+
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
|
|
55
55
|
window="24h",
|
|
56
56
|
)
|
|
57
|
-
done = client.wait_for_completion(batch.id
|
|
57
|
+
done = client.wait_for_completion(batch.id) # polls until terminal; pass timeout= to bound it
|
|
58
58
|
results = client.get_results(done.id)
|
|
59
59
|
by_id = results.index_by_custom_id()
|
|
60
60
|
print(by_id["row-a"].completion_text)
|
|
@@ -75,7 +75,7 @@ req = InferenceRequest.chat(
|
|
|
75
75
|
custom_id="row-a",
|
|
76
76
|
user_content="Summarize this.",
|
|
77
77
|
system_content="One sentence only.",
|
|
78
|
-
model="
|
|
78
|
+
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
|
|
79
79
|
temperature=0,
|
|
80
80
|
)
|
|
81
81
|
batch = client.submit_batch(requests=[req], window="24h")
|
|
@@ -93,7 +93,7 @@ from sference_sdk import SferenceClient
|
|
|
93
93
|
client = SferenceClient(api_key="sk_...")
|
|
94
94
|
|
|
95
95
|
created = client.create_response(
|
|
96
|
-
model="
|
|
96
|
+
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
|
|
97
97
|
input=[{"role": "user", "content": "Hello"}],
|
|
98
98
|
metadata={"completion_window": "24h"},
|
|
99
99
|
)
|
|
@@ -102,6 +102,94 @@ row = client.get_response(created.id)
|
|
|
102
102
|
|
|
103
103
|
For a stream, add `stream_id` inside `metadata` next to `completion_window`.
|
|
104
104
|
|
|
105
|
+
`create_response` also takes `tools`, `tool_choice`, `reasoning`, `include`, `text`, `prompt_cache_key` and `max_queue_wait_s`. Two options matter for cost and reliability:
|
|
106
|
+
|
|
107
|
+
- `service_tier="flex"` gives discounted tokens in exchange for lower scheduling priority (pair it with `background=True`); `"priority"` is scheduled ahead of default traffic and billed at a premium. `response.service_tier` is the tier actually served.
|
|
108
|
+
- `idempotency_key="..."` lets you retry a create after a network error without running the request twice.
|
|
109
|
+
|
|
110
|
+
### Streaming output (SSE)
|
|
111
|
+
|
|
112
|
+
For interactive use, `stream_response` takes the same options as `create_response` and yields events while the model generates. This is HTTP streaming of one response, unrelated to sference streams (`create_stream`), which group many responses. The events follow the OpenAI Responses streaming format:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
for event in client.stream_response(
|
|
116
|
+
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
|
|
117
|
+
input="Write a haiku about queues.",
|
|
118
|
+
):
|
|
119
|
+
if event.type == "response.output_text.delta":
|
|
120
|
+
print(event.delta, end="", flush=True)
|
|
121
|
+
elif event.type in ("response.completed", "response.incomplete", "response.failed"):
|
|
122
|
+
final = event.response # full Response with output and usage
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Reasoning arrives as `response.reasoning_summary_text.delta` events. If the server fails mid-stream, iteration raises `ApiError`. Stopping iteration early disconnects, which cancels the generation. `AsyncSferenceClient.stream_response` works the same way with `async for`.
|
|
126
|
+
|
|
127
|
+
### Models, usage and billing
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
models = client.list_models() # typed catalog: modality, pricing, capabilities, retires_on
|
|
131
|
+
live = [m.id for m in models.data if not m.retires_on]
|
|
132
|
+
|
|
133
|
+
client.get_billing_balance().credit_balance_micros # micro-USD
|
|
134
|
+
client.get_usage_summary(days=7).summary.total_cost_micros
|
|
135
|
+
client.get_usage_by_key(month="2026-11").items # spend per API key
|
|
136
|
+
page = client.list_billing_transactions(limit=50) # next page: starting_after=page.next_starting_after
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Batches, streams and completion events also report cost in micro-USD (`total_cost_micros`, `cost_micros`).
|
|
140
|
+
|
|
141
|
+
### Errors
|
|
142
|
+
|
|
143
|
+
Every non-2xx response raises `sference_sdk.ApiError` with `status_code`, `type`, `code`, `message` and the raw `body`:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from sference_sdk import ApiError
|
|
147
|
+
|
|
148
|
+
try:
|
|
149
|
+
client.create_response(model="deepseek-ai/DeepSeek-V4.1-Flash-1017", input="hi")
|
|
150
|
+
except ApiError as err:
|
|
151
|
+
if err.status_code == 429:
|
|
152
|
+
... # back off and retry
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Timeouts
|
|
156
|
+
|
|
157
|
+
Most calls time out after 30 seconds. Calls that the server keeps open while it works get longer waits that sit just above the server's own limits, so you get the server's error (a 408 or 504, or a failed stream event) instead of a client-side timeout. A blocking `create_response` waits up to 31 minutes, `stream_response` up to 6 minutes between events, and `create_decision` 45 seconds. Passing `timeout=` to the client sets one timeout for every call instead.
|
|
158
|
+
|
|
159
|
+
### Decisions (realtime classification)
|
|
160
|
+
|
|
161
|
+
`POST /v1/decisions` answers up to 64 questions about one `state` (text or any JSON value) in a single call. Pick a model with `modality == "decisions"` from `list_models()`. Question types: `choice` (pick one label), `score` (ordinal scale, index 0 = lowest) and `noul` (probability of true). Billed on input tokens only, including image tokens.
|
|
162
|
+
|
|
163
|
+
Both clients accept `images=["data:image/png;base64,..."]` or
|
|
164
|
+
`images=[{"content_type": "image/jpeg", "base64": "..."}]` (also available as
|
|
165
|
+
`sference_sdk.DecisionImage`). Images precede the state in array order and travel
|
|
166
|
+
inline without separate uploads. Clef accepts up to 4 PNG/JPEG/WebP images,
|
|
167
|
+
4 MiB and 16 megapixels each, 8 MiB total decoded bytes, with a 13 MiB request
|
|
168
|
+
body limit. Remote URLs are not accepted. Accepted images are EXIF-oriented and
|
|
169
|
+
downscaled to at most 2,097,152 pixels before inference; usage counts the resulting
|
|
170
|
+
image tokens. The 16-megapixel limit applies to the original uploaded image.
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
from sference_sdk import ChoiceQuestion, NoulQuestion, ScoreQuestion, SferenceClient
|
|
174
|
+
|
|
175
|
+
client = SferenceClient(api_key="sk_...")
|
|
176
|
+
|
|
177
|
+
decision = client.create_decision(
|
|
178
|
+
model="Cloudflare/clef",
|
|
179
|
+
state="I was charged twice this month, please refund me.",
|
|
180
|
+
questions={
|
|
181
|
+
"route": ChoiceQuestion(criteria={"billing": "Payments and invoices", "support": "Everything else"}),
|
|
182
|
+
"urgency": ScoreQuestion(criteria=["Low", "Medium", "High"]),
|
|
183
|
+
"refund": NoulQuestion(instructions="Does the customer ask for a refund?"),
|
|
184
|
+
},
|
|
185
|
+
)
|
|
186
|
+
decision.answers["route"].choice # "billing"
|
|
187
|
+
decision.answers["urgency"].score # 0..2, expected value over the scale
|
|
188
|
+
decision.answers["refund"].noul # probability of true
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Questions may also be plain dicts (`{"type": "noul"}`). `429` means no decision capacity right now and is safe to retry; `504` means the deadline passed and nothing was charged.
|
|
192
|
+
|
|
105
193
|
### OpenAI Python SDK (`openai` package)
|
|
106
194
|
|
|
107
195
|
If you already use the official OpenAI client, point it at sference’s **`/v1`** endpoint and the same API key (with `responses:read` and `responses:write`).
|
|
@@ -124,7 +212,7 @@ async def main() -> None:
|
|
|
124
212
|
)
|
|
125
213
|
|
|
126
214
|
response = await client.responses.create(
|
|
127
|
-
model="
|
|
215
|
+
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
|
|
128
216
|
input=[{"role": "user", "content": "Hello, world!"}],
|
|
129
217
|
background=True,
|
|
130
218
|
)
|
|
@@ -156,7 +244,7 @@ async def main() -> None:
|
|
|
156
244
|
async with AsyncSferenceClient(api_key="sk_...") as client:
|
|
157
245
|
batch = await client.submit_batch(
|
|
158
246
|
input_file="./workload.jsonl",
|
|
159
|
-
model="
|
|
247
|
+
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
|
|
160
248
|
window="24h",
|
|
161
249
|
)
|
|
162
250
|
done = await client.wait_for_completion(batch.id, poll_interval=2.0, timeout=3600.0)
|
|
@@ -185,7 +273,7 @@ async def main() -> None:
|
|
|
185
273
|
async with AsyncSferenceClient(api_key="sk_...") as client:
|
|
186
274
|
stream = await client.create_stream(name="sdk-demo", window="24h")
|
|
187
275
|
await client.create_response(
|
|
188
|
-
model="
|
|
276
|
+
model="deepseek-ai/DeepSeek-V4.1-Flash-1017",
|
|
189
277
|
input=[{"role": "user", "content": "Hello"}],
|
|
190
278
|
metadata={"stream_id": stream.id, "completion_window": "24h"},
|
|
191
279
|
)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sference-sdk"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.4.0"
|
|
4
4
|
description = "Python SDK for the sference batch API"
|
|
5
5
|
readme = "README.md"
|
|
6
|
-
requires-python = ">=3.
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
7
|
license = "Apache-2.0"
|
|
8
8
|
license-files = ["LICENSE"]
|
|
9
9
|
authors = [{ name = "sference" }]
|
|
@@ -14,10 +14,10 @@ classifiers = [
|
|
|
14
14
|
"Operating System :: OS Independent",
|
|
15
15
|
"Programming Language :: Python :: 3",
|
|
16
16
|
"Programming Language :: Python :: 3 :: Only",
|
|
17
|
-
"Programming Language :: Python :: 3.10",
|
|
18
17
|
"Programming Language :: Python :: 3.11",
|
|
19
18
|
"Programming Language :: Python :: 3.12",
|
|
20
19
|
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Programming Language :: Python :: 3.14",
|
|
21
21
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
22
22
|
"Typing :: Typed",
|
|
23
23
|
]
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
from importlib.metadata import PackageNotFoundError, version as _distribution_version
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def _package_version(distribution_name: str) -> str:
|
|
5
|
+
"""Installed distribution version (matches ``pyproject.toml`` / release tag)."""
|
|
6
|
+
try:
|
|
7
|
+
return _distribution_version(distribution_name)
|
|
8
|
+
except PackageNotFoundError:
|
|
9
|
+
return "0.0.0-dev"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
__version__ = _package_version("sference-sdk")
|
|
13
|
+
|
|
14
|
+
from ._base import ApiError
|
|
15
|
+
from .async_client import AsyncSferenceClient
|
|
16
|
+
from .checkpoint import clear_checkpoint, load_checkpoint, save_checkpoint
|
|
17
|
+
from .client import SferenceClient
|
|
18
|
+
from .models import (
|
|
19
|
+
COMPLETION_WINDOWS,
|
|
20
|
+
ApiModel,
|
|
21
|
+
Batch,
|
|
22
|
+
BatchList,
|
|
23
|
+
BatchResultRow,
|
|
24
|
+
BatchResults,
|
|
25
|
+
BillingBalanceResponse,
|
|
26
|
+
BillingModelSummary,
|
|
27
|
+
BillingSummary,
|
|
28
|
+
BillingSummaryResponse,
|
|
29
|
+
CapabilityFlag,
|
|
30
|
+
ChoiceAnswer,
|
|
31
|
+
ChoiceQuestion,
|
|
32
|
+
CompletionWindow,
|
|
33
|
+
DailyUsage,
|
|
34
|
+
DecisionAnswer,
|
|
35
|
+
DecisionImage,
|
|
36
|
+
DecisionQuestion,
|
|
37
|
+
DecisionResponse,
|
|
38
|
+
DecisionUsage,
|
|
39
|
+
EmbeddingData,
|
|
40
|
+
EmbeddingResponse,
|
|
41
|
+
EmbeddingUsage,
|
|
42
|
+
InferenceRequest,
|
|
43
|
+
LedgerEntryItem,
|
|
44
|
+
LedgerListResponse,
|
|
45
|
+
ModelCapabilities,
|
|
46
|
+
ModelInfo,
|
|
47
|
+
ModelList,
|
|
48
|
+
ModelPricing,
|
|
49
|
+
ModelUsageSummary,
|
|
50
|
+
NoulAnswer,
|
|
51
|
+
NoulQuestion,
|
|
52
|
+
OffPeakPricing,
|
|
53
|
+
PricingInfo,
|
|
54
|
+
Response,
|
|
55
|
+
ResponseError,
|
|
56
|
+
ResponseFunctionToolCall,
|
|
57
|
+
ResponseIncompleteDetails,
|
|
58
|
+
ResponseList,
|
|
59
|
+
ResponseListItem,
|
|
60
|
+
ResponseStreamEvent,
|
|
61
|
+
ResponseOutputMessage,
|
|
62
|
+
ResponseOutputReasoning,
|
|
63
|
+
ResponseOutputText,
|
|
64
|
+
ResponseStatus,
|
|
65
|
+
ResponseUsage,
|
|
66
|
+
ScoreAnswer,
|
|
67
|
+
ScoreQuestion,
|
|
68
|
+
ServiceTier,
|
|
69
|
+
Stream,
|
|
70
|
+
StreamEventList,
|
|
71
|
+
StreamInferenceCompletionEvent,
|
|
72
|
+
StreamList,
|
|
73
|
+
ThinkingCapability,
|
|
74
|
+
UsageByKeyItem,
|
|
75
|
+
UsageByKeyResponse,
|
|
76
|
+
UsageByTagItem,
|
|
77
|
+
UsageDailyResponse,
|
|
78
|
+
UsageSummary,
|
|
79
|
+
UsageSummaryResponse,
|
|
80
|
+
User,
|
|
81
|
+
UserUsageSummary,
|
|
82
|
+
reasoning_summary_plaintext,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
__all__ = [
|
|
86
|
+
"__version__",
|
|
87
|
+
"ApiError",
|
|
88
|
+
"AsyncSferenceClient",
|
|
89
|
+
"SferenceClient",
|
|
90
|
+
"clear_checkpoint",
|
|
91
|
+
"load_checkpoint",
|
|
92
|
+
"save_checkpoint",
|
|
93
|
+
"COMPLETION_WINDOWS",
|
|
94
|
+
"ApiModel",
|
|
95
|
+
"Batch",
|
|
96
|
+
"BatchList",
|
|
97
|
+
"BatchResultRow",
|
|
98
|
+
"BatchResults",
|
|
99
|
+
"BillingBalanceResponse",
|
|
100
|
+
"BillingModelSummary",
|
|
101
|
+
"BillingSummary",
|
|
102
|
+
"BillingSummaryResponse",
|
|
103
|
+
"CapabilityFlag",
|
|
104
|
+
"ChoiceAnswer",
|
|
105
|
+
"ChoiceQuestion",
|
|
106
|
+
"CompletionWindow",
|
|
107
|
+
"DailyUsage",
|
|
108
|
+
"DecisionAnswer",
|
|
109
|
+
"DecisionImage",
|
|
110
|
+
"DecisionQuestion",
|
|
111
|
+
"DecisionResponse",
|
|
112
|
+
"DecisionUsage",
|
|
113
|
+
"EmbeddingData",
|
|
114
|
+
"EmbeddingResponse",
|
|
115
|
+
"EmbeddingUsage",
|
|
116
|
+
"InferenceRequest",
|
|
117
|
+
"LedgerEntryItem",
|
|
118
|
+
"LedgerListResponse",
|
|
119
|
+
"ModelCapabilities",
|
|
120
|
+
"ModelInfo",
|
|
121
|
+
"ModelList",
|
|
122
|
+
"ModelPricing",
|
|
123
|
+
"ModelUsageSummary",
|
|
124
|
+
"NoulAnswer",
|
|
125
|
+
"NoulQuestion",
|
|
126
|
+
"OffPeakPricing",
|
|
127
|
+
"PricingInfo",
|
|
128
|
+
"Response",
|
|
129
|
+
"ResponseError",
|
|
130
|
+
"ResponseFunctionToolCall",
|
|
131
|
+
"ResponseIncompleteDetails",
|
|
132
|
+
"ResponseList",
|
|
133
|
+
"ResponseListItem",
|
|
134
|
+
"ResponseStreamEvent",
|
|
135
|
+
"ResponseOutputMessage",
|
|
136
|
+
"ResponseOutputReasoning",
|
|
137
|
+
"ResponseOutputText",
|
|
138
|
+
"ResponseStatus",
|
|
139
|
+
"ResponseUsage",
|
|
140
|
+
"ScoreAnswer",
|
|
141
|
+
"ScoreQuestion",
|
|
142
|
+
"ServiceTier",
|
|
143
|
+
"Stream",
|
|
144
|
+
"StreamEventList",
|
|
145
|
+
"StreamInferenceCompletionEvent",
|
|
146
|
+
"StreamList",
|
|
147
|
+
"ThinkingCapability",
|
|
148
|
+
"UsageByKeyItem",
|
|
149
|
+
"UsageByKeyResponse",
|
|
150
|
+
"UsageByTagItem",
|
|
151
|
+
"UsageDailyResponse",
|
|
152
|
+
"UsageSummary",
|
|
153
|
+
"UsageSummaryResponse",
|
|
154
|
+
"User",
|
|
155
|
+
"UserUsageSummary",
|
|
156
|
+
"reasoning_summary_plaintext",
|
|
157
|
+
]
|