@@ -202,6 +202,7 @@ def __init__(
202202 | None
203203 ) = None ,
204204 timeout_millisec : int | None = None ,
205+ headers : dict [str , str ] | None = None ,
205206 ):
206207 """Constructor"""
207208 self ._url = api_url
@@ -326,6 +327,10 @@ def __init__(
326327 """Telemetry configuration
327328 """
328329
330+ self ._headers = headers or {}
331+ """Default headers to be sent with every request
332+ """
333+
329334 def __deepcopy__ (self , memo ):
330335 cls = self .__class__
331336 result = cls .__new__ (cls )
@@ -656,6 +661,17 @@ def is_valid(self):
656661 f"timeout_millisec not within reasonable range (0,60000), { self ._timeout_millisec } "
657662 )
658663
664+ if self ._headers is not None :
665+ for key , value in self ._headers .items ():
666+ if not isinstance (key , str ):
667+ raise FgaValidationException (
668+ f"header keys must be strings, got { type (key ).__name__ } for key { key } "
669+ )
670+ if not isinstance (value , str ):
671+ raise FgaValidationException (
672+ f"header values must be strings, got { type (value ).__name__ } for key '{ key } '"
673+ )
674+
659675 @property
660676 def api_scheme (self ):
661677 """Return connection is https or http."""
@@ -740,3 +756,31 @@ def timeout_millisec(self, value):
740756 Update timeout milliseconds
741757 """
742758 self ._timeout_millisec = value
759+
760+ @property
761+ def headers (self ) -> dict [str , str ]:
762+ """
763+ Return default headers to be sent with every request.
764+
765+ Headers are key-value pairs that will be included in all API requests.
766+ Common use cases include correlation IDs, API versioning, and tenant identification.
767+ """
768+ return self ._headers
769+
770+ @headers .setter
771+ def headers (self , value : dict [str , str ] | None ) -> None :
772+ """
773+ Update default headers to be sent with every request.
774+
775+ Args:
776+ value: Dictionary of header names to values, or None to clear headers.
777+ Both keys and values must be strings.
778+
779+ Raises:
780+ FgaValidationException: If value is not a dict or None.
781+ """
782+ if value is not None and not isinstance (value , dict ):
783+ raise FgaValidationException (
784+ f"headers must be a dict or None, got { type (value ).__name__ } "
785+ )
786+ self ._headers = value or {}
0 commit comments