|
60 | 60 | validate_resource_url, |
61 | 61 | ) |
62 | 62 |
|
63 | | -from . import __version__ |
64 | | - |
65 | 63 | # Load environment variables |
66 | 64 | load_dotenv() |
67 | 65 |
|
68 | 66 | # User-Agent for client identification in server logs |
69 | | -USER_AGENT = f"blockrun-python/{__version__}" |
| 67 | +# Version read lazily to avoid circular import with __init__.py |
| 68 | +def _get_user_agent() -> str: |
| 69 | + from . import __version__ |
| 70 | + return f"blockrun-python/{__version__}" |
70 | 71 |
|
71 | 72 |
|
72 | 73 | # ============================================================================= |
@@ -408,7 +409,7 @@ def _request_with_payment(self, endpoint: str, body: Dict[str, Any]) -> ChatResp |
408 | 409 | response = self._client.post( |
409 | 410 | url, |
410 | 411 | json=body, |
411 | | - headers={"Content-Type": "application/json", "User-Agent": USER_AGENT}, |
| 412 | + headers={"Content-Type": "application/json", "User-Agent": _get_user_agent()}, |
412 | 413 | ) |
413 | 414 |
|
414 | 415 | # Handle 402 Payment Required |
@@ -505,7 +506,7 @@ def _handle_payment_and_retry( |
505 | 506 | json=body, |
506 | 507 | headers={ |
507 | 508 | "Content-Type": "application/json", |
508 | | - "User-Agent": USER_AGENT, |
| 509 | + "User-Agent": _get_user_agent(), |
509 | 510 | "PAYMENT-SIGNATURE": payment_payload, |
510 | 511 | }, |
511 | 512 | timeout=request_timeout, |
@@ -832,7 +833,7 @@ async def _request_with_payment(self, endpoint: str, body: Dict[str, Any]) -> Ch |
832 | 833 | response = await self._client.post( |
833 | 834 | url, |
834 | 835 | json=body, |
835 | | - headers={"Content-Type": "application/json", "User-Agent": USER_AGENT}, |
| 836 | + headers={"Content-Type": "application/json", "User-Agent": _get_user_agent()}, |
836 | 837 | ) |
837 | 838 |
|
838 | 839 | if response.status_code == 402: |
@@ -909,7 +910,7 @@ async def _handle_payment_and_retry( |
909 | 910 | json=body, |
910 | 911 | headers={ |
911 | 912 | "Content-Type": "application/json", |
912 | | - "User-Agent": USER_AGENT, |
| 913 | + "User-Agent": _get_user_agent(), |
913 | 914 | "PAYMENT-SIGNATURE": payment_payload, |
914 | 915 | }, |
915 | 916 | ) |
|
0 commit comments