offpeak 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.
- offpeak-0.1.0/.github/workflows/ci.yml +25 -0
- offpeak-0.1.0/.github/workflows/publish.yml +39 -0
- offpeak-0.1.0/.gitignore +21 -0
- offpeak-0.1.0/CONTRIBUTING.md +31 -0
- offpeak-0.1.0/LICENSE +202 -0
- offpeak-0.1.0/PKG-INFO +144 -0
- offpeak-0.1.0/README.md +107 -0
- offpeak-0.1.0/SPEC.md +73 -0
- offpeak-0.1.0/pyproject.toml +65 -0
- offpeak-0.1.0/src/offpeak/__init__.py +37 -0
- offpeak-0.1.0/src/offpeak/client.py +223 -0
- offpeak-0.1.0/src/offpeak/deadline.py +84 -0
- offpeak-0.1.0/src/offpeak/job.py +109 -0
- offpeak-0.1.0/src/offpeak/prices.py +68 -0
- offpeak-0.1.0/src/offpeak/venues/__init__.py +5 -0
- offpeak-0.1.0/src/offpeak/venues/anthropic_batch.py +141 -0
- offpeak-0.1.0/src/offpeak/venues/base.py +58 -0
- offpeak-0.1.0/src/offpeak/venues/openai_batch.py +149 -0
- offpeak-0.1.0/tests/test_deadline.py +69 -0
- offpeak-0.1.0/tests/test_job_receipt.py +84 -0
- offpeak-0.1.0/tests/test_run.py +159 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
fail-fast: false
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: actions/setup-python@v5
|
|
18
|
+
with:
|
|
19
|
+
python-version: ${{ matrix.python-version }}
|
|
20
|
+
- name: Install
|
|
21
|
+
run: pip install -e ".[dev]"
|
|
22
|
+
- name: Lint
|
|
23
|
+
run: ruff check src tests
|
|
24
|
+
- name: Test
|
|
25
|
+
run: pytest
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
# Publishes on every GitHub Release via PyPI Trusted Publishing (OIDC).
|
|
4
|
+
# No API tokens: configure the publisher on pypi.org first — see the repo's
|
|
5
|
+
# release docs. The "pypi" environment below must exist in repo settings.
|
|
6
|
+
|
|
7
|
+
on:
|
|
8
|
+
release:
|
|
9
|
+
types: [published]
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
build:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: "3.12"
|
|
19
|
+
- name: Build sdist and wheel
|
|
20
|
+
run: |
|
|
21
|
+
pip install build
|
|
22
|
+
python -m build
|
|
23
|
+
- uses: actions/upload-artifact@v4
|
|
24
|
+
with:
|
|
25
|
+
name: dist
|
|
26
|
+
path: dist/
|
|
27
|
+
|
|
28
|
+
publish:
|
|
29
|
+
needs: build
|
|
30
|
+
runs-on: ubuntu-latest
|
|
31
|
+
environment: pypi
|
|
32
|
+
permissions:
|
|
33
|
+
id-token: write # required for Trusted Publishing
|
|
34
|
+
steps:
|
|
35
|
+
- uses: actions/download-artifact@v4
|
|
36
|
+
with:
|
|
37
|
+
name: dist
|
|
38
|
+
path: dist/
|
|
39
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
offpeak-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.eggs/
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
.venv/
|
|
9
|
+
venv/
|
|
10
|
+
|
|
11
|
+
# Tooling
|
|
12
|
+
.pytest_cache/
|
|
13
|
+
.ruff_cache/
|
|
14
|
+
.mypy_cache/
|
|
15
|
+
.coverage
|
|
16
|
+
htmlcov/
|
|
17
|
+
|
|
18
|
+
# Editors / OS
|
|
19
|
+
.idea/
|
|
20
|
+
.vscode/
|
|
21
|
+
.DS_Store
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thanks for helping build the deadline standard.
|
|
4
|
+
|
|
5
|
+
## Dev setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
git clone https://github.com/offpeak-ai/offpeak
|
|
9
|
+
cd offpeak
|
|
10
|
+
python -m venv .venv && source .venv/bin/activate
|
|
11
|
+
pip install -e ".[dev]"
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Checks
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
ruff check src tests
|
|
18
|
+
pytest
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Both run in CI on every PR. Tests are network-free — venue drivers are tested against fakes; never add a test that needs an API key.
|
|
22
|
+
|
|
23
|
+
## What's welcome
|
|
24
|
+
|
|
25
|
+
- New venue drivers (implement `offpeak.Venue`; keep provider SDKs behind optional extras).
|
|
26
|
+
- Deadline-form and receipt improvements.
|
|
27
|
+
- Price-sheet corrections (cite the provider's public pricing page in the PR).
|
|
28
|
+
|
|
29
|
+
## Spec changes
|
|
30
|
+
|
|
31
|
+
[SPEC.md](SPEC.md) changes start as an issue before a PR, so semantics get discussed ahead of wording.
|
offpeak-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
https://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Offpeak
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
offpeak-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: offpeak
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Deadline-priced inference: give AI jobs a deadline and run them on the cheapest venue — provider batch tiers (−50%) today. Same model, same tokens, a different hour.
|
|
5
|
+
Project-URL: Homepage, https://github.com/offpeak-ai/offpeak
|
|
6
|
+
Project-URL: Repository, https://github.com/offpeak-ai/offpeak
|
|
7
|
+
Project-URL: Issues, https://github.com/offpeak-ai/offpeak/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/offpeak-ai/offpeak/releases
|
|
9
|
+
Author: Offpeak
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: anthropic,batch,batch-api,cost-optimization,deadline,finops,inference,llm,openai,scheduling
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Topic :: System :: Distributed Computing
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Provides-Extra: all
|
|
25
|
+
Requires-Dist: anthropic>=0.40; extra == 'all'
|
|
26
|
+
Requires-Dist: openai>=1.50; extra == 'all'
|
|
27
|
+
Provides-Extra: anthropic
|
|
28
|
+
Requires-Dist: anthropic>=0.40; extra == 'anthropic'
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: build; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
32
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
33
|
+
Requires-Dist: twine; extra == 'dev'
|
|
34
|
+
Provides-Extra: openai
|
|
35
|
+
Requires-Dist: openai>=1.50; extra == 'openai'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# offpeak
|
|
39
|
+
|
|
40
|
+
**Deadline-priced inference.** Same model, same tokens, a different hour — for half the price.
|
|
41
|
+
|
|
42
|
+
[](https://github.com/offpeak-ai/offpeak/actions/workflows/ci.yml)
|
|
43
|
+
[](https://pypi.org/project/offpeak/)
|
|
44
|
+
[](LICENSE)
|
|
45
|
+
|
|
46
|
+
OpenAI, Anthropic, and Google all sell batch inference at **50% off list price**. Almost nobody uses it, because no API lets work say it can wait: every token runs "now" by default, and the batch workflow — build a file, upload, poll, download, match results back up — is enough friction that urgency gets bought by accident.
|
|
47
|
+
|
|
48
|
+
`offpeak` gives your code one new argument.
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
import offpeak
|
|
52
|
+
|
|
53
|
+
jobs = [offpeak.job("claude-haiku-4-5", f"Summarize:\n\n{doc}") for doc in docs]
|
|
54
|
+
|
|
55
|
+
results = offpeak.run(jobs, deadline="06:00") # done by 6am, at batch prices
|
|
56
|
+
|
|
57
|
+
print(offpeak.receipt(results))
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
OFFPEAK SETTLEMENT ────────────────────────────
|
|
62
|
+
jobs 1,000 (1,000 ok, 2 sync fallback)
|
|
63
|
+
sla 1,000/1,000 met
|
|
64
|
+
venues anthropic:batch 1,000
|
|
65
|
+
tokens 12,410,332 in · 3,104,551 out
|
|
66
|
+
list $27.93
|
|
67
|
+
paid $14.02
|
|
68
|
+
captured $13.91 (49.8%)
|
|
69
|
+
prices snapshot 2026-08 — override via offpeak.prices
|
|
70
|
+
───────────────────────────────────────────────
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## What it does
|
|
74
|
+
|
|
75
|
+
- **One argument, not a workflow.** `run(jobs, deadline=...)` handles batching, submission, polling, collection, and result matching across providers.
|
|
76
|
+
- **Deadlines are guarded, not hoped for.** If a batch hasn't landed by the time the remaining window shrinks to a risk buffer, `offpeak` cancels and re-runs the stragglers synchronously at list price. You state the deadline; it gets met.
|
|
77
|
+
- **Every run settles a receipt.** List cost, paid cost, captured spread — arithmetic against public price sheets, not estimates.
|
|
78
|
+
- **Your keys, your perimeter.** `offpeak` talks directly to the providers with your own API keys. There is no proxy and no third party in the data path.
|
|
79
|
+
- **Zero-dependency core.** Provider SDKs load only via extras.
|
|
80
|
+
|
|
81
|
+
## Install
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install "offpeak[all]" # OpenAI + Anthropic venues
|
|
85
|
+
pip install "offpeak[anthropic]" # or one provider
|
|
86
|
+
pip install "offpeak[openai]"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Venues use the standard environment variables (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`), or pass a configured client: `OpenAIBatch(client=my_client)`.
|
|
90
|
+
|
|
91
|
+
## Deadlines
|
|
92
|
+
|
|
93
|
+
Deadlines are how software says "this can wait" — the full semantics live in [SPEC.md](SPEC.md).
|
|
94
|
+
|
|
95
|
+
| Form | Meaning |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| `"06:00"` | the next 6am, local time (the canonical overnight form) |
|
|
98
|
+
| `"4h"`, `"90m"`, `"2d"` | relative to now |
|
|
99
|
+
| `"2026-08-21T06:00:00-07:00"` | ISO 8601, absolute |
|
|
100
|
+
| `datetime` / `timedelta` / seconds | native Python forms |
|
|
101
|
+
|
|
102
|
+
## How a run works
|
|
103
|
+
|
|
104
|
+
1. Jobs are grouped by venue (`claude-*` → Anthropic Message Batches, `gpt-*`/`o*` → OpenAI Batch) and submitted at the batch tier — 50% of list.
|
|
105
|
+
2. `offpeak` polls the venues, backing off while the window is long.
|
|
106
|
+
3. When remaining time reaches the **risk buffer** (default: 15% of the window, clamped to 1–10 minutes), unfinished jobs are cancelled and re-run synchronously so the deadline holds. Set `fallback="none"` to report them instead.
|
|
107
|
+
4. Results come back in input order, each with a per-job `Receipt`; `offpeak.receipt(results)` settles the run.
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
results = offpeak.run(
|
|
111
|
+
jobs,
|
|
112
|
+
deadline="06:00",
|
|
113
|
+
fallback="sync", # meet the deadline at list price if the batch is at risk
|
|
114
|
+
risk_buffer=600, # seconds held in reserve (optional)
|
|
115
|
+
)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Receipts and prices
|
|
119
|
+
|
|
120
|
+
Receipts are computed against a bundled snapshot of public list prices (batch = 50% of list, as published). Providers change prices — verify and override at runtime:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
import offpeak
|
|
124
|
+
|
|
125
|
+
offpeak.prices.register_price("my-fine-tune", input_per_m=4.0, output_per_m=16.0)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Unknown models settle with `cost = None` rather than a guess.
|
|
129
|
+
|
|
130
|
+
## What this is (and the roadmap)
|
|
131
|
+
|
|
132
|
+
`offpeak` is the open client and spec for a simple claim: **intelligence has a time value**. A large share of AI work — embeddings, evals, backfills, report generation, overnight agents — has no human waiting on it, and the venues already price that patience at −50%. This library is the missing workflow.
|
|
133
|
+
|
|
134
|
+
The roadmap follows the same interface upward: more venues (Google batch, spot capacity, off-peak windows on your own GPUs), queue-latency forecasting instead of a fixed risk buffer, portfolio placement across venues, energy- and carbon-aware scheduling with per-job receipts. The venue interface (`offpeak.Venue`) is deliberately the extension point — a venue is anywhere deferred work can run.
|
|
135
|
+
|
|
136
|
+
A hosted desk that does the forecasting, cross-venue portfolio scheduling, and SLA insurance at fleet scale — payloads never leaving your perimeter — is being built by the same team. The SDK and the deadline spec stay open, Apache-2.0.
|
|
137
|
+
|
|
138
|
+
## Contributing
|
|
139
|
+
|
|
140
|
+
Issues and PRs welcome — see [CONTRIBUTING.md](CONTRIBUTING.md). Spec changes start as issues against [SPEC.md](SPEC.md).
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
Apache-2.0 © Offpeak
|
offpeak-0.1.0/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# offpeak
|
|
2
|
+
|
|
3
|
+
**Deadline-priced inference.** Same model, same tokens, a different hour — for half the price.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/offpeak-ai/offpeak/actions/workflows/ci.yml)
|
|
6
|
+
[](https://pypi.org/project/offpeak/)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
OpenAI, Anthropic, and Google all sell batch inference at **50% off list price**. Almost nobody uses it, because no API lets work say it can wait: every token runs "now" by default, and the batch workflow — build a file, upload, poll, download, match results back up — is enough friction that urgency gets bought by accident.
|
|
10
|
+
|
|
11
|
+
`offpeak` gives your code one new argument.
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
import offpeak
|
|
15
|
+
|
|
16
|
+
jobs = [offpeak.job("claude-haiku-4-5", f"Summarize:\n\n{doc}") for doc in docs]
|
|
17
|
+
|
|
18
|
+
results = offpeak.run(jobs, deadline="06:00") # done by 6am, at batch prices
|
|
19
|
+
|
|
20
|
+
print(offpeak.receipt(results))
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
OFFPEAK SETTLEMENT ────────────────────────────
|
|
25
|
+
jobs 1,000 (1,000 ok, 2 sync fallback)
|
|
26
|
+
sla 1,000/1,000 met
|
|
27
|
+
venues anthropic:batch 1,000
|
|
28
|
+
tokens 12,410,332 in · 3,104,551 out
|
|
29
|
+
list $27.93
|
|
30
|
+
paid $14.02
|
|
31
|
+
captured $13.91 (49.8%)
|
|
32
|
+
prices snapshot 2026-08 — override via offpeak.prices
|
|
33
|
+
───────────────────────────────────────────────
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## What it does
|
|
37
|
+
|
|
38
|
+
- **One argument, not a workflow.** `run(jobs, deadline=...)` handles batching, submission, polling, collection, and result matching across providers.
|
|
39
|
+
- **Deadlines are guarded, not hoped for.** If a batch hasn't landed by the time the remaining window shrinks to a risk buffer, `offpeak` cancels and re-runs the stragglers synchronously at list price. You state the deadline; it gets met.
|
|
40
|
+
- **Every run settles a receipt.** List cost, paid cost, captured spread — arithmetic against public price sheets, not estimates.
|
|
41
|
+
- **Your keys, your perimeter.** `offpeak` talks directly to the providers with your own API keys. There is no proxy and no third party in the data path.
|
|
42
|
+
- **Zero-dependency core.** Provider SDKs load only via extras.
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install "offpeak[all]" # OpenAI + Anthropic venues
|
|
48
|
+
pip install "offpeak[anthropic]" # or one provider
|
|
49
|
+
pip install "offpeak[openai]"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Venues use the standard environment variables (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`), or pass a configured client: `OpenAIBatch(client=my_client)`.
|
|
53
|
+
|
|
54
|
+
## Deadlines
|
|
55
|
+
|
|
56
|
+
Deadlines are how software says "this can wait" — the full semantics live in [SPEC.md](SPEC.md).
|
|
57
|
+
|
|
58
|
+
| Form | Meaning |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `"06:00"` | the next 6am, local time (the canonical overnight form) |
|
|
61
|
+
| `"4h"`, `"90m"`, `"2d"` | relative to now |
|
|
62
|
+
| `"2026-08-21T06:00:00-07:00"` | ISO 8601, absolute |
|
|
63
|
+
| `datetime` / `timedelta` / seconds | native Python forms |
|
|
64
|
+
|
|
65
|
+
## How a run works
|
|
66
|
+
|
|
67
|
+
1. Jobs are grouped by venue (`claude-*` → Anthropic Message Batches, `gpt-*`/`o*` → OpenAI Batch) and submitted at the batch tier — 50% of list.
|
|
68
|
+
2. `offpeak` polls the venues, backing off while the window is long.
|
|
69
|
+
3. When remaining time reaches the **risk buffer** (default: 15% of the window, clamped to 1–10 minutes), unfinished jobs are cancelled and re-run synchronously so the deadline holds. Set `fallback="none"` to report them instead.
|
|
70
|
+
4. Results come back in input order, each with a per-job `Receipt`; `offpeak.receipt(results)` settles the run.
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
results = offpeak.run(
|
|
74
|
+
jobs,
|
|
75
|
+
deadline="06:00",
|
|
76
|
+
fallback="sync", # meet the deadline at list price if the batch is at risk
|
|
77
|
+
risk_buffer=600, # seconds held in reserve (optional)
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Receipts and prices
|
|
82
|
+
|
|
83
|
+
Receipts are computed against a bundled snapshot of public list prices (batch = 50% of list, as published). Providers change prices — verify and override at runtime:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
import offpeak
|
|
87
|
+
|
|
88
|
+
offpeak.prices.register_price("my-fine-tune", input_per_m=4.0, output_per_m=16.0)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Unknown models settle with `cost = None` rather than a guess.
|
|
92
|
+
|
|
93
|
+
## What this is (and the roadmap)
|
|
94
|
+
|
|
95
|
+
`offpeak` is the open client and spec for a simple claim: **intelligence has a time value**. A large share of AI work — embeddings, evals, backfills, report generation, overnight agents — has no human waiting on it, and the venues already price that patience at −50%. This library is the missing workflow.
|
|
96
|
+
|
|
97
|
+
The roadmap follows the same interface upward: more venues (Google batch, spot capacity, off-peak windows on your own GPUs), queue-latency forecasting instead of a fixed risk buffer, portfolio placement across venues, energy- and carbon-aware scheduling with per-job receipts. The venue interface (`offpeak.Venue`) is deliberately the extension point — a venue is anywhere deferred work can run.
|
|
98
|
+
|
|
99
|
+
A hosted desk that does the forecasting, cross-venue portfolio scheduling, and SLA insurance at fleet scale — payloads never leaving your perimeter — is being built by the same team. The SDK and the deadline spec stay open, Apache-2.0.
|
|
100
|
+
|
|
101
|
+
## Contributing
|
|
102
|
+
|
|
103
|
+
Issues and PRs welcome — see [CONTRIBUTING.md](CONTRIBUTING.md). Spec changes start as issues against [SPEC.md](SPEC.md).
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
Apache-2.0 © Offpeak
|
offpeak-0.1.0/SPEC.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# The Deadline Spec — v0.1 (draft)
|
|
2
|
+
|
|
3
|
+
How software says **"this can wait."**
|
|
4
|
+
|
|
5
|
+
Status: draft. The spec is versioned with the library; breaking changes bump the minor version while in 0.x. Changes start as issues on this repository.
|
|
6
|
+
|
|
7
|
+
## 1. Why a spec
|
|
8
|
+
|
|
9
|
+
Every inference API today has exactly one urgency: now. Venues already price patience (public batch tiers at 50% of list), but no annotation exists for a caller to express it. This spec defines that annotation — the *deadline* — so that any client, gateway, queue, or scheduler can carry it, and any venue can honor it.
|
|
10
|
+
|
|
11
|
+
## 2. The deadline
|
|
12
|
+
|
|
13
|
+
A **deadline** is the instant by which a job's result must be available to the caller. It is a property of the *job*, not of the venue or transport.
|
|
14
|
+
|
|
15
|
+
### 2.1 Forms
|
|
16
|
+
|
|
17
|
+
Producers MAY express a deadline in any of these forms; consumers MUST resolve them to an absolute, timezone-aware instant at ingestion time:
|
|
18
|
+
|
|
19
|
+
| Form | Example | Resolution rule |
|
|
20
|
+
| --- | --- | --- |
|
|
21
|
+
| Wall-clock | `"06:00"` | the next occurrence in the producer's timezone: today if still ahead, else tomorrow |
|
|
22
|
+
| Relative | `"4h"`, `"90m"`, `"45s"`, `"2d"` | added to the ingestion instant |
|
|
23
|
+
| Absolute | `"2026-08-21T06:00:00-07:00"` | ISO 8601; a naive timestamp is interpreted in the producer's timezone |
|
|
24
|
+
|
|
25
|
+
Resolved deadlines MUST be in the future at ingestion; a past deadline is an error, never a silent "run now".
|
|
26
|
+
|
|
27
|
+
### 2.2 Wire form
|
|
28
|
+
|
|
29
|
+
In JSON, a resolved deadline is carried as an ISO 8601 string with offset:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{ "deadline": "2026-08-21T06:00:00-07:00" }
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Over HTTP (for gateways and proxies), the request header:
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
Offpeak-Deadline: 2026-08-21T06:00:00-07:00
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
A gateway that receives the header and cannot honor it MUST ignore it and serve the request at standard urgency, never fail it.
|
|
42
|
+
|
|
43
|
+
## 3. Scheduling semantics
|
|
44
|
+
|
|
45
|
+
- A job with a deadline MAY be executed at any time up to the deadline, on any venue that can deliver the result by then. Where it runs and when are the scheduler's choice; *whether* it lands on time is not.
|
|
46
|
+
- A scheduler MUST hold a **fallback path** whose completion time is reliably known (e.g. synchronous execution at list price) and MUST invoke it when the primary venue's completion becomes doubtful within a risk buffer.
|
|
47
|
+
- Work without a deadline is **urgent** and MUST be untouched: never delayed, never re-routed, never repriced.
|
|
48
|
+
|
|
49
|
+
## 4. Outcomes
|
|
50
|
+
|
|
51
|
+
Each job settles in exactly one terminal state:
|
|
52
|
+
|
|
53
|
+
| State | Meaning |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| `succeeded` | completed on the chosen deferred venue, by the deadline |
|
|
56
|
+
| `fell_back` | completed by the deadline via the fallback path (SLA met, spread not captured) |
|
|
57
|
+
| `failed` | not completed by the deadline, or errored |
|
|
58
|
+
|
|
59
|
+
`sla_met` is true iff the result was available at or before the deadline.
|
|
60
|
+
|
|
61
|
+
## 5. The receipt
|
|
62
|
+
|
|
63
|
+
A settlement receipt makes the trade auditable. Per job, a receipt SHOULD carry: venue, model, submission and completion instants, the resolved deadline, token counts, cost paid, equivalent list cost, and the captured spread. Costs MUST be computed against citable public price sheets; where no price is known, the receipt carries `null`, never an estimate presented as fact.
|
|
64
|
+
|
|
65
|
+
Future fields (reserved, optional): `energy_wh`, `co2e_g`, `grid_intensity_gco2_kwh` — measured or cited, labeled as such.
|
|
66
|
+
|
|
67
|
+
## 6. Conformance
|
|
68
|
+
|
|
69
|
+
A **producer** conforms if every deadline it emits resolves per §2. A **scheduler** conforms if it honors §3 and settles §4 states truthfully. A **venue driver** conforms if it reports completion and token usage accurately and supports best-effort cancellation.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
*Maintained at [github.com/offpeak-ai/offpeak](https://github.com/offpeak-ai/offpeak). Apache-2.0.*
|