@@ -58,11 +58,13 @@ class Knock(SyncAPIClient):
5858
5959 # client options
6060 api_key : str
61+ branch : str | None
6162
6263 def __init__ (
6364 self ,
6465 * ,
6566 api_key : str | None = None ,
67+ branch : str | None = None ,
6668 base_url : str | httpx .URL | None = None ,
6769 timeout : float | Timeout | None | NotGiven = not_given ,
6870 max_retries : int = DEFAULT_MAX_RETRIES ,
@@ -84,7 +86,9 @@ def __init__(
8486 ) -> None :
8587 """Construct a new synchronous Knock client instance.
8688
87- This automatically infers the `api_key` argument from the `KNOCK_API_KEY` environment variable if it is not provided.
89+ This automatically infers the following arguments from their corresponding environment variables if they are not provided:
90+ - `api_key` from `KNOCK_API_KEY`
91+ - `branch` from `KNOCK_BRANCH`
8892 """
8993 if api_key is None :
9094 api_key = os .environ .get ("KNOCK_API_KEY" )
@@ -94,6 +98,10 @@ def __init__(
9498 )
9599 self .api_key = api_key
96100
101+ if branch is None :
102+ branch = os .environ .get ("KNOCK_BRANCH" )
103+ self .branch = branch
104+
97105 if base_url is None :
98106 base_url = os .environ .get ("KNOCK_BASE_URL" )
99107 if base_url is None :
@@ -143,13 +151,15 @@ def default_headers(self) -> dict[str, str | Omit]:
143151 return {
144152 ** super ().default_headers ,
145153 "X-Stainless-Async" : "false" ,
154+ "X-Knock-Branch" : self .branch if self .branch is not None else Omit (),
146155 ** self ._custom_headers ,
147156 }
148157
149158 def copy (
150159 self ,
151160 * ,
152161 api_key : str | None = None ,
162+ branch : str | None = None ,
153163 base_url : str | httpx .URL | None = None ,
154164 timeout : float | Timeout | None | NotGiven = not_given ,
155165 http_client : httpx .Client | None = None ,
@@ -184,6 +194,7 @@ def copy(
184194 http_client = http_client or self ._client
185195 return self .__class__ (
186196 api_key = api_key or self .api_key ,
197+ branch = branch or self .branch ,
187198 base_url = base_url or self .base_url ,
188199 timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
189200 http_client = http_client ,
@@ -248,11 +259,13 @@ class AsyncKnock(AsyncAPIClient):
248259
249260 # client options
250261 api_key : str
262+ branch : str | None
251263
252264 def __init__ (
253265 self ,
254266 * ,
255267 api_key : str | None = None ,
268+ branch : str | None = None ,
256269 base_url : str | httpx .URL | None = None ,
257270 timeout : float | Timeout | None | NotGiven = not_given ,
258271 max_retries : int = DEFAULT_MAX_RETRIES ,
@@ -274,7 +287,9 @@ def __init__(
274287 ) -> None :
275288 """Construct a new async AsyncKnock client instance.
276289
277- This automatically infers the `api_key` argument from the `KNOCK_API_KEY` environment variable if it is not provided.
290+ This automatically infers the following arguments from their corresponding environment variables if they are not provided:
291+ - `api_key` from `KNOCK_API_KEY`
292+ - `branch` from `KNOCK_BRANCH`
278293 """
279294 if api_key is None :
280295 api_key = os .environ .get ("KNOCK_API_KEY" )
@@ -284,6 +299,10 @@ def __init__(
284299 )
285300 self .api_key = api_key
286301
302+ if branch is None :
303+ branch = os .environ .get ("KNOCK_BRANCH" )
304+ self .branch = branch
305+
287306 if base_url is None :
288307 base_url = os .environ .get ("KNOCK_BASE_URL" )
289308 if base_url is None :
@@ -333,13 +352,15 @@ def default_headers(self) -> dict[str, str | Omit]:
333352 return {
334353 ** super ().default_headers ,
335354 "X-Stainless-Async" : f"async:{ get_async_library ()} " ,
355+ "X-Knock-Branch" : self .branch if self .branch is not None else Omit (),
336356 ** self ._custom_headers ,
337357 }
338358
339359 def copy (
340360 self ,
341361 * ,
342362 api_key : str | None = None ,
363+ branch : str | None = None ,
343364 base_url : str | httpx .URL | None = None ,
344365 timeout : float | Timeout | None | NotGiven = not_given ,
345366 http_client : httpx .AsyncClient | None = None ,
@@ -374,6 +395,7 @@ def copy(
374395 http_client = http_client or self ._client
375396 return self .__class__ (
376397 api_key = api_key or self .api_key ,
398+ branch = branch or self .branch ,
377399 base_url = base_url or self .base_url ,
378400 timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
379401 http_client = http_client ,
0 commit comments