@@ -18,6 +18,7 @@ class ZhipuAI(HttpClient):
1818 chat : api_resource .chat .Chat
1919 api_key : str
2020 _disable_token_cache : bool = True
21+ source_channel : str
2122
2223 def __init__ (
2324 self ,
@@ -30,12 +31,14 @@ def __init__(
3031 custom_headers : Mapping [str , str ] | None = None ,
3132 disable_token_cache : bool = True ,
3233 _strict_response_validation : bool = False ,
34+ source_channel : str | None = None
3335 ) -> None :
3436 if api_key is None :
3537 api_key = os .environ .get ("ZHIPUAI_API_KEY" )
3638 if api_key is None :
3739 raise ZhipuAIError ("未提供api_key,请通过参数或环境变量提供" )
3840 self .api_key = api_key
41+ self .source_channel = source_channel
3942 self ._disable_token_cache = disable_token_cache
4043
4144 if base_url is None :
@@ -69,10 +72,11 @@ def __init__(
6972 @override
7073 def auth_headers (self ) -> dict [str , str ]:
7174 api_key = self .api_key
75+ source_channel = self .source_channel or "python-sdk"
7276 if self ._disable_token_cache :
73- return {"Authorization" : f"Bearer { api_key } " }
77+ return {"Authorization" : f"Bearer { api_key } " , "x-source-channel" : source_channel }
7478 else :
75- return {"Authorization" : f"Bearer { _jwt_token .generate_token (api_key )} " }
79+ return {"Authorization" : f"Bearer { _jwt_token .generate_token (api_key )} " , "x-source-channel" : source_channel }
7680
7781 def __del__ (self ) -> None :
7882 if (not hasattr (self , "_has_custom_http_client" )
0 commit comments