Skip to content

Commit 3704b22

Browse files
## Summary
1 parent 45c2816 commit 3704b22

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tofupilot/v2/client_with_error_tracking.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77

88
from pydantic_core import ValidationError
99

10+
import httpx as _httpx
11+
1012
from .sdk import TofuPilot
1113
from .errors.tofupiloterror import TofuPilotError
14+
from ._hooks.types import BeforeRequestContext, BeforeRequestHook
15+
from ._version import __version__
1216

1317

1418
def _enhance_error_message(e: TofuPilotError) -> None:
@@ -125,6 +129,17 @@ def download(self, attachment, dest: Union[str, Path, None] = None) -> Path:
125129
return dest
126130

127131

132+
class _ClientInfoHook(BeforeRequestHook):
133+
"""Injects x-client-type and x-client-version headers into every request."""
134+
135+
def before_request(
136+
self, hook_ctx: BeforeRequestContext, request: _httpx.Request
137+
):
138+
request.headers["x-client-type"] = "python"
139+
request.headers["x-client-version"] = __version__
140+
return request
141+
142+
128143
class TofuPilotWithErrorTracking(TofuPilot):
129144
"""
130145
Enhanced TofuPilot client with automatic error tracking and improved logging.
@@ -169,6 +184,9 @@ def __init__(
169184
**kwargs
170185
)
171186

187+
# Register client info hook for API activity tracking
188+
self.sdk_configuration.hooks.register_before_request_hook(_ClientInfoHook())
189+
172190
def __getattr__(self, name: str):
173191
attr = super().__getattr__(name)
174192
if name == 'runs':

0 commit comments

Comments
 (0)