visionai-sdk-python 2.2.0.dev7__tar.gz → 2.3.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.
Files changed (67) hide show
  1. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/.github/workflows/ci.yml +2 -0
  2. {visionai_sdk_python-2.2.0.dev7/src/visionai_sdk_python.egg-info → visionai_sdk_python-2.3.0}/PKG-INFO +28 -2
  3. visionai_sdk_python-2.2.0.dev7/PKG-INFO → visionai_sdk_python-2.3.0/README.md +25 -19
  4. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/docs/relay-protocol.md +6 -3
  5. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/pyproject.toml +2 -0
  6. visionai_sdk_python-2.3.0/src/visionai_sdk_python/exceptions.py +150 -0
  7. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/instrumentation.py +12 -4
  8. visionai_sdk_python-2.2.0.dev7/README.md → visionai_sdk_python-2.3.0/src/visionai_sdk_python.egg-info/PKG-INFO +45 -1
  9. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python.egg-info/SOURCES.txt +1 -0
  10. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python.egg-info/requires.txt +3 -0
  11. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python.egg-info/scm_file_list.json +1 -0
  12. visionai_sdk_python-2.3.0/src/visionai_sdk_python.egg-info/scm_version.json +8 -0
  13. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/tests/constants.py +7 -0
  14. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/tests/test_client.py +17 -2
  15. visionai_sdk_python-2.3.0/tests/test_exceptions.py +129 -0
  16. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/tests/test_instrumentation.py +25 -16
  17. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/uv.lock +59 -5
  18. visionai_sdk_python-2.2.0.dev7/src/visionai_sdk_python/exceptions.py +0 -97
  19. visionai_sdk_python-2.2.0.dev7/src/visionai_sdk_python.egg-info/scm_version.json +0 -8
  20. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/.github/dependabot.yml +0 -0
  21. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/.github/workflows/publish.yml +0 -0
  22. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/.gitignore +0 -0
  23. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/setup.cfg +0 -0
  24. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/__init__.py +0 -0
  25. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/_base.py +0 -0
  26. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/_jwt_verifier.py +0 -0
  27. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/_request_attribution.py +0 -0
  28. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/_source_header.py +0 -0
  29. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/async_client.py +0 -0
  30. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/auth/__init__.py +0 -0
  31. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/auth/_mixin.py +0 -0
  32. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/auth/async_resource.py +0 -0
  33. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/auth/credentials.py +0 -0
  34. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/auth/models.py +0 -0
  35. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/auth/resource.py +0 -0
  36. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/client.py +0 -0
  37. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/constants.py +0 -0
  38. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/endpoints.py +0 -0
  39. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/py.typed +0 -0
  40. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/relay/__init__.py +0 -0
  41. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/relay/examples/__init__.py +0 -0
  42. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/relay/examples/error_connection.json +0 -0
  43. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/relay/examples/error_request.json +0 -0
  44. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/relay/examples/heartbeat.json +0 -0
  45. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/relay/examples/register.json +0 -0
  46. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/relay/examples/registered.json +0 -0
  47. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/relay/examples/request.json +0 -0
  48. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/relay/examples/response.json +0 -0
  49. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/relay/examples/response_text.json +0 -0
  50. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/relay/protocol.py +0 -0
  51. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/vlm/__init__.py +0 -0
  52. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/vlm/_mixin.py +0 -0
  53. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/vlm/async_resource.py +0 -0
  54. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/vlm/models.py +0 -0
  55. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/vlm/preprocess.py +0 -0
  56. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python/vlm/resource.py +0 -0
  57. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python.egg-info/dependency_links.txt +0 -0
  58. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/src/visionai_sdk_python.egg-info/top_level.txt +0 -0
  59. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/tests/__init__.py +0 -0
  60. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/tests/relay/__init__.py +0 -0
  61. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/tests/relay/test_protocol.py +0 -0
  62. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/tests/test__base.py +0 -0
  63. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/tests/test_async_client.py +0 -0
  64. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/tests/test_credentials.py +0 -0
  65. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/tests/test_request.py +0 -0
  66. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/tests/test_transport_options.py +0 -0
  67. {visionai_sdk_python-2.2.0.dev7 → visionai_sdk_python-2.3.0}/tests/test_vlm_preprocess.py +0 -0
@@ -72,6 +72,7 @@ jobs:
72
72
  run: >-
73
73
  uv pip install
74
74
  "httpx==0.28.1"
75
+ "httpx2==2.13.*"
75
76
  "requests==2.31.*"
76
77
  "aiohttp==3.9.*"
77
78
  "wrapt==1.16.*"
@@ -81,6 +82,7 @@ jobs:
81
82
  run: >-
82
83
  uv pip install --upgrade
83
84
  "httpx>=0.28.1"
85
+ "httpx2>=2.13,<3"
84
86
  "requests>=2.31,<3"
85
87
  "aiohttp>=3.9,<4"
86
88
  "wrapt>=1.16,<3"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: visionai-sdk-python
3
- Version: 2.2.0.dev7
3
+ Version: 2.3.0
4
4
  Summary: VisionAI SDK for Python
5
5
  Author-email: Tony Yang <tonyyang@linkervision.com>
6
6
  Requires-Python: >=3.11
@@ -13,6 +13,8 @@ Provides-Extra: requests
13
13
  Requires-Dist: requests<3,>=2.31; extra == "requests"
14
14
  Provides-Extra: aiohttp
15
15
  Requires-Dist: aiohttp<4,>=3.9; extra == "aiohttp"
16
+ Provides-Extra: httpx2
17
+ Requires-Dist: httpx2<3,>=2.13; extra == "httpx2"
16
18
  Provides-Extra: instrumentation
17
19
  Requires-Dist: wrapt<3,>=1.16; extra == "instrumentation"
18
20
 
@@ -43,6 +45,7 @@ Attributing direct `requests`/`aiohttp` calls, or using `instrumentation.instrum
43
45
  ```bash
44
46
  pip install visionai-sdk-python[requests]
45
47
  pip install visionai-sdk-python[aiohttp]
48
+ pip install visionai-sdk-python[httpx2]
46
49
  pip install visionai-sdk-python[instrumentation] # needed for instrument() itself
47
50
  ```
48
51
 
@@ -340,6 +343,25 @@ except VisionaiSDKError as e:
340
343
  - `NetworkError`: Connection/timeout errors
341
344
  - `JwksDiscoveryError`: OIDC discovery failures
342
345
 
346
+ Every HTTP error (`ClientError`, `ServerError` and their subclasses) carries
347
+ `status_code`, `code` and `body`; `body` is the whole JSON body. `code` is set for two
348
+ bodies only: a VS chat result (its `error`) and the relay's own errors (their `code`).
349
+ It is `None` for every other body, including the ones that list their errors under
350
+ `errors` (VS's `invalid_credentials` or `workspace_mismatch`, Platform's errors): read
351
+ `body` there. Where `code` is set, branch on it, not on the message text:
352
+
353
+ ```python
354
+ try:
355
+ result = client.vlm.chat(request)
356
+ except ClientError as e:
357
+ # [400 Bad Request] postprocess_error (message='Yes')
358
+ if e.code == "postprocess_error":
359
+ raw_output = e.body["message"]
360
+ ```
361
+
362
+ VS answers a failed chat with 200 and `status: "failed"` (read `result.error`), except
363
+ `postprocess_error` (400) and a timeout (408), which raise `ClientError`.
364
+
343
365
  ## Context Manager Usage
344
366
 
345
367
  Recommended for automatic resource cleanup:
@@ -424,7 +446,10 @@ instrumentation.instrument(
424
446
  ```
425
447
 
426
448
  This wraps a request-dispatch method of `requests.Session`, `httpx.Client`/
427
- `AsyncClient` and `aiohttp.ClientSession` in place, so it also covers calls made
449
+ `AsyncClient`, `httpx2.Client`/`AsyncClient` (the httpx fork Starlette prefers
450
+ from 1.2.0 on, see
451
+ [Kludex/starlette#3291](https://github.com/Kludex/starlette/pull/3291)) and
452
+ `aiohttp.ClientSession` in place, so it also covers calls made
428
453
  by third-party packages you cannot edit, module-level one-shots like
429
454
  `requests.get()`, and requests sent through a client instance that already
430
455
  existed before `instrument()` ran (see "Call it any time" below).
@@ -436,6 +461,7 @@ it patches are separately optional, and whichever is not installed is skipped:
436
461
  pip install visionai-sdk-python[instrumentation]
437
462
  pip install visionai-sdk-python[requests] # httpx is already a core dependency
438
463
  pip install visionai-sdk-python[aiohttp]
464
+ pip install visionai-sdk-python[httpx2]
439
465
  ```
440
466
 
441
467
  ### Destination scoping
@@ -1,21 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: visionai-sdk-python
3
- Version: 2.2.0.dev7
4
- Summary: VisionAI SDK for Python
5
- Author-email: Tony Yang <tonyyang@linkervision.com>
6
- Requires-Python: >=3.11
7
- Description-Content-Type: text/markdown
8
- Requires-Dist: httpx<1,>=0.28.1
9
- Requires-Dist: pydantic>=2.12.5
10
- Requires-Dist: cryptography>=46.0.5
11
- Requires-Dist: PyJWT[cryptography]>=2.8.0
12
- Provides-Extra: requests
13
- Requires-Dist: requests<3,>=2.31; extra == "requests"
14
- Provides-Extra: aiohttp
15
- Requires-Dist: aiohttp<4,>=3.9; extra == "aiohttp"
16
- Provides-Extra: instrumentation
17
- Requires-Dist: wrapt<3,>=1.16; extra == "instrumentation"
18
-
19
1
  # VisionAI SDK for Python
20
2
 
21
3
  Python client library for VisionAI authentication and Vision Language Model (VLM) inference services.
@@ -43,6 +25,7 @@ Attributing direct `requests`/`aiohttp` calls, or using `instrumentation.instrum
43
25
  ```bash
44
26
  pip install visionai-sdk-python[requests]
45
27
  pip install visionai-sdk-python[aiohttp]
28
+ pip install visionai-sdk-python[httpx2]
46
29
  pip install visionai-sdk-python[instrumentation] # needed for instrument() itself
47
30
  ```
48
31
 
@@ -340,6 +323,25 @@ except VisionaiSDKError as e:
340
323
  - `NetworkError`: Connection/timeout errors
341
324
  - `JwksDiscoveryError`: OIDC discovery failures
342
325
 
326
+ Every HTTP error (`ClientError`, `ServerError` and their subclasses) carries
327
+ `status_code`, `code` and `body`; `body` is the whole JSON body. `code` is set for two
328
+ bodies only: a VS chat result (its `error`) and the relay's own errors (their `code`).
329
+ It is `None` for every other body, including the ones that list their errors under
330
+ `errors` (VS's `invalid_credentials` or `workspace_mismatch`, Platform's errors): read
331
+ `body` there. Where `code` is set, branch on it, not on the message text:
332
+
333
+ ```python
334
+ try:
335
+ result = client.vlm.chat(request)
336
+ except ClientError as e:
337
+ # [400 Bad Request] postprocess_error (message='Yes')
338
+ if e.code == "postprocess_error":
339
+ raw_output = e.body["message"]
340
+ ```
341
+
342
+ VS answers a failed chat with 200 and `status: "failed"` (read `result.error`), except
343
+ `postprocess_error` (400) and a timeout (408), which raise `ClientError`.
344
+
343
345
  ## Context Manager Usage
344
346
 
345
347
  Recommended for automatic resource cleanup:
@@ -424,7 +426,10 @@ instrumentation.instrument(
424
426
  ```
425
427
 
426
428
  This wraps a request-dispatch method of `requests.Session`, `httpx.Client`/
427
- `AsyncClient` and `aiohttp.ClientSession` in place, so it also covers calls made
429
+ `AsyncClient`, `httpx2.Client`/`AsyncClient` (the httpx fork Starlette prefers
430
+ from 1.2.0 on, see
431
+ [Kludex/starlette#3291](https://github.com/Kludex/starlette/pull/3291)) and
432
+ `aiohttp.ClientSession` in place, so it also covers calls made
428
433
  by third-party packages you cannot edit, module-level one-shots like
429
434
  `requests.get()`, and requests sent through a client instance that already
430
435
  existed before `instrument()` ran (see "Call it any time" below).
@@ -436,6 +441,7 @@ it patches are separately optional, and whichever is not installed is skipped:
436
441
  pip install visionai-sdk-python[instrumentation]
437
442
  pip install visionai-sdk-python[requests] # httpx is already a core dependency
438
443
  pip install visionai-sdk-python[aiohttp]
444
+ pip install visionai-sdk-python[httpx2]
439
445
  ```
440
446
 
441
447
  ### Destination scoping
@@ -34,9 +34,12 @@ Sec-WebSocket-Protocol: platform-relay.v1
34
34
  ```
35
35
 
36
36
  - `Authorization` is a platform M2M token (client credentials). A refused upgrade is an HTTP
37
- status, not a close code: 400 when the relay knows none of the offered subprotocols, 401 when the
38
- token is not accepted (the agent fetches a new token, once, and reconnects), 503 when the relay
39
- could not validate it (the agent retries with the same token).
37
+ status, not a close code, with a JSON body `{"detail": "<why>"}`: 400 when the relay knows none
38
+ of the offered subprotocols; 401 when Platform does not accept the token (the agent fetches a new
39
+ token, once, and reconnects); 403 when the token is valid but the relay does not serve that
40
+ identity, a user token or a client outside its allowlist (a new token would not help: the agent
41
+ keeps it and retries after its backoff); 503 when the relay got no answer from Platform, a 429 of
42
+ its auth-failure throttle included (the agent retries with the same token).
40
43
  - `Sec-WebSocket-Protocol` carries the protocol version (§6).
41
44
  - After `101` the connection is the identity. Messages carry no agent or tenant fields.
42
45
 
@@ -24,6 +24,7 @@ dependencies = [
24
24
  [project.optional-dependencies]
25
25
  requests = ["requests>=2.31,<3"]
26
26
  aiohttp = ["aiohttp>=3.9,<4"]
27
+ httpx2 = ["httpx2>=2.13,<3"]
27
28
  instrumentation = ["wrapt>=1.16,<3"]
28
29
 
29
30
  [build-system]
@@ -57,6 +58,7 @@ dev = [
57
58
  "ruff>=0.15.11",
58
59
  "requests>=2.31,<3",
59
60
  "aiohttp>=3.9,<4",
61
+ "httpx2>=2.13,<3",
60
62
  "wrapt>=1.16,<3",
61
63
  ]
62
64
 
@@ -0,0 +1,150 @@
1
+ from http import HTTPStatus
2
+ from typing import Any
3
+
4
+ import httpx
5
+
6
+ # The longest `message` text an exception quotes; `APIError.body` keeps all of it.
7
+ _MESSAGE_LIMIT = 200
8
+
9
+
10
+ class VisionaiSDKError(Exception):
11
+ """Base exception for all SDK errors."""
12
+
13
+
14
+ class APIError(VisionaiSDKError):
15
+ """Base exception for all HTTP API errors.
16
+
17
+ Attributes:
18
+ status_code: The response's HTTP status.
19
+ code: The error code in the body (e.g. ``postprocess_error``), None without one.
20
+ body: The response's JSON object, None when it is not one.
21
+ """
22
+
23
+ def __init__(
24
+ self,
25
+ status_code: int,
26
+ message: str,
27
+ *,
28
+ code: str | None = None,
29
+ body: dict[str, Any] | None = None,
30
+ ) -> None:
31
+ self.status_code = status_code
32
+ self.code = code
33
+ self.body = body
34
+ super().__init__(f"[{_status_text(status_code)}] {message}")
35
+
36
+
37
+ class ClientError(APIError):
38
+ """4xx - Client-side error."""
39
+
40
+
41
+ class AuthenticationError(ClientError):
42
+ """401 - Invalid credentials/password."""
43
+
44
+ def __init__(self, message: str, **kwargs: Any) -> None:
45
+ super().__init__(401, message, **kwargs)
46
+
47
+
48
+ class PermissionDeniedError(ClientError):
49
+ """403 - Insufficient permissions."""
50
+
51
+ def __init__(self, message: str, **kwargs: Any) -> None:
52
+ super().__init__(403, message, **kwargs)
53
+
54
+
55
+ class RateLimitedError(ClientError):
56
+ """429 - Too many requests; on client-token, Platform is rate limiting mints."""
57
+
58
+ def __init__(self, message: str, **kwargs: Any) -> None:
59
+ super().__init__(429, message, **kwargs)
60
+
61
+
62
+ class ServerError(APIError):
63
+ """5xx - Server-side failure, consider retry."""
64
+
65
+
66
+ class NetworkError(VisionaiSDKError):
67
+ """Connection or timeout failure."""
68
+
69
+
70
+ class JwksDiscoveryError(VisionaiSDKError):
71
+ """Failed to fetch or parse the OIDC discovery document or JWKS endpoint."""
72
+
73
+
74
+ def from_transport_error(error: httpx.RequestError) -> VisionaiSDKError:
75
+ """The SDK exception for an httpx request that never got a response."""
76
+ if isinstance(error, httpx.TimeoutException):
77
+ return NetworkError("Request timed out")
78
+ if isinstance(error, httpx.NetworkError):
79
+ return NetworkError(f"Network error: {error}")
80
+ return VisionaiSDKError(f"Request failed: {error}")
81
+
82
+
83
+ def raise_for_status(response: httpx.Response) -> httpx.Response:
84
+ """Raise SDK-specific exceptions for non-2xx responses.
85
+
86
+ Raises:
87
+ AuthenticationError: If the server returns 401
88
+ PermissionDeniedError: If the server returns 403
89
+ ClientError: If the server returns any other 4xx
90
+ ServerError: If the server returns 5xx
91
+ APIError: If the server returns any other non-2xx status
92
+ """
93
+ try:
94
+ response.raise_for_status()
95
+ except httpx.HTTPStatusError as e:
96
+ body = None
97
+ if e.response.content:
98
+ try:
99
+ body = e.response.json()
100
+ except Exception:
101
+ pass
102
+ code = None
103
+ if isinstance(body, dict):
104
+ detail: str = body.get("detail") or body.get("message") or str(e)
105
+ # A VS chat result puts the error code in `error`, the relay in `code`.
106
+ # An `errors` list (VS's exceptions, Platform) is not read.
107
+ # TODO: read one shape once the services agree on an error body.
108
+ code = next(
109
+ (v for k in ("error", "code") if isinstance(v := body.get(k), str)),
110
+ None,
111
+ )
112
+ if code:
113
+ detail = _coded_detail(code, body)
114
+ else:
115
+ body = None
116
+ detail = str(e)
117
+ status = e.response.status_code
118
+ if status == 401:
119
+ raise AuthenticationError(detail, code=code, body=body) from e
120
+ if status == 403:
121
+ raise PermissionDeniedError(detail, code=code, body=body) from e
122
+ if status == 429:
123
+ raise RateLimitedError(detail, code=code, body=body) from e
124
+ if 400 <= status < 500:
125
+ raise ClientError(status, detail, code=code, body=body) from e
126
+ if 500 <= status < 600:
127
+ raise ServerError(status, detail, code=code, body=body) from e
128
+ raise APIError(status, detail, code=code, body=body) from e
129
+ return response
130
+
131
+
132
+ def _status_text(status_code: int) -> str:
133
+ """The status with its standard phrase (400 Bad Request); the number alone without one."""
134
+ try:
135
+ return f"{status_code} {HTTPStatus(status_code).phrase}"
136
+ except ValueError:
137
+ return str(status_code)
138
+
139
+
140
+ def _coded_detail(code: str, body: dict[str, Any]) -> str:
141
+ """The message of an error with a code: the code, then what the body says about it."""
142
+ if body.get("detail"):
143
+ return f"{code}: {body['detail']}"
144
+ if body.get("message"):
145
+ # VS's `message` is the model's output, not a description: quote it, cut short.
146
+ text = str(body["message"])
147
+ if len(text) > _MESSAGE_LIMIT:
148
+ text = f"{text[:_MESSAGE_LIMIT]}..."
149
+ return f"{code} (message={text!r})"
150
+ return code
@@ -8,8 +8,8 @@ should receive the header::
8
8
  allowed_destination_hosts=["vlm-inference-server", "*.svc.cluster.local"],
9
9
  )
10
10
 
11
- Every request through ``requests``, ``httpx`` (sync and async) and ``aiohttp``
12
- then carries ``X-Request-Source`` -- including third-party code, module-level
11
+ Every request through ``requests``, ``httpx``/``httpx2`` (sync and async) and
12
+ ``aiohttp`` then carries ``X-Request-Source`` -- including third-party code, module-level
13
13
  one-shots (``requests.get()``), and clients built before ``instrument()`` ran,
14
14
  since injection patches a request-dispatch method on the class rather than
15
15
  ``__init__``.
@@ -387,12 +387,20 @@ async def _inject_httpx_send_async(
387
387
  return await wrapped(*args, **kwargs)
388
388
 
389
389
 
390
- # (module, attribute path, wrapper). Missing modules are skipped: requests and
391
- # aiohttp are optional extras, httpx is a core dependency.
390
+ # (module, attribute path, wrapper). Missing modules are skipped: requests,
391
+ # aiohttp and httpx2 are optional extras, httpx is a core dependency. httpx2 is
392
+ # the fork Starlette's TestClient prefers from 1.2.0 on, deprecating httpx
393
+ # (https://github.com/Kludex/starlette/pull/3291) -- a separate class
394
+ # hierarchy under its own import name (not a subclass of httpx's), so it needs
395
+ # its own targets, but its redirect loop and _build_redirect_request
396
+ # (extensions passed by reference) match httpx's, so the same wrappers apply
397
+ # unchanged.
392
398
  _TARGETS = (
393
399
  ("requests", "Session.send", _inject_requests_send),
394
400
  ("httpx", "Client._send_single_request", _inject_httpx_send),
395
401
  ("httpx", "AsyncClient._send_single_request", _inject_httpx_send_async),
402
+ ("httpx2", "Client._send_single_request", _inject_httpx_send),
403
+ ("httpx2", "AsyncClient._send_single_request", _inject_httpx_send_async),
396
404
  ("aiohttp", "ClientRequest.__init__", _inject_aiohttp_request),
397
405
  )
398
406
 
@@ -1,3 +1,23 @@
1
+ Metadata-Version: 2.4
2
+ Name: visionai-sdk-python
3
+ Version: 2.3.0
4
+ Summary: VisionAI SDK for Python
5
+ Author-email: Tony Yang <tonyyang@linkervision.com>
6
+ Requires-Python: >=3.11
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: httpx<1,>=0.28.1
9
+ Requires-Dist: pydantic>=2.12.5
10
+ Requires-Dist: cryptography>=46.0.5
11
+ Requires-Dist: PyJWT[cryptography]>=2.8.0
12
+ Provides-Extra: requests
13
+ Requires-Dist: requests<3,>=2.31; extra == "requests"
14
+ Provides-Extra: aiohttp
15
+ Requires-Dist: aiohttp<4,>=3.9; extra == "aiohttp"
16
+ Provides-Extra: httpx2
17
+ Requires-Dist: httpx2<3,>=2.13; extra == "httpx2"
18
+ Provides-Extra: instrumentation
19
+ Requires-Dist: wrapt<3,>=1.16; extra == "instrumentation"
20
+
1
21
  # VisionAI SDK for Python
2
22
 
3
23
  Python client library for VisionAI authentication and Vision Language Model (VLM) inference services.
@@ -25,6 +45,7 @@ Attributing direct `requests`/`aiohttp` calls, or using `instrumentation.instrum
25
45
  ```bash
26
46
  pip install visionai-sdk-python[requests]
27
47
  pip install visionai-sdk-python[aiohttp]
48
+ pip install visionai-sdk-python[httpx2]
28
49
  pip install visionai-sdk-python[instrumentation] # needed for instrument() itself
29
50
  ```
30
51
 
@@ -322,6 +343,25 @@ except VisionaiSDKError as e:
322
343
  - `NetworkError`: Connection/timeout errors
323
344
  - `JwksDiscoveryError`: OIDC discovery failures
324
345
 
346
+ Every HTTP error (`ClientError`, `ServerError` and their subclasses) carries
347
+ `status_code`, `code` and `body`; `body` is the whole JSON body. `code` is set for two
348
+ bodies only: a VS chat result (its `error`) and the relay's own errors (their `code`).
349
+ It is `None` for every other body, including the ones that list their errors under
350
+ `errors` (VS's `invalid_credentials` or `workspace_mismatch`, Platform's errors): read
351
+ `body` there. Where `code` is set, branch on it, not on the message text:
352
+
353
+ ```python
354
+ try:
355
+ result = client.vlm.chat(request)
356
+ except ClientError as e:
357
+ # [400 Bad Request] postprocess_error (message='Yes')
358
+ if e.code == "postprocess_error":
359
+ raw_output = e.body["message"]
360
+ ```
361
+
362
+ VS answers a failed chat with 200 and `status: "failed"` (read `result.error`), except
363
+ `postprocess_error` (400) and a timeout (408), which raise `ClientError`.
364
+
325
365
  ## Context Manager Usage
326
366
 
327
367
  Recommended for automatic resource cleanup:
@@ -406,7 +446,10 @@ instrumentation.instrument(
406
446
  ```
407
447
 
408
448
  This wraps a request-dispatch method of `requests.Session`, `httpx.Client`/
409
- `AsyncClient` and `aiohttp.ClientSession` in place, so it also covers calls made
449
+ `AsyncClient`, `httpx2.Client`/`AsyncClient` (the httpx fork Starlette prefers
450
+ from 1.2.0 on, see
451
+ [Kludex/starlette#3291](https://github.com/Kludex/starlette/pull/3291)) and
452
+ `aiohttp.ClientSession` in place, so it also covers calls made
410
453
  by third-party packages you cannot edit, module-level one-shots like
411
454
  `requests.get()`, and requests sent through a client instance that already
412
455
  existed before `instrument()` ran (see "Call it any time" below).
@@ -418,6 +461,7 @@ it patches are separately optional, and whichever is not installed is skipped:
418
461
  pip install visionai-sdk-python[instrumentation]
419
462
  pip install visionai-sdk-python[requests] # httpx is already a core dependency
420
463
  pip install visionai-sdk-python[aiohttp]
464
+ pip install visionai-sdk-python[httpx2]
421
465
  ```
422
466
 
423
467
  ### Destination scoping
@@ -54,6 +54,7 @@ tests/test__base.py
54
54
  tests/test_async_client.py
55
55
  tests/test_client.py
56
56
  tests/test_credentials.py
57
+ tests/test_exceptions.py
57
58
  tests/test_instrumentation.py
58
59
  tests/test_request.py
59
60
  tests/test_transport_options.py
@@ -6,6 +6,9 @@ PyJWT[cryptography]>=2.8.0
6
6
  [aiohttp]
7
7
  aiohttp<4,>=3.9
8
8
 
9
+ [httpx2]
10
+ httpx2<3,>=2.13
11
+
9
12
  [instrumentation]
10
13
  wrapt<3,>=1.16
11
14
 
@@ -50,6 +50,7 @@
50
50
  "tests/test_async_client.py",
51
51
  "tests/test_client.py",
52
52
  "tests/test_credentials.py",
53
+ "tests/test_exceptions.py",
53
54
  "tests/test_instrumentation.py",
54
55
  "tests/test_request.py",
55
56
  "tests/test_transport_options.py",
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "2.3.0",
3
+ "distance": 0,
4
+ "node": "gfecc05790d4a07e50989afa3d914e4a24f5d0aba",
5
+ "dirty": false,
6
+ "branch": "HEAD",
7
+ "node_date": "2026-12-02"
8
+ }
@@ -29,3 +29,10 @@ ERROR_TIMEOUT_RESPONSE = {
29
29
  "status": "timeout",
30
30
  "error": "request timed out",
31
31
  }
32
+ # VS answers 400 with this when the model's output is not the JSON the request asked for.
33
+ ERROR_POSTPROCESS_RESPONSE = {
34
+ "chat_id": "id-001",
35
+ "status": "failed",
36
+ "error": "postprocess_error",
37
+ "message": "Yes",
38
+ }
@@ -8,6 +8,7 @@ from pydantic import ValidationError
8
8
  from tests.constants import (
9
9
  AUTH_URL,
10
10
  ERROR_FAILED_RESPONSE,
11
+ ERROR_POSTPROCESS_RESPONSE,
11
12
  ERROR_TIMEOUT_RESPONSE,
12
13
  NORMAL_COMPLETED_RESPONSE,
13
14
  NORMAL_PENDING_RESPONSE,
@@ -21,6 +22,7 @@ from visionai_sdk_python.client import Client
21
22
  from visionai_sdk_python.exceptions import (
22
23
  APIError,
23
24
  AuthenticationError,
25
+ ClientError,
24
26
  JwksDiscoveryError,
25
27
  NetworkError,
26
28
  ServerError,
@@ -446,9 +448,11 @@ def test_client_close_idempotent(success_transport: httpx.MockTransport) -> None
446
448
  # --- chat / get_chat shared fixtures & helpers ---
447
449
 
448
450
 
449
- def _make_vlm_client(response_body: dict) -> Client:
451
+ def _make_vlm_client(response_body: dict, status_code: int = 200) -> Client:
450
452
  """Return a Client whose transport always returns response_body and that is authenticated."""
451
- transport = httpx.MockTransport(lambda _: httpx.Response(200, json=response_body))
453
+ transport = httpx.MockTransport(
454
+ lambda _: httpx.Response(status_code, json=response_body)
455
+ )
452
456
  c = Client(auth_url=AUTH_URL, vlm_url=VLM_URL)
453
457
  c._client = httpx.Client(transport=transport)
454
458
  # Simulate authenticated state with a valid token
@@ -579,6 +583,17 @@ def test_chat_returns_error_model_for_error_statuses(
579
583
  assert result.status == expected_status
580
584
 
581
585
 
586
+ def test_chat_raises_with_the_error_code_when_vs_answers_400() -> None:
587
+ # Arrange
588
+ c = _make_vlm_client(ERROR_POSTPROCESS_RESPONSE, status_code=400)
589
+
590
+ # Act & Assert
591
+ with pytest.raises(ClientError) as exc_info:
592
+ c.vlm.chat(VALID_NIM_PAYLOAD)
593
+ assert exc_info.value.code == "postprocess_error"
594
+ assert exc_info.value.body == ERROR_POSTPROCESS_RESPONSE
595
+
596
+
582
597
  # --- get_chat ---
583
598
 
584
599
 
@@ -0,0 +1,129 @@
1
+ import httpx
2
+ import pytest
3
+
4
+ from tests.constants import ERROR_POSTPROCESS_RESPONSE
5
+ from visionai_sdk_python.exceptions import (
6
+ APIError,
7
+ AuthenticationError,
8
+ ClientError,
9
+ PermissionDeniedError,
10
+ RateLimitedError,
11
+ ServerError,
12
+ raise_for_status,
13
+ )
14
+
15
+ VS_TIMEOUT = {
16
+ "chat_id": "normal:id-001",
17
+ "status": "timeout",
18
+ "error": "scheduler_timeout",
19
+ "message": None,
20
+ }
21
+
22
+
23
+ def _response(status_code: int, **kwargs) -> httpx.Response:
24
+ request = httpx.Request("POST", "https://relay.example.com/ws/api/chat")
25
+ return httpx.Response(status_code, request=request, **kwargs)
26
+
27
+
28
+ @pytest.mark.parametrize(
29
+ "status_code,body,error_class,code,message",
30
+ [
31
+ (
32
+ 400,
33
+ ERROR_POSTPROCESS_RESPONSE,
34
+ ClientError,
35
+ "postprocess_error",
36
+ "[400 Bad Request] postprocess_error (message='Yes')",
37
+ ),
38
+ (
39
+ 408,
40
+ VS_TIMEOUT,
41
+ ClientError,
42
+ "scheduler_timeout",
43
+ "[408 Request Timeout] scheduler_timeout",
44
+ ),
45
+ (
46
+ 502,
47
+ {"detail": "VS did not answer", "code": "upstream_unreachable"},
48
+ ServerError,
49
+ "upstream_unreachable",
50
+ "[502 Bad Gateway] upstream_unreachable: VS did not answer",
51
+ ),
52
+ (
53
+ 503,
54
+ {"detail": "no agent for this workspace"},
55
+ ServerError,
56
+ None,
57
+ "[503 Service Unavailable] no agent for this workspace",
58
+ ),
59
+ (
60
+ 401,
61
+ {"detail": "token expired", "code": "token_expired"},
62
+ AuthenticationError,
63
+ "token_expired",
64
+ "[401 Unauthorized] token_expired: token expired",
65
+ ),
66
+ (
67
+ 403,
68
+ {"detail": "not a member"},
69
+ PermissionDeniedError,
70
+ None,
71
+ "[403 Forbidden] not a member",
72
+ ),
73
+ (
74
+ 429,
75
+ {"detail": "slow down", "code": "throttled"},
76
+ RateLimitedError,
77
+ "throttled",
78
+ "[429 Too Many Requests] throttled: slow down",
79
+ ),
80
+ ],
81
+ ids=[
82
+ "vs-postprocess",
83
+ "vs-timeout",
84
+ "relay-code",
85
+ "relay-no-code",
86
+ "401",
87
+ "403",
88
+ "429",
89
+ ],
90
+ )
91
+ def test_raise_for_status_carries_the_code_and_the_body(
92
+ status_code: int,
93
+ body: dict,
94
+ error_class: type[APIError],
95
+ code: str | None,
96
+ message: str,
97
+ ) -> None:
98
+ with pytest.raises(error_class) as exc_info:
99
+ raise_for_status(_response(status_code, json=body))
100
+
101
+ error = exc_info.value
102
+ assert type(error) is error_class
103
+ assert (error.status_code, error.code, error.body) == (status_code, code, body)
104
+ assert str(error) == message
105
+
106
+
107
+ def test_raise_for_status_cuts_a_long_message_short() -> None:
108
+ body = {**ERROR_POSTPROCESS_RESPONSE, "message": "x" * 500}
109
+
110
+ with pytest.raises(ClientError) as exc_info:
111
+ raise_for_status(_response(400, json=body))
112
+
113
+ quoted = "x" * 200 + "..."
114
+ assert str(exc_info.value) == (
115
+ f"[400 Bad Request] postprocess_error (message='{quoted}')"
116
+ )
117
+ assert exc_info.value.body == body
118
+
119
+
120
+ def test_raise_for_status_without_a_json_object() -> None:
121
+ with pytest.raises(ServerError) as exc_info:
122
+ raise_for_status(_response(500, text="upstream connect error"))
123
+
124
+ assert exc_info.value.code is None
125
+ assert exc_info.value.body is None
126
+
127
+
128
+ def test_api_error_shows_the_number_alone_for_an_unknown_status() -> None:
129
+ assert str(APIError(310, "Too many redirect")) == "[310] Too many redirect"
@@ -16,6 +16,7 @@ import warnings
16
16
 
17
17
  import aiohttp
18
18
  import httpx
19
+ import httpx2
19
20
  import pytest
20
21
  import requests
21
22
 
@@ -109,6 +110,12 @@ def instrumented(monkeypatch):
109
110
  instrumentation.uninstrument()
110
111
 
111
112
 
113
+ @pytest.fixture(params=[httpx, httpx2], ids=lambda m: m.__name__)
114
+ def httpx_lib(request):
115
+ """httpx and its fork httpx2 (separate classes, same dispatch internals)."""
116
+ return request.param
117
+
118
+
112
119
  class TestRequests:
113
120
  def test_session_carries_header(self, url, instrumented):
114
121
  assert requests.Session().get(url).text == "stream-agent"
@@ -152,27 +159,27 @@ class TestRequests:
152
159
 
153
160
 
154
161
  class TestHttpx:
155
- def test_client_carries_header(self, url, instrumented):
156
- with httpx.Client() as client:
162
+ def test_client_carries_header(self, httpx_lib, url, instrumented):
163
+ with httpx_lib.Client() as client:
157
164
  assert client.get(url).text == "stream-agent"
158
165
 
159
- def test_module_level_one_shot_carries_header(self, url, instrumented):
160
- assert httpx.get(url).text == "stream-agent"
166
+ def test_module_level_one_shot_carries_header(self, httpx_lib, url, instrumented):
167
+ assert httpx_lib.get(url).text == "stream-agent"
161
168
 
162
- def test_send_prebuilt_request_carries_header(self, url, instrumented):
163
- with httpx.Client() as client:
169
+ def test_send_prebuilt_request_carries_header(self, httpx_lib, url, instrumented):
170
+ with httpx_lib.Client() as client:
164
171
  response = client.send(client.build_request("GET", url))
165
172
 
166
173
  assert response.text == "stream-agent"
167
174
 
168
- async def test_async_client_carries_header(self, url, instrumented):
169
- async with httpx.AsyncClient() as client:
175
+ async def test_async_client_carries_header(self, httpx_lib, url, instrumented):
176
+ async with httpx_lib.AsyncClient() as client:
170
177
  response = await client.get(url)
171
178
 
172
179
  assert response.text == "stream-agent"
173
180
 
174
- def test_real_class_is_not_replaced(self, instrumented):
175
- assert httpx.Client.__mro__[0] is httpx.Client
181
+ def test_real_class_is_not_replaced(self, httpx_lib, instrumented):
182
+ assert httpx_lib.Client.__mro__[0] is httpx_lib.Client
176
183
 
177
184
 
178
185
  class TestAiohttp:
@@ -695,26 +702,28 @@ class TestRedirectReChecksDestinationPerHop:
695
702
  assert response.text == MISSING
696
703
 
697
704
  def test_httpx_allowed_to_disallowed_strips_the_header(
698
- self, url, url_localhost, instrumented
705
+ self, httpx_lib, url, url_localhost, instrumented
699
706
  ):
700
- with httpx.Client(follow_redirects=True) as client:
707
+ with httpx_lib.Client(follow_redirects=True) as client:
701
708
  response = client.get(_redirect(url, url_localhost))
702
709
  assert response.text == MISSING
703
710
 
704
- def test_httpx_allowed_to_allowed_keeps_the_header(self, url, instrumented):
705
- with httpx.Client(follow_redirects=True) as client:
711
+ def test_httpx_allowed_to_allowed_keeps_the_header(
712
+ self, httpx_lib, url, instrumented
713
+ ):
714
+ with httpx_lib.Client(follow_redirects=True) as client:
706
715
  response = client.get(_redirect(url, url))
707
716
  assert response.text == "stream-agent"
708
717
 
709
718
  def test_httpx_third_hop_does_not_leak_the_header(
710
- self, url, url_localhost, instrumented
719
+ self, httpx_lib, url, url_localhost, instrumented
711
720
  ):
712
721
  """httpx doesn't share requests' bug: _build_redirect_request derives
713
722
  each hop's headers from the current (already-mutated-by-us) request,
714
723
  not from an independent copy chain, so this already passed before
715
724
  the requests-specific fix above -- kept as regression coverage."""
716
725
  chain = _redirect(url, _redirect(url_localhost, url_localhost))
717
- with httpx.Client(follow_redirects=True) as client:
726
+ with httpx_lib.Client(follow_redirects=True) as client:
718
727
  response = client.get(chain)
719
728
  assert response.text == MISSING
720
729
 
@@ -1,5 +1,5 @@
1
1
  version = 1
2
- revision = 3
2
+ revision = 5
3
3
  requires-python = ">=3.11"
4
4
  resolution-markers = [
5
5
  "python_full_version >= '3.12'",
@@ -599,6 +599,19 @@ wheels = [
599
599
  { url = "https://files.pythonhosted.org/packages/7e/f5/f66802a942d491edb555dd61e3a9961140fd64c90bce1eafd741609d334d/httpcore-1.0.9-py3-none-any.whl", hash = "sha256:2d400746a40668fc9dec9810239072b40b4484b640a8c38fd654a024c7a1bf55", size = 78784, upload-time = "2025-04-24T22:06:20.566Z" },
600
600
  ]
601
601
 
602
+ [[package]]
603
+ name = "httpcore2"
604
+ version = "2.13.1"
605
+ source = { registry = "https://pypi.org/simple" }
606
+ dependencies = [
607
+ { name = "h11" },
608
+ { name = "truststore" },
609
+ ]
610
+ sdist = { url = "https://files.pythonhosted.org/packages/cb/f3/1db7aa2bc2524062192bb0e0323969492d1883152a232fe36eea65f4e35c/httpcore2-2.13.1.tar.gz", hash = "sha256:e0aa977abe17e69a3b820a24542a6fa88702676d83880b8d194dcd18408e5103", size = 68071, upload-time = "2026-09-23T07:47:22.372Z" }
611
+ wheels = [
612
+ { url = "https://files.pythonhosted.org/packages/09/ba/a4568248771ce81957bfb7cc600264a40fbcda092391ee1c415c50be4bea/httpcore2-2.13.1-py3-none-any.whl", hash = "sha256:e1e05d4f25f7d7d496bfb96748f6f4b67657b03da069b3a68c36069f3db73d0a", size = 83423, upload-time = "2026-09-23T07:47:19.365Z" },
613
+ ]
614
+
602
615
  [[package]]
603
616
  name = "httpx"
604
617
  version = "0.28.1"
@@ -614,13 +627,39 @@ wheels = [
614
627
  { url = "https://files.pythonhosted.org/packages/2a/39/e50c7c3a983047577ee07d2a9e53faf5a69493943ec3f6a384bdc792deb2/httpx-0.28.1-py3-none-any.whl", hash = "sha256:d909fcccc110f8c7faf814ca82a9a4d816bc5a6dbfea25d6591d6985b8ba59ad", size = 73517, upload-time = "2024-12-06T15:37:21.509Z" },
615
628
  ]
616
629
 
630
+ [[package]]
631
+ name = "httpx2"
632
+ version = "2.13.1"
633
+ source = { registry = "https://pypi.org/simple" }
634
+ dependencies = [
635
+ { name = "anyio", marker = "sys_platform != 'emscripten'" },
636
+ { name = "httpcore2", marker = "sys_platform != 'emscripten'" },
637
+ { name = "httpx2-jsfetch", marker = "python_full_version >= '3.12' and sys_platform == 'emscripten'" },
638
+ { name = "idna" },
639
+ { name = "truststore", marker = "sys_platform != 'emscripten'" },
640
+ { name = "typing-extensions", marker = "python_full_version < '3.13'" },
641
+ ]
642
+ sdist = { url = "https://files.pythonhosted.org/packages/d5/44/474bef2a0e9d90f1715d32cb98b0738695ca17ba324095fb2497ed7fbd59/httpx2-2.13.1.tar.gz", hash = "sha256:e48744a19e3af5ee48313d0ce5fe941d5422fae5705ea922a4aabf94d7800dfa", size = 100405, upload-time = "2026-09-23T07:47:23.052Z" }
643
+ wheels = [
644
+ { url = "https://files.pythonhosted.org/packages/d8/9c/6fe8931fd9f381042a9e4c7d5a7b4cbf7016b252bec0c99a49fce42c3326/httpx2-2.13.1-py3-none-any.whl", hash = "sha256:6dff50fabc270ee5fd25d845d0b078ed20564579744d6d962850975996d2f9a4", size = 95597, upload-time = "2026-09-23T07:47:20.995Z" },
645
+ ]
646
+
647
+ [[package]]
648
+ name = "httpx2-jsfetch"
649
+ version = "1.0"
650
+ source = { registry = "https://pypi.org/simple" }
651
+ sdist = { url = "https://files.pythonhosted.org/packages/cd/c4/0e5636363151a2a1795e0a77617168b9ca438e1748ec05fc9b5687f93d64/httpx2_jsfetch-1.0.tar.gz", hash = "sha256:70a0e3eabfef7cce5ad9c629f7d01ca05e418f586646f4ddf14782e4c1454c60", size = 6872, upload-time = "2026-08-07T00:13:07.492Z" }
652
+ wheels = [
653
+ { url = "https://files.pythonhosted.org/packages/9b/43/832f631d32e4f1211caa2ba368317739fe71f0b8530e4c9d15dc454bac2a/httpx2_jsfetch-1.0-py3-none-any.whl", hash = "sha256:cb916b707601e69a07721aabc8f3f6659be3a6893bc1ff5c6f9e02241df2da32", size = 6382, upload-time = "2026-08-07T00:13:06.567Z" },
654
+ ]
655
+
617
656
  [[package]]
618
657
  name = "idna"
619
- version = "3.11"
658
+ version = "3.20"
620
659
  source = { registry = "https://pypi.org/simple" }
621
- sdist = { url = "https://files.pythonhosted.org/packages/6f/6d/0703ccc57f3a7233505399edb88de3cbd678da106337b9fcde432b65ed60/idna-3.11.tar.gz", hash = "sha256:795dafcc9c04ed0c1fb032c2aa73654d8e8c5023a7df64a53f39190ada629902", size = 194582, upload-time = "2025-10-12T14:55:20.501Z" }
660
+ sdist = { url = "https://files.pythonhosted.org/packages/f5/08/8eea9d4b8302028f3abb2c0813953f7aec26d33b7a8960ed760e65ff29fa/idna-3.20.tar.gz", hash = "sha256:a7db850025b95ded1eae8a46181a1a6c56c92c96f0e2b005d9ff8dc0210cab44", size = 216463, upload-time = "2026-09-17T14:11:04.752Z" }
622
661
  wheels = [
623
- { url = "https://files.pythonhosted.org/packages/0e/61/66938bbb5fc52dbdf84594873d5b51fb1f7c7794e9c0f5bd885f30bc507b/idna-3.11-py3-none-any.whl", hash = "sha256:771a87f49d9defaf64091e6e6fe9c18d4833f140bd19464795bc32d966ca37ea", size = 71008, upload-time = "2025-10-12T14:55:18.883Z" },
662
+ { url = "https://files.pythonhosted.org/packages/58/a2/bb081bab032533a855d44de1d56f8e8426114ff1ba5d1f07a438a0a654f8/idna-3.20-py3-none-any.whl", hash = "sha256:ab7ae7122974553370f0bdb919e1a960b2cd1bc1ef0276416d896db81c14582c", size = 69583, upload-time = "2026-09-17T14:11:03.168Z" },
624
663
  ]
625
664
 
626
665
  [[package]]
@@ -1122,6 +1161,15 @@ wheels = [
1122
1161
  { url = "https://files.pythonhosted.org/packages/63/b6/aeadee5443e49baa2facd51131159fd6301cc4ccfc1541e4df7b021c37dd/ruff-0.15.11-py3-none-win_arm64.whl", hash = "sha256:063fed18cc1bbe0ee7393957284a6fe8b588c6a406a285af3ee3f46da2391ee4", size = 11032614, upload-time = "2026-04-16T18:46:34.487Z" },
1123
1162
  ]
1124
1163
 
1164
+ [[package]]
1165
+ name = "truststore"
1166
+ version = "0.10.5"
1167
+ source = { registry = "https://pypi.org/simple" }
1168
+ sdist = { url = "https://files.pythonhosted.org/packages/ee/9f/c5201d42a484c061e528825fc8e2d565f5abd50a4ced6fb7d29c4ec99b2b/truststore-0.10.5.tar.gz", hash = "sha256:30d36967ccaded5cbb38d602c433f53600036c79d502f4533a49b60a03bbefcd", size = 28091, upload-time = "2026-10-12T22:27:31.808Z" }
1169
+ wheels = [
1170
+ { url = "https://files.pythonhosted.org/packages/51/e9/3a7820be2bb0fe53b6bc9c3be26d3d1158004e4c3ab953aa6840b955b1e9/truststore-0.10.5-py3-none-any.whl", hash = "sha256:9aaaedaefaf06d8b206278cf8b5012bc897f485a874503501e12d776df78951c", size = 19017, upload-time = "2026-10-12T22:27:30.377Z" },
1171
+ ]
1172
+
1125
1173
  [[package]]
1126
1174
  name = "typing-extensions"
1127
1175
  version = "4.16.0"
@@ -1166,6 +1214,9 @@ dependencies = [
1166
1214
  aiohttp = [
1167
1215
  { name = "aiohttp" },
1168
1216
  ]
1217
+ httpx2 = [
1218
+ { name = "httpx2" },
1219
+ ]
1169
1220
  instrumentation = [
1170
1221
  { name = "wrapt" },
1171
1222
  ]
@@ -1176,6 +1227,7 @@ requests = [
1176
1227
  [package.dev-dependencies]
1177
1228
  dev = [
1178
1229
  { name = "aiohttp" },
1230
+ { name = "httpx2" },
1179
1231
  { name = "pytest" },
1180
1232
  { name = "pytest-asyncio" },
1181
1233
  { name = "requests" },
@@ -1188,16 +1240,18 @@ requires-dist = [
1188
1240
  { name = "aiohttp", marker = "extra == 'aiohttp'", specifier = ">=3.9,<4" },
1189
1241
  { name = "cryptography", specifier = ">=46.0.5" },
1190
1242
  { name = "httpx", specifier = ">=0.28.1,<1" },
1243
+ { name = "httpx2", marker = "extra == 'httpx2'", specifier = ">=2.13,<3" },
1191
1244
  { name = "pydantic", specifier = ">=2.12.5" },
1192
1245
  { name = "pyjwt", extras = ["cryptography"], specifier = ">=2.8.0" },
1193
1246
  { name = "requests", marker = "extra == 'requests'", specifier = ">=2.31,<3" },
1194
1247
  { name = "wrapt", marker = "extra == 'instrumentation'", specifier = ">=1.16,<3" },
1195
1248
  ]
1196
- provides-extras = ["requests", "aiohttp", "instrumentation"]
1249
+ provides-extras = ["requests", "aiohttp", "httpx2", "instrumentation"]
1197
1250
 
1198
1251
  [package.metadata.requires-dev]
1199
1252
  dev = [
1200
1253
  { name = "aiohttp", specifier = ">=3.9,<4" },
1254
+ { name = "httpx2", specifier = ">=2.13,<3" },
1201
1255
  { name = "pytest", specifier = ">=9.0.2" },
1202
1256
  { name = "pytest-asyncio", specifier = ">=0.25.0" },
1203
1257
  { name = "requests", specifier = ">=2.31,<3" },
@@ -1,97 +0,0 @@
1
- import httpx
2
-
3
-
4
- class VisionaiSDKError(Exception):
5
- """Base exception for all SDK errors."""
6
-
7
-
8
- class APIError(VisionaiSDKError):
9
- """Base exception for all HTTP API errors (has status_code)."""
10
-
11
- def __init__(self, status_code: int, message: str) -> None:
12
- self.status_code = status_code
13
- super().__init__(f"[{status_code}] {message}")
14
-
15
-
16
- class ClientError(APIError):
17
- """4xx - Client-side error."""
18
-
19
-
20
- class AuthenticationError(ClientError):
21
- """401 - Invalid credentials/password."""
22
-
23
- def __init__(self, message: str) -> None:
24
- super().__init__(401, message)
25
-
26
-
27
- class PermissionDeniedError(ClientError):
28
- """403 - Insufficient permissions."""
29
-
30
- def __init__(self, message: str) -> None:
31
- super().__init__(403, message)
32
-
33
-
34
- class RateLimitedError(ClientError):
35
- """429 - Too many requests; on client-token, Platform is rate limiting mints."""
36
-
37
- def __init__(self, message: str) -> None:
38
- super().__init__(429, message)
39
-
40
-
41
- class ServerError(APIError):
42
- """5xx - Server-side failure, consider retry."""
43
-
44
-
45
- class NetworkError(VisionaiSDKError):
46
- """Connection or timeout failure."""
47
-
48
-
49
- class JwksDiscoveryError(VisionaiSDKError):
50
- """Failed to fetch or parse the OIDC discovery document or JWKS endpoint."""
51
-
52
-
53
- def from_transport_error(error: httpx.RequestError) -> VisionaiSDKError:
54
- """The SDK exception for an httpx request that never got a response."""
55
- if isinstance(error, httpx.TimeoutException):
56
- return NetworkError("Request timed out")
57
- if isinstance(error, httpx.NetworkError):
58
- return NetworkError(f"Network error: {error}")
59
- return VisionaiSDKError(f"Request failed: {error}")
60
-
61
-
62
- def raise_for_status(response: httpx.Response) -> httpx.Response:
63
- """Raise SDK-specific exceptions for non-2xx responses.
64
-
65
- Raises:
66
- AuthenticationError: If the server returns 401
67
- PermissionDeniedError: If the server returns 403
68
- ClientError: If the server returns any other 4xx
69
- ServerError: If the server returns 5xx
70
- APIError: If the server returns any other non-2xx status
71
- """
72
- try:
73
- response.raise_for_status()
74
- except httpx.HTTPStatusError as e:
75
- body = None
76
- if e.response.content:
77
- try:
78
- body = e.response.json()
79
- except Exception:
80
- pass
81
- if isinstance(body, dict):
82
- detail: str = body.get("detail") or body.get("message") or str(e)
83
- else:
84
- detail = str(e)
85
- status = e.response.status_code
86
- if status == 401:
87
- raise AuthenticationError(detail) from e
88
- if status == 403:
89
- raise PermissionDeniedError(detail) from e
90
- if status == 429:
91
- raise RateLimitedError(detail) from e
92
- if 400 <= status < 500:
93
- raise ClientError(status, detail) from e
94
- if 500 <= status < 600:
95
- raise ServerError(status, detail) from e
96
- raise APIError(status, detail) from e
97
- return response
@@ -1,8 +0,0 @@
1
- {
2
- "tag": "2.2.0.dev7",
3
- "distance": 0,
4
- "node": "g2926924b043d544a5f2bb4c878693b2a774c1190",
5
- "dirty": false,
6
- "branch": "HEAD",
7
- "node_date": "2026-10-28"
8
- }