devupai 1.0.0a1__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.
- devupai-1.0.0a1/.gitignore +25 -0
- devupai-1.0.0a1/CHANGELOG.md +42 -0
- devupai-1.0.0a1/LICENSE +21 -0
- devupai-1.0.0a1/PKG-INFO +221 -0
- devupai-1.0.0a1/README.md +193 -0
- devupai-1.0.0a1/pyproject.toml +78 -0
- devupai-1.0.0a1/src/devupai/__init__.py +85 -0
- devupai-1.0.0a1/src/devupai/_client.py +1154 -0
- devupai-1.0.0a1/src/devupai/_errors.py +314 -0
- devupai-1.0.0a1/src/devupai/_response.py +225 -0
- devupai-1.0.0a1/src/devupai/_streaming.py +515 -0
- devupai-1.0.0a1/src/devupai/_version.py +3 -0
- devupai-1.0.0a1/src/devupai/py.typed +0 -0
- devupai-1.0.0a1/src/devupai/resources/__init__.py +137 -0
- devupai-1.0.0a1/src/devupai/resources/_base.py +207 -0
- devupai-1.0.0a1/src/devupai/resources/audio.py +663 -0
- devupai-1.0.0a1/src/devupai/resources/balance.py +103 -0
- devupai-1.0.0a1/src/devupai/resources/chat.py +428 -0
- devupai-1.0.0a1/src/devupai/resources/embeddings.py +141 -0
- devupai-1.0.0a1/src/devupai/resources/health.py +113 -0
- devupai-1.0.0a1/src/devupai/resources/images.py +503 -0
- devupai-1.0.0a1/src/devupai/resources/inference.py +347 -0
- devupai-1.0.0a1/src/devupai/resources/me.py +208 -0
- devupai-1.0.0a1/src/devupai/resources/models.py +405 -0
- devupai-1.0.0a1/src/devupai/resources/rerank.py +147 -0
- devupai-1.0.0a1/src/devupai/resources/responses.py +400 -0
- devupai-1.0.0a1/src/devupai/resources/shared.py +314 -0
- devupai-1.0.0a1/src/devupai/resources/video.py +600 -0
- devupai-1.0.0a1/src/devupai/types/__init__.py +264 -0
- devupai-1.0.0a1/src/devupai/types/_base.py +167 -0
- devupai-1.0.0a1/src/devupai/types/account.py +48 -0
- devupai-1.0.0a1/src/devupai/types/audio.py +89 -0
- devupai-1.0.0a1/src/devupai/types/chat.py +284 -0
- devupai-1.0.0a1/src/devupai/types/embeddings.py +51 -0
- devupai-1.0.0a1/src/devupai/types/images.py +238 -0
- devupai-1.0.0a1/src/devupai/types/models.py +107 -0
- devupai-1.0.0a1/src/devupai/types/rerank.py +41 -0
- devupai-1.0.0a1/src/devupai/types/responses.py +219 -0
- devupai-1.0.0a1/src/devupai/types/shared.py +79 -0
- devupai-1.0.0a1/src/devupai/types/video.py +218 -0
- devupai-1.0.0a1/src/devupai/types/webhooks.py +61 -0
- devupai-1.0.0a1/src/devupai/webhooks.py +278 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Virtual environments
|
|
2
|
+
.venv/
|
|
3
|
+
.venv314/
|
|
4
|
+
.venv*/
|
|
5
|
+
|
|
6
|
+
# Bytecode and tool state folders
|
|
7
|
+
__pycache__/
|
|
8
|
+
*.py[cod]
|
|
9
|
+
.pytest_*/
|
|
10
|
+
.mypy_*/
|
|
11
|
+
.ruff_*/
|
|
12
|
+
|
|
13
|
+
# Coverage
|
|
14
|
+
.coverage
|
|
15
|
+
.coverage.*
|
|
16
|
+
htmlcov/
|
|
17
|
+
|
|
18
|
+
# Build output
|
|
19
|
+
dist/
|
|
20
|
+
build/
|
|
21
|
+
*.egg-info/
|
|
22
|
+
|
|
23
|
+
# Local settings
|
|
24
|
+
.env
|
|
25
|
+
.env.*
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the `devupai` Python package are documented in this file.
|
|
4
|
+
|
|
5
|
+
## [1.0.0a1]
|
|
6
|
+
|
|
7
|
+
The first pre-release of the official Python SDK for the DEVUP AI API, with a
|
|
8
|
+
synchronous client (`DevupAI`) and an asynchronous client (`AsyncDevupAI`).
|
|
9
|
+
It needs Python 3.11 or later. Install it with `pip install --pre devupai`.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `client.chat.completions.create()` and `client.responses.create()`, with
|
|
14
|
+
JSON responses and `stream=True`. A stream is an iterator (`async for` on
|
|
15
|
+
`AsyncDevupAI`) that also works in a `with` block, and its `request_id` and
|
|
16
|
+
`warnings` are readable before the first chunk.
|
|
17
|
+
- `client.models.list()` and `client.models.retrieve()`.
|
|
18
|
+
- `client.images.generate()`, `client.images.edit()` and
|
|
19
|
+
`client.images.download()`.
|
|
20
|
+
- `client.embeddings.create()` and `client.rerank.create()`.
|
|
21
|
+
- `client.audio.speech.create()` and `client.audio.transcriptions.create()`.
|
|
22
|
+
- `client.video.generations.create()` and `client.video.edits.create()`.
|
|
23
|
+
- `client.inference.run()`, with JSON or binary results.
|
|
24
|
+
- `client.balance.retrieve()`, `client.me.retrieve()`, `client.me.avatar()`
|
|
25
|
+
and `client.health.check()`.
|
|
26
|
+
- File uploads from `bytes`, a binary file object, a `pathlib.Path` or a
|
|
27
|
+
`(filename, content, content_type)` tuple. The SDK closes the files it opens
|
|
28
|
+
from a path and never closes a file object you pass.
|
|
29
|
+
- `BinaryResponse` and `AsyncBinaryResponse` for binary results, with
|
|
30
|
+
`read()`, `iter_bytes()` and `write_to_file()`.
|
|
31
|
+
- `with_response` on each resource that calls the API, to read the status
|
|
32
|
+
code, headers and `request_id` together with the parsed result.
|
|
33
|
+
- Webhook signature verification: `client.webhooks.verify_signature()`,
|
|
34
|
+
`client.webhooks.construct_event()`, `verify_webhook_signature()` and
|
|
35
|
+
`construct_webhook_event()`.
|
|
36
|
+
- Error classes for each HTTP status the API documents, all subclasses of
|
|
37
|
+
`DevupAPIError`, plus `APIConnectionError` and `APITimeoutError`.
|
|
38
|
+
`error.code` names the reason, and `error.request_id` identifies the request.
|
|
39
|
+
- Retries with backoff for requests that are safe to send again. A billed
|
|
40
|
+
request is sent again only after a 429 or 503 answer, or when the
|
|
41
|
+
connection could not be opened.
|
|
42
|
+
- Type hints for every request and response (`py.typed`).
|
devupai-1.0.0a1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DEVUP AI
|
|
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.
|
devupai-1.0.0a1/PKG-INFO
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: devupai
|
|
3
|
+
Version: 1.0.0a1
|
|
4
|
+
Summary: Official Python SDK for the DEVUP AI API, with billing in DZD.
|
|
5
|
+
Project-URL: Homepage, https://github.com/devupai-platform/devupai-python#readme
|
|
6
|
+
Project-URL: Repository, https://github.com/devupai-platform/devupai-python
|
|
7
|
+
Project-URL: Issues, https://github.com/devupai-platform/devupai-python/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/devupai-platform/devupai-python/blob/main/CHANGELOG.md
|
|
9
|
+
Author: DEVUP AI
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ai,api,devup,devupai,dzd,sdk
|
|
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 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.11
|
|
25
|
+
Requires-Dist: httpx<1,>=0.28.1
|
|
26
|
+
Requires-Dist: pydantic<3,>=2.10
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# DEVUP AI Python SDK
|
|
30
|
+
|
|
31
|
+
The official Python SDK for the DEVUP AI API, with a synchronous client,
|
|
32
|
+
`DevupAI`, and an asynchronous client, `AsyncDevupAI`.
|
|
33
|
+
|
|
34
|
+
## Requirements
|
|
35
|
+
|
|
36
|
+
Python 3.11 or later.
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install --pre devupai
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Version 1.0.0 removes the need for `--pre`.
|
|
45
|
+
|
|
46
|
+
## Create a client
|
|
47
|
+
|
|
48
|
+
Synchronous client:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from devupai import DevupAI
|
|
52
|
+
|
|
53
|
+
with DevupAI() as client:
|
|
54
|
+
print(client.base_url)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Asynchronous client:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
import asyncio
|
|
61
|
+
|
|
62
|
+
from devupai import AsyncDevupAI
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
async def main() -> None:
|
|
66
|
+
async with AsyncDevupAI() as client:
|
|
67
|
+
print(client.base_url)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
asyncio.run(main())
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
You can also pass the key yourself:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from devupai import DevupAI
|
|
77
|
+
|
|
78
|
+
client = DevupAI(api_key="your-api-key")
|
|
79
|
+
try:
|
|
80
|
+
print(client.base_url)
|
|
81
|
+
finally:
|
|
82
|
+
client.close()
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Without a `with` block, call `client.close()` (or `await client.close()` for
|
|
86
|
+
`AsyncDevupAI`) when you are done. Closing a client more than once is allowed.
|
|
87
|
+
|
|
88
|
+
## API key
|
|
89
|
+
|
|
90
|
+
The client takes the API key from the first of these that is set:
|
|
91
|
+
|
|
92
|
+
1. The `api_key` argument.
|
|
93
|
+
2. The `DEVUP_API_KEY` environment variable.
|
|
94
|
+
3. The `DEVUPAI_API_KEY` environment variable. It is read only when
|
|
95
|
+
`DEVUP_API_KEY` is not set at all.
|
|
96
|
+
|
|
97
|
+
When none of them is set, or the environment variable is empty, creating the
|
|
98
|
+
client raises `ValueError`. A key that contains a line break or a NUL
|
|
99
|
+
character also raises `ValueError`.
|
|
100
|
+
|
|
101
|
+
`api_key=""` is allowed: the client then sends an empty key, which is useful
|
|
102
|
+
only for requests that do not need one.
|
|
103
|
+
|
|
104
|
+
## Options
|
|
105
|
+
|
|
106
|
+
Every option is a keyword argument, and both clients take the same options.
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from devupai import DevupAI
|
|
110
|
+
|
|
111
|
+
client = DevupAI(
|
|
112
|
+
api_key="your-api-key",
|
|
113
|
+
base_url="https://api.devupai.com/v1",
|
|
114
|
+
timeout=60.0,
|
|
115
|
+
max_retries=2,
|
|
116
|
+
default_headers={"X-Application-Name": "my-application"},
|
|
117
|
+
)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
| Option | Type | Default | Description |
|
|
121
|
+
| ----------------- | --------------------------------------- | ---------------------------- | ----------- |
|
|
122
|
+
| `api_key` | `str \| None` | See [API key](#api-key) | Your DEVUP AI API key. |
|
|
123
|
+
| `base_url` | `str \| None` | `https://api.devupai.com/v1` | DEVUP AI API base URL. A trailing `/` is removed. It must be an absolute `http` or `https` URL without a user name or password (`ValueError` otherwise). |
|
|
124
|
+
| `timeout` | `float \| None` | `600.0` (10 minutes) | Seconds. One limit for the whole call, retries included. The Node.js SDK takes this value in milliseconds; this SDK takes seconds. |
|
|
125
|
+
| `max_retries` | `int \| None` | `2` | How many times a request is sent again. See [Retries](#retries). |
|
|
126
|
+
| `default_headers` | `Mapping[str, str] \| None` | — | Headers included in every request. |
|
|
127
|
+
| `http_client` | `httpx.Client` / `httpx.AsyncClient` | A client the SDK creates | Your own `httpx.Client` (for `DevupAI`) or `httpx.AsyncClient` (for `AsyncDevupAI`). Only its transport, connection pool and event hooks apply: its own `auth`, base URL, headers, query parameters, cookies and timeouts are not used (each request takes the `timeout` of this client or of the call). The SDK never closes a client you pass. |
|
|
128
|
+
| `on_debug` | `Callable[[DebugEvent], None] \| None` | — | Receives debug events, such as `retry` before each retry. An exception raised in it is ignored. |
|
|
129
|
+
|
|
130
|
+
`timeout` must be a positive number of seconds, and `max_retries` a
|
|
131
|
+
non-negative integer. A wrong type raises `TypeError` and a wrong value raises
|
|
132
|
+
`ValueError`, before any request is sent.
|
|
133
|
+
|
|
134
|
+
The SDK sends `User-Agent: devupai-python/<version>`. It manages the
|
|
135
|
+
`Authorization` and `Content-Type` headers itself; custom headers cannot
|
|
136
|
+
override them. Redirects are not followed.
|
|
137
|
+
|
|
138
|
+
## Retries
|
|
139
|
+
|
|
140
|
+
The client sends a request again, up to `max_retries` times (default 2), after
|
|
141
|
+
a 408, 429, 502, 503 or 504 answer, or a connection error.
|
|
142
|
+
|
|
143
|
+
| Requests | Sent again after |
|
|
144
|
+
| -------- | ---------------- |
|
|
145
|
+
| Billed requests: chat completions, Responses, embeddings, rerank, image generation and edits, audio, video, and native inference | 429 and 503, and a connection that could not be opened |
|
|
146
|
+
| Other requests | 408, 429, 502, 503, and 504, and connection errors |
|
|
147
|
+
|
|
148
|
+
A billed request is sent again only after a 429 or 503 answer, or when the
|
|
149
|
+
connection could not be opened. After any other answer, or a connection lost
|
|
150
|
+
after the request may have been sent, the error is returned to you without a
|
|
151
|
+
retry, because the request may already have been processed and charged.
|
|
152
|
+
|
|
153
|
+
A 500 answer is not retried.
|
|
154
|
+
|
|
155
|
+
When the answer has a `retry-after-ms` or `Retry-After` header, the client
|
|
156
|
+
waits that long before the next attempt. Otherwise it waits a random time that
|
|
157
|
+
grows with each attempt, at most 60 seconds between attempts. A wait that does
|
|
158
|
+
not fit in the time left of `timeout` ends the call with the error.
|
|
159
|
+
|
|
160
|
+
`max_retries=0` turns retries off.
|
|
161
|
+
|
|
162
|
+
## Errors
|
|
163
|
+
|
|
164
|
+
Every error from the API is a `DevupAPIError`. The SDK raises the subclass
|
|
165
|
+
that matches the HTTP status, so you can catch a specific case or the base
|
|
166
|
+
class. All the classes below are subclasses of `DevupAPIError`.
|
|
167
|
+
|
|
168
|
+
| Class | Status | Notes |
|
|
169
|
+
| --------------------------- | ---------- | ----- |
|
|
170
|
+
| `BadRequestError` | 400 | The request is not valid as sent; `code` names the reason. |
|
|
171
|
+
| `AuthenticationError` | 401 | Missing or invalid API key. |
|
|
172
|
+
| `PaymentRequiredError` | 402 | The balance does not cover the request (`insufficient_balance`), or a scoped credential reached its budget (`budget_exhausted`). |
|
|
173
|
+
| `PermissionDeniedError` | 403 | The key cannot use this resource. |
|
|
174
|
+
| `NotFoundError` | 404 | For example, an unknown model. |
|
|
175
|
+
| `ConflictError` | 409 | The outcome of this request is not confirmed yet (`request_outcome_pending`). Do not send it again: contact support with `request_id`. |
|
|
176
|
+
| `PayloadTooLargeError` | 413 | The request body is larger than the limit (`payload_too_large`). |
|
|
177
|
+
| `UnsupportedMediaTypeError` | 415 | The model does not accept the content type of the request. Send the `Content-Type` and body format that the API reference lists for the endpoint. |
|
|
178
|
+
| `UnprocessableEntityError` | 422 | The request was not accepted in its current form. |
|
|
179
|
+
| `RateLimitError` | 429 | Read `retry_after_ms` for the suggested wait. |
|
|
180
|
+
| `InternalServerError` | 500 and up | After a 500 or 502 the request may already have been processed and charged: check its outcome before sending it again. |
|
|
181
|
+
| `APIConnectionError` | `0` | The API could not be reached. |
|
|
182
|
+
| `APITimeoutError` | `0` | The call exceeded `timeout`. A subclass of `APIConnectionError`. |
|
|
183
|
+
| `DevupAPIError` | other | Any other status. |
|
|
184
|
+
|
|
185
|
+
| Field | Type | Description |
|
|
186
|
+
| ------------------- | ---------------- | ----------- |
|
|
187
|
+
| `status` | `int` | HTTP status code, or `0` for connection errors and timeouts. |
|
|
188
|
+
| `message` | `str` | Human-readable error message (also `str(err)`). |
|
|
189
|
+
| `code` | `str \| None` | Machine-readable error code, when available. |
|
|
190
|
+
| `type` | `str \| None` | Error category, when available. |
|
|
191
|
+
| `param` | `str \| None` | The request parameter the error refers to, when available. |
|
|
192
|
+
| `request_id` | `str \| None` | The `x-request-id` header. Include it when you contact support. |
|
|
193
|
+
| `client_request_id` | `str \| None` | The `x-client-request-id` header. |
|
|
194
|
+
| `retry_after` | `str \| None` | Raw `Retry-After` header value. |
|
|
195
|
+
| `retry_after_ms` | `float \| None` | Suggested wait in milliseconds, when the answer gives one. |
|
|
196
|
+
| `warnings` | `list[str]` | Notice codes from the `X-DEVUP-Warnings` header (empty when none). |
|
|
197
|
+
| `headers` | `dict[str, str]` | Response headers, with lower-case names. |
|
|
198
|
+
|
|
199
|
+
The underlying exception, when there is one, is chained as `__cause__`.
|
|
200
|
+
|
|
201
|
+
A 409 means the outcome of the request is not confirmed yet. Do not send it
|
|
202
|
+
again: contact support with its `request_id`.
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
from devupai import DevupAPIError, RateLimitError
|
|
206
|
+
|
|
207
|
+
try:
|
|
208
|
+
... # a call to the DEVUP AI API
|
|
209
|
+
except RateLimitError as err:
|
|
210
|
+
print(err.retry_after_ms)
|
|
211
|
+
except DevupAPIError as err:
|
|
212
|
+
print(err.status, err.code, err.request_id)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
The error codes you can act on are listed at
|
|
216
|
+
[docs.devupai.com/docs/errors](https://docs.devupai.com/docs/errors).
|
|
217
|
+
|
|
218
|
+
## License
|
|
219
|
+
|
|
220
|
+
The DEVUP AI Python SDK is released under the
|
|
221
|
+
[MIT License](https://github.com/devupai-platform/devupai-python/blob/main/LICENSE).
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# DEVUP AI Python SDK
|
|
2
|
+
|
|
3
|
+
The official Python SDK for the DEVUP AI API, with a synchronous client,
|
|
4
|
+
`DevupAI`, and an asynchronous client, `AsyncDevupAI`.
|
|
5
|
+
|
|
6
|
+
## Requirements
|
|
7
|
+
|
|
8
|
+
Python 3.11 or later.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install --pre devupai
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Version 1.0.0 removes the need for `--pre`.
|
|
17
|
+
|
|
18
|
+
## Create a client
|
|
19
|
+
|
|
20
|
+
Synchronous client:
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from devupai import DevupAI
|
|
24
|
+
|
|
25
|
+
with DevupAI() as client:
|
|
26
|
+
print(client.base_url)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Asynchronous client:
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import asyncio
|
|
33
|
+
|
|
34
|
+
from devupai import AsyncDevupAI
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
async def main() -> None:
|
|
38
|
+
async with AsyncDevupAI() as client:
|
|
39
|
+
print(client.base_url)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
asyncio.run(main())
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
You can also pass the key yourself:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from devupai import DevupAI
|
|
49
|
+
|
|
50
|
+
client = DevupAI(api_key="your-api-key")
|
|
51
|
+
try:
|
|
52
|
+
print(client.base_url)
|
|
53
|
+
finally:
|
|
54
|
+
client.close()
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Without a `with` block, call `client.close()` (or `await client.close()` for
|
|
58
|
+
`AsyncDevupAI`) when you are done. Closing a client more than once is allowed.
|
|
59
|
+
|
|
60
|
+
## API key
|
|
61
|
+
|
|
62
|
+
The client takes the API key from the first of these that is set:
|
|
63
|
+
|
|
64
|
+
1. The `api_key` argument.
|
|
65
|
+
2. The `DEVUP_API_KEY` environment variable.
|
|
66
|
+
3. The `DEVUPAI_API_KEY` environment variable. It is read only when
|
|
67
|
+
`DEVUP_API_KEY` is not set at all.
|
|
68
|
+
|
|
69
|
+
When none of them is set, or the environment variable is empty, creating the
|
|
70
|
+
client raises `ValueError`. A key that contains a line break or a NUL
|
|
71
|
+
character also raises `ValueError`.
|
|
72
|
+
|
|
73
|
+
`api_key=""` is allowed: the client then sends an empty key, which is useful
|
|
74
|
+
only for requests that do not need one.
|
|
75
|
+
|
|
76
|
+
## Options
|
|
77
|
+
|
|
78
|
+
Every option is a keyword argument, and both clients take the same options.
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from devupai import DevupAI
|
|
82
|
+
|
|
83
|
+
client = DevupAI(
|
|
84
|
+
api_key="your-api-key",
|
|
85
|
+
base_url="https://api.devupai.com/v1",
|
|
86
|
+
timeout=60.0,
|
|
87
|
+
max_retries=2,
|
|
88
|
+
default_headers={"X-Application-Name": "my-application"},
|
|
89
|
+
)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
| Option | Type | Default | Description |
|
|
93
|
+
| ----------------- | --------------------------------------- | ---------------------------- | ----------- |
|
|
94
|
+
| `api_key` | `str \| None` | See [API key](#api-key) | Your DEVUP AI API key. |
|
|
95
|
+
| `base_url` | `str \| None` | `https://api.devupai.com/v1` | DEVUP AI API base URL. A trailing `/` is removed. It must be an absolute `http` or `https` URL without a user name or password (`ValueError` otherwise). |
|
|
96
|
+
| `timeout` | `float \| None` | `600.0` (10 minutes) | Seconds. One limit for the whole call, retries included. The Node.js SDK takes this value in milliseconds; this SDK takes seconds. |
|
|
97
|
+
| `max_retries` | `int \| None` | `2` | How many times a request is sent again. See [Retries](#retries). |
|
|
98
|
+
| `default_headers` | `Mapping[str, str] \| None` | — | Headers included in every request. |
|
|
99
|
+
| `http_client` | `httpx.Client` / `httpx.AsyncClient` | A client the SDK creates | Your own `httpx.Client` (for `DevupAI`) or `httpx.AsyncClient` (for `AsyncDevupAI`). Only its transport, connection pool and event hooks apply: its own `auth`, base URL, headers, query parameters, cookies and timeouts are not used (each request takes the `timeout` of this client or of the call). The SDK never closes a client you pass. |
|
|
100
|
+
| `on_debug` | `Callable[[DebugEvent], None] \| None` | — | Receives debug events, such as `retry` before each retry. An exception raised in it is ignored. |
|
|
101
|
+
|
|
102
|
+
`timeout` must be a positive number of seconds, and `max_retries` a
|
|
103
|
+
non-negative integer. A wrong type raises `TypeError` and a wrong value raises
|
|
104
|
+
`ValueError`, before any request is sent.
|
|
105
|
+
|
|
106
|
+
The SDK sends `User-Agent: devupai-python/<version>`. It manages the
|
|
107
|
+
`Authorization` and `Content-Type` headers itself; custom headers cannot
|
|
108
|
+
override them. Redirects are not followed.
|
|
109
|
+
|
|
110
|
+
## Retries
|
|
111
|
+
|
|
112
|
+
The client sends a request again, up to `max_retries` times (default 2), after
|
|
113
|
+
a 408, 429, 502, 503 or 504 answer, or a connection error.
|
|
114
|
+
|
|
115
|
+
| Requests | Sent again after |
|
|
116
|
+
| -------- | ---------------- |
|
|
117
|
+
| Billed requests: chat completions, Responses, embeddings, rerank, image generation and edits, audio, video, and native inference | 429 and 503, and a connection that could not be opened |
|
|
118
|
+
| Other requests | 408, 429, 502, 503, and 504, and connection errors |
|
|
119
|
+
|
|
120
|
+
A billed request is sent again only after a 429 or 503 answer, or when the
|
|
121
|
+
connection could not be opened. After any other answer, or a connection lost
|
|
122
|
+
after the request may have been sent, the error is returned to you without a
|
|
123
|
+
retry, because the request may already have been processed and charged.
|
|
124
|
+
|
|
125
|
+
A 500 answer is not retried.
|
|
126
|
+
|
|
127
|
+
When the answer has a `retry-after-ms` or `Retry-After` header, the client
|
|
128
|
+
waits that long before the next attempt. Otherwise it waits a random time that
|
|
129
|
+
grows with each attempt, at most 60 seconds between attempts. A wait that does
|
|
130
|
+
not fit in the time left of `timeout` ends the call with the error.
|
|
131
|
+
|
|
132
|
+
`max_retries=0` turns retries off.
|
|
133
|
+
|
|
134
|
+
## Errors
|
|
135
|
+
|
|
136
|
+
Every error from the API is a `DevupAPIError`. The SDK raises the subclass
|
|
137
|
+
that matches the HTTP status, so you can catch a specific case or the base
|
|
138
|
+
class. All the classes below are subclasses of `DevupAPIError`.
|
|
139
|
+
|
|
140
|
+
| Class | Status | Notes |
|
|
141
|
+
| --------------------------- | ---------- | ----- |
|
|
142
|
+
| `BadRequestError` | 400 | The request is not valid as sent; `code` names the reason. |
|
|
143
|
+
| `AuthenticationError` | 401 | Missing or invalid API key. |
|
|
144
|
+
| `PaymentRequiredError` | 402 | The balance does not cover the request (`insufficient_balance`), or a scoped credential reached its budget (`budget_exhausted`). |
|
|
145
|
+
| `PermissionDeniedError` | 403 | The key cannot use this resource. |
|
|
146
|
+
| `NotFoundError` | 404 | For example, an unknown model. |
|
|
147
|
+
| `ConflictError` | 409 | The outcome of this request is not confirmed yet (`request_outcome_pending`). Do not send it again: contact support with `request_id`. |
|
|
148
|
+
| `PayloadTooLargeError` | 413 | The request body is larger than the limit (`payload_too_large`). |
|
|
149
|
+
| `UnsupportedMediaTypeError` | 415 | The model does not accept the content type of the request. Send the `Content-Type` and body format that the API reference lists for the endpoint. |
|
|
150
|
+
| `UnprocessableEntityError` | 422 | The request was not accepted in its current form. |
|
|
151
|
+
| `RateLimitError` | 429 | Read `retry_after_ms` for the suggested wait. |
|
|
152
|
+
| `InternalServerError` | 500 and up | After a 500 or 502 the request may already have been processed and charged: check its outcome before sending it again. |
|
|
153
|
+
| `APIConnectionError` | `0` | The API could not be reached. |
|
|
154
|
+
| `APITimeoutError` | `0` | The call exceeded `timeout`. A subclass of `APIConnectionError`. |
|
|
155
|
+
| `DevupAPIError` | other | Any other status. |
|
|
156
|
+
|
|
157
|
+
| Field | Type | Description |
|
|
158
|
+
| ------------------- | ---------------- | ----------- |
|
|
159
|
+
| `status` | `int` | HTTP status code, or `0` for connection errors and timeouts. |
|
|
160
|
+
| `message` | `str` | Human-readable error message (also `str(err)`). |
|
|
161
|
+
| `code` | `str \| None` | Machine-readable error code, when available. |
|
|
162
|
+
| `type` | `str \| None` | Error category, when available. |
|
|
163
|
+
| `param` | `str \| None` | The request parameter the error refers to, when available. |
|
|
164
|
+
| `request_id` | `str \| None` | The `x-request-id` header. Include it when you contact support. |
|
|
165
|
+
| `client_request_id` | `str \| None` | The `x-client-request-id` header. |
|
|
166
|
+
| `retry_after` | `str \| None` | Raw `Retry-After` header value. |
|
|
167
|
+
| `retry_after_ms` | `float \| None` | Suggested wait in milliseconds, when the answer gives one. |
|
|
168
|
+
| `warnings` | `list[str]` | Notice codes from the `X-DEVUP-Warnings` header (empty when none). |
|
|
169
|
+
| `headers` | `dict[str, str]` | Response headers, with lower-case names. |
|
|
170
|
+
|
|
171
|
+
The underlying exception, when there is one, is chained as `__cause__`.
|
|
172
|
+
|
|
173
|
+
A 409 means the outcome of the request is not confirmed yet. Do not send it
|
|
174
|
+
again: contact support with its `request_id`.
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
from devupai import DevupAPIError, RateLimitError
|
|
178
|
+
|
|
179
|
+
try:
|
|
180
|
+
... # a call to the DEVUP AI API
|
|
181
|
+
except RateLimitError as err:
|
|
182
|
+
print(err.retry_after_ms)
|
|
183
|
+
except DevupAPIError as err:
|
|
184
|
+
print(err.status, err.code, err.request_id)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
The error codes you can act on are listed at
|
|
188
|
+
[docs.devupai.com/docs/errors](https://docs.devupai.com/docs/errors).
|
|
189
|
+
|
|
190
|
+
## License
|
|
191
|
+
|
|
192
|
+
The DEVUP AI Python SDK is released under the
|
|
193
|
+
[MIT License](https://github.com/devupai-platform/devupai-python/blob/main/LICENSE).
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling==1.33.0"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "devupai"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Official Python SDK for the DEVUP AI API, with billing in DZD."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.11"
|
|
13
|
+
authors = [{ name = "DEVUP AI" }]
|
|
14
|
+
keywords = ["devupai", "devup", "ai", "api", "sdk", "dzd"]
|
|
15
|
+
dependencies = [
|
|
16
|
+
"httpx>=0.28.1,<1",
|
|
17
|
+
"pydantic>=2.10,<3",
|
|
18
|
+
]
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Development Status :: 3 - Alpha",
|
|
21
|
+
"Intended Audience :: Developers",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
"Programming Language :: Python :: 3",
|
|
24
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: Python :: 3.13",
|
|
28
|
+
"Programming Language :: Python :: 3.14",
|
|
29
|
+
"Programming Language :: Python :: 3.15",
|
|
30
|
+
"Typing :: Typed",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://github.com/devupai-platform/devupai-python#readme"
|
|
35
|
+
Repository = "https://github.com/devupai-platform/devupai-python"
|
|
36
|
+
Issues = "https://github.com/devupai-platform/devupai-python/issues"
|
|
37
|
+
Changelog = "https://github.com/devupai-platform/devupai-python/blob/main/CHANGELOG.md"
|
|
38
|
+
|
|
39
|
+
[tool.hatch.version]
|
|
40
|
+
path = "src/devupai/_version.py"
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.wheel]
|
|
43
|
+
packages = ["src/devupai"]
|
|
44
|
+
|
|
45
|
+
[tool.hatch.build.targets.sdist]
|
|
46
|
+
include = [
|
|
47
|
+
"src/devupai",
|
|
48
|
+
"README.md",
|
|
49
|
+
"CHANGELOG.md",
|
|
50
|
+
"LICENSE",
|
|
51
|
+
"pyproject.toml",
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
[tool.pytest.ini_options]
|
|
55
|
+
testpaths = ["tests"]
|
|
56
|
+
pythonpath = ["src", "tests", "scripts"]
|
|
57
|
+
addopts = "-ra --strict-markers --strict-config"
|
|
58
|
+
xfail_strict = true
|
|
59
|
+
|
|
60
|
+
[tool.mypy]
|
|
61
|
+
strict = true
|
|
62
|
+
python_version = "3.11"
|
|
63
|
+
files = ["src", "scripts", "tests/type_checks"]
|
|
64
|
+
|
|
65
|
+
[tool.pyright]
|
|
66
|
+
include = ["src", "scripts", "tests/type_checks"]
|
|
67
|
+
typeCheckingMode = "strict"
|
|
68
|
+
pythonVersion = "3.11"
|
|
69
|
+
|
|
70
|
+
[tool.ruff]
|
|
71
|
+
target-version = "py311"
|
|
72
|
+
line-length = 120
|
|
73
|
+
|
|
74
|
+
[tool.ruff.lint]
|
|
75
|
+
select = ["E", "F", "W", "I", "UP", "B"]
|
|
76
|
+
|
|
77
|
+
[tool.ruff.lint.isort]
|
|
78
|
+
known-first-party = ["devupai"]
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""The official Python client for the DEVUP AI API.
|
|
2
|
+
|
|
3
|
+
Create a client and call the API::
|
|
4
|
+
|
|
5
|
+
from devupai import DevupAI
|
|
6
|
+
|
|
7
|
+
client = DevupAI() # reads the key from DEVUP_API_KEY, then DEVUPAI_API_KEY
|
|
8
|
+
|
|
9
|
+
``AsyncDevupAI`` offers the same options for ``asyncio`` code. ``create(stream=True)`` returns a ``Stream`` (an
|
|
10
|
+
``AsyncStream`` on the async client), and a binary result is a ``BinaryResponse`` (``AsyncBinaryResponse``).
|
|
11
|
+
|
|
12
|
+
An answer or a connection problem raises a subclass of ``DevupAPIError`` (``APIConnectionError`` when no response
|
|
13
|
+
was received); a webhook that cannot be verified raises ``DevupWebhookVerificationError``. An option or header value
|
|
14
|
+
that is not valid raises ``TypeError`` or ``ValueError`` before anything is sent, and a closed client raises
|
|
15
|
+
``RuntimeError``.
|
|
16
|
+
|
|
17
|
+
Request parameter and response types live in ``devupai.types``. Webhook signatures are checked with
|
|
18
|
+
``client.webhooks``, or with ``verify_webhook_signature`` and ``construct_webhook_event`` without a client.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from devupai import types
|
|
22
|
+
from devupai._client import AsyncDevupAI, DebugEvent, DevupAI, RequestOptions
|
|
23
|
+
from devupai._errors import (
|
|
24
|
+
APIConnectionError,
|
|
25
|
+
APITimeoutError,
|
|
26
|
+
AuthenticationError,
|
|
27
|
+
BadRequestError,
|
|
28
|
+
ConflictError,
|
|
29
|
+
DevupAPIError,
|
|
30
|
+
DevupWebhookVerificationError,
|
|
31
|
+
InternalServerError,
|
|
32
|
+
NotFoundError,
|
|
33
|
+
PayloadTooLargeError,
|
|
34
|
+
PaymentRequiredError,
|
|
35
|
+
PermissionDeniedError,
|
|
36
|
+
RateLimitError,
|
|
37
|
+
UnprocessableEntityError,
|
|
38
|
+
UnsupportedMediaTypeError,
|
|
39
|
+
)
|
|
40
|
+
from devupai._response import APIResponse, AsyncBinaryResponse, BinaryResponse
|
|
41
|
+
from devupai._streaming import AsyncStream, Stream
|
|
42
|
+
from devupai._version import __version__
|
|
43
|
+
from devupai.webhooks import Webhooks, construct_webhook_event, verify_webhook_signature
|
|
44
|
+
|
|
45
|
+
VERSION: str = __version__
|
|
46
|
+
"""The version of this package, the same value as ``__version__``."""
|
|
47
|
+
|
|
48
|
+
__all__ = [
|
|
49
|
+
# Clients and responses.
|
|
50
|
+
"DevupAI",
|
|
51
|
+
"AsyncDevupAI",
|
|
52
|
+
"APIResponse",
|
|
53
|
+
"DebugEvent",
|
|
54
|
+
"RequestOptions",
|
|
55
|
+
# Streams and binary results.
|
|
56
|
+
"Stream",
|
|
57
|
+
"AsyncStream",
|
|
58
|
+
"BinaryResponse",
|
|
59
|
+
"AsyncBinaryResponse",
|
|
60
|
+
# Version.
|
|
61
|
+
"VERSION",
|
|
62
|
+
"__version__",
|
|
63
|
+
# Errors.
|
|
64
|
+
"DevupAPIError",
|
|
65
|
+
"BadRequestError",
|
|
66
|
+
"AuthenticationError",
|
|
67
|
+
"PaymentRequiredError",
|
|
68
|
+
"PermissionDeniedError",
|
|
69
|
+
"NotFoundError",
|
|
70
|
+
"ConflictError",
|
|
71
|
+
"PayloadTooLargeError",
|
|
72
|
+
"UnsupportedMediaTypeError",
|
|
73
|
+
"UnprocessableEntityError",
|
|
74
|
+
"RateLimitError",
|
|
75
|
+
"InternalServerError",
|
|
76
|
+
"APIConnectionError",
|
|
77
|
+
"APITimeoutError",
|
|
78
|
+
"DevupWebhookVerificationError",
|
|
79
|
+
# Webhooks.
|
|
80
|
+
"Webhooks",
|
|
81
|
+
"verify_webhook_signature",
|
|
82
|
+
"construct_webhook_event",
|
|
83
|
+
# Request parameter and response types.
|
|
84
|
+
"types",
|
|
85
|
+
]
|