opengradient 0.5.10__py3-none-any.whl → 0.5.11__py3-none-any.whl

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.
opengradient/client.py CHANGED
@@ -1152,7 +1152,7 @@ class Client:
1152
1152
  limits=LIMITS,
1153
1153
  http2=False,
1154
1154
  follow_redirects=False,
1155
- auth=X402Auth(account=self._wallet_account), # type: ignore
1155
+ auth=X402Auth(account=self._wallet_account, network_filter=DEFAULT_NETWORK_FILTER), # type: ignore
1156
1156
  ) as client:
1157
1157
  headers = {
1158
1158
  "Content-Type": "application/json",
opengradient/x402_auth.py CHANGED
@@ -5,12 +5,12 @@ This module provides an httpx Auth class that handles x402 payment protocol
5
5
  authentication for streaming responses.
6
6
  """
7
7
 
8
- from typing import Generator, Optional
9
-
10
8
  import httpx
11
- from eth_account.account import LocalAccount
9
+ import typing
10
+ import logging
11
+
12
12
  from x402.clients.base import x402Client
13
- from x402.types import x402PaymentRequiredResponse
13
+ from x402.types import x402PaymentRequiredResponse, PaymentRequirements
14
14
 
15
15
 
16
16
  class X402Auth(httpx.Auth):
@@ -29,10 +29,20 @@ class X402Auth(httpx.Auth):
29
29
 
30
30
  def __init__(
31
31
  self,
32
- account: LocalAccount,
33
- max_value: Optional[int] = None,
34
- network_filter: Optional[str] = None,
35
- scheme_filter: Optional[str] = None,
32
+ account: typing.Any,
33
+ max_value: typing.Optional[int] = None,
34
+ payment_requirements_selector: typing.Optional[
35
+ typing.Callable[
36
+ [
37
+ list[PaymentRequirements],
38
+ typing.Optional[str],
39
+ typing.Optional[str],
40
+ typing.Optional[int],
41
+ ],
42
+ PaymentRequirements,
43
+ ]
44
+ ] = None,
45
+ network_filter: typing.Optional[str] = None,
36
46
  ):
37
47
  """
38
48
  Initialize X402Auth with an Ethereum account for signing payments.
@@ -43,60 +53,47 @@ class X402Auth(httpx.Auth):
43
53
  network_filter: Optional network filter for selecting payment requirements
44
54
  scheme_filter: Optional scheme filter for selecting payment requirements
45
55
  """
46
- self._account = account
47
- self._max_value = max_value
48
- self._network_filter = network_filter
49
- self._scheme_filter = scheme_filter
50
- self._x402_client = x402Client(
56
+ self.x402_client = x402Client(
51
57
  account,
52
58
  max_value=max_value,
53
- network_filter=network_filter,
54
- scheme_filter=scheme_filter,
59
+ payment_requirements_selector=payment_requirements_selector, # type: ignore
55
60
  )
61
+ self.network_filter = network_filter
56
62
 
57
- def auth_flow(
63
+ async def async_auth_flow(
58
64
  self, request: httpx.Request
59
- ) -> Generator[httpx.Request, httpx.Response, None]:
65
+ ) -> typing.AsyncGenerator[httpx.Request, httpx.Response]:
60
66
  """
61
- Implement the auth flow for x402 payment handling.
62
-
63
- This method yields the initial request, and if a 402 response is received,
64
- it creates a payment header and retries the request.
67
+ Handle authentication flow for x402 payment protocol.
65
68
 
66
69
  Args:
67
- request: The initial httpx Request
70
+ request: httpx Request object to be authenticated
68
71
 
69
72
  Yields:
70
- httpx.Request objects (initial and retry with payment header)
73
+ httpx Request object with authentication headers attached
71
74
  """
72
- # Send the initial request
73
75
  response = yield request
74
76
 
75
- # If not a 402, we're done
76
- if response.status_code != 402:
77
- return
78
-
79
- # Handle 402 Payment Required
80
- try:
81
- data = response.json()
82
- payment_response = x402PaymentRequiredResponse(**data)
77
+ if response.status_code == 402:
78
+ try:
79
+ await response.aread()
80
+ data = response.json()
83
81
 
84
- # Select payment requirements
85
- selected_requirements = self._x402_client.select_payment_requirements(
86
- payment_response.accepts
87
- )
82
+ payment_response = x402PaymentRequiredResponse(**data)
88
83
 
89
- # Create payment header
90
- payment_header = self._x402_client.create_payment_header(
91
- selected_requirements, payment_response.x402_version
92
- )
84
+ selected_requirements = self.x402_client.select_payment_requirements(
85
+ payment_response.accepts,
86
+ self.network_filter,
87
+ )
93
88
 
94
- # Add payment header and retry
95
- request.headers["X-Payment"] = payment_header
96
- request.headers["Access-Control-Expose-Headers"] = "X-Payment-Response"
89
+ payment_header = self.x402_client.create_payment_header(
90
+ selected_requirements, payment_response.x402_version
91
+ )
97
92
 
98
- yield request
93
+ request.headers["X-Payment"] = payment_header
94
+ request.headers["Access-Control-Expose-Headers"] = "X-Payment-Response"
95
+ yield request
99
96
 
100
- except Exception:
101
- # If payment handling fails, just return the original 402 response
102
- return
97
+ except Exception as e:
98
+ logging.error(f"X402Auth: Error handling payment: {e}")
99
+ return
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opengradient
3
- Version: 0.5.10
3
+ Version: 0.5.11
4
4
  Summary: Python SDK for OpenGradient decentralized model management & inference services
5
5
  Author-email: OpenGradient <kyle@vannalabs.ai>
6
6
  License-Expression: MIT
@@ -2,12 +2,12 @@ opengradient/__init__.py,sha256=hRGex2VGwAQ-lqBNphW93D4R3wPHQpQrTkwgGLe2MoA,1025
2
2
  opengradient/account.py,sha256=5wrYpws_1lozjOFjLCTHtxgoxK-LmObDAaVy9eDcJY4,1145
3
3
  opengradient/alpha.py,sha256=WAtL1GGbEpoeLO89rOMd8-YAgAFJYM1UJlICm6YGsPs,15195
4
4
  opengradient/cli.py,sha256=pfgyLfD1MIDifKmGLFsJqBlgvqIcnsIh3zzg7PaIeH4,33670
5
- opengradient/client.py,sha256=B13xv_iL2ZynCsiojfsXuERzIdbt62UoOLd_s_moCnA,65250
5
+ opengradient/client.py,sha256=KQZI1WZaMqyIHRWFH4HA1fFd1JtSdkrUYa7RX_bIwJA,65289
6
6
  opengradient/defaults.py,sha256=8faLPwvp_BQdErY_SEjBzvmGVuOBdZ2zKcoryD8SCXk,797
7
7
  opengradient/exceptions.py,sha256=88tfegboGtlehQcwhxsl6ZzhLJWZWlkf_bkHTiCtXpo,3391
8
8
  opengradient/types.py,sha256=bADakUM6WwdMORGC5HvQvWCezNwIlVc7l0zodPapbhQ,14622
9
9
  opengradient/utils.py,sha256=ZUq4OBIml2vsC0tRqus4Zwb_e3g4woo00apByrafuVw,8058
10
- opengradient/x402_auth.py,sha256=utfusvfKxPtsq4MtRX03yQ969G7VeatxAQwHLAW77JU,3350
10
+ opengradient/x402_auth.py,sha256=fuSsgFmvrlZ3X6uAlUnqtkQ485NECxHfBr3IFADpKAg,3309
11
11
  opengradient/abi/InferencePrecompile.abi,sha256=reepTHg6Q01UrFP0Gexc-JayplsvOLPfG7jrEZ-cV28,10197
12
12
  opengradient/abi/PriceHistoryInference.abi,sha256=ZB3fZdx1kaFlp2wt1vTbTZZG1k8HPvmNtkG5Q8Bnajw,5098
13
13
  opengradient/abi/WorkflowScheduler.abi,sha256=yEGs76qO4S1z980KL5hBdfyXiJ6k-kERcB1O_o73AEU,416
@@ -29,9 +29,9 @@ opengradient/workflow_models/constants.py,sha256=viIkb_LGcfVprqQNaA80gBTj6cfYam0
29
29
  opengradient/workflow_models/types.py,sha256=Z22hF6c8Y4D2GlzVEIBODGwsqSjSrQvUcpZ7R-mIJdI,409
30
30
  opengradient/workflow_models/utils.py,sha256=aL2-Hp5J5qlJft6-wx4GnZNOXZ1vjYaTF1uEgYavWdI,1509
31
31
  opengradient/workflow_models/workflow_models.py,sha256=d4C_gs39DAfy4cdY9Ee6GMXpPfzwvKFpmxzK1A7LNgU,3900
32
- opengradient-0.5.10.dist-info/licenses/LICENSE,sha256=xEcvQ3AxZOtDkrqkys2Mm6Y9diEnaSeQRKvxi-JGnNA,1069
33
- opengradient-0.5.10.dist-info/METADATA,sha256=Pfj4IQ8soL-1AO5X5PbqcunZF4K0UK3AixX3Lfsh_Bw,5437
34
- opengradient-0.5.10.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
35
- opengradient-0.5.10.dist-info/entry_points.txt,sha256=yUKTaJx8RXnybkob0J62wVBiCp_1agVbgw9uzsmaeJc,54
36
- opengradient-0.5.10.dist-info/top_level.txt,sha256=oC1zimVLa2Yi1LQz8c7x-0IQm92milb5ax8gHBHwDqU,13
37
- opengradient-0.5.10.dist-info/RECORD,,
32
+ opengradient-0.5.11.dist-info/licenses/LICENSE,sha256=xEcvQ3AxZOtDkrqkys2Mm6Y9diEnaSeQRKvxi-JGnNA,1069
33
+ opengradient-0.5.11.dist-info/METADATA,sha256=qJZT1jnWcmpeBQsLN1YrmPRCfMzD4nk7saMguFYNmyc,5437
34
+ opengradient-0.5.11.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
35
+ opengradient-0.5.11.dist-info/entry_points.txt,sha256=yUKTaJx8RXnybkob0J62wVBiCp_1agVbgw9uzsmaeJc,54
36
+ opengradient-0.5.11.dist-info/top_level.txt,sha256=oC1zimVLa2Yi1LQz8c7x-0IQm92milb5ax8gHBHwDqU,13
37
+ opengradient-0.5.11.dist-info/RECORD,,