@@ -29,8 +29,6 @@ def to_url(self):
2929 case _:
3030 raise ValueError (f"Unsupported endpoint: { self } " )
3131
32- COPILOT_INTEGRATION_ID = 'vscode-chat'
33-
3432# you can also set https://api.githubcopilot.com if you prefer
3533# but beware that your taskflows need to reference the correct model id
3634# since different APIs use their own id schema, use -l with your desired
@@ -52,6 +50,26 @@ def get_AI_token():
5250 return token
5351 raise RuntimeError ("AI_API_TOKEN environment variable is not set." )
5452
53+ def get_custom_header () -> dict [str , str ]:
54+ """
55+ Get custom header from environment variable CUSTOM_HEADER.
56+ Expected format: name:value
57+ Returns a dictionary that can be merged into request headers.
58+ """
59+ custom_header = os .getenv ('AI_API_CUSTOM_HEADER' )
60+ if not custom_header :
61+ return {}
62+
63+ # Split on first colon to handle values that might contain colons
64+ parts = custom_header .split (':' , 1 )
65+ if len (parts ) != 2 :
66+ logging .warning (f"Invalid AI_API_CUSTOM_HEADER format. Expected 'name:value', got: { custom_header } " )
67+ return {}
68+
69+ name , value = parts
70+ return {name .strip (): value .strip ()}
71+
72+
5573# assume we are >= python 3.9 for our type hints
5674def list_capi_models (token : str ) -> dict [str , dict ]:
5775 """Retrieve a dictionary of available CAPI models"""
@@ -69,12 +87,11 @@ def list_capi_models(token: str) -> dict[str, dict]:
6987 case _:
7088 raise ValueError (f"Unsupported Model Endpoint: { api_endpoint } \n "
7189 f"Supported endpoints: { [e .to_url () for e in AI_API_ENDPOINT_ENUM ]} " )
72- r = httpx .get (httpx .URL (api_endpoint ).join (models_catalog ),
73- headers = {
74- 'Accept' : 'application/json' ,
75- 'Authorization' : f'Bearer { token } ' ,
76- 'Copilot-Integration-Id' : COPILOT_INTEGRATION_ID
77- })
90+ headers = {
91+ 'Accept' : 'application/json' ,
92+ 'Authorization' : f'Bearer { token } ' ,
93+ } | get_custom_header ()
94+ r = httpx .get (httpx .URL (api_endpoint ).join (models_catalog ), headers = headers )
7895 r .raise_for_status ()
7996 # CAPI vs Models API
8097 match netloc :
0 commit comments