@@ -58,8 +58,9 @@ class ContextualAI(SyncAPIClient):
5858 with_streaming_response : ContextualAIWithStreamedResponse
5959
6060 # client options
61- api_key : str
62- is_snowflake : bool
61+ api_key : str | None = None
62+ is_snowflake : bool = False
63+ is_snowflake_internal : bool = False
6364
6465 def __init__ (
6566 self ,
@@ -91,9 +92,12 @@ def __init__(
9192 if api_key is None :
9293 api_key = os .environ .get ("CONTEXTUAL_API_KEY" )
9394 if api_key is None :
94- raise ContextualAIError (
95- "The api_key client option must be set either by passing api_key to the client or by setting the CONTEXTUAL_API_KEY environment variable"
96- )
95+ if os .getenv ('SNOWFLAKE_INTERNAL_API_SERVICE' , False ):
96+ self .is_snowflake_internal = True
97+ else :
98+ raise ContextualAIError (
99+ "The api_key client option must be set either by passing api_key to the client or by setting the CONTEXTUAL_API_KEY environment variable"
100+ )
97101 self .api_key = api_key
98102
99103 if base_url is None :
@@ -103,8 +107,6 @@ def __init__(
103107
104108 if 'snowflakecomputing.app' in str (base_url ):
105109 self .is_snowflake = True
106- else :
107- self .is_snowflake = False
108110
109111 super ().__init__ (
110112 version = __version__ ,
@@ -137,6 +139,8 @@ def auth_headers(self) -> dict[str, str]:
137139 api_key = self .api_key
138140 if self .is_snowflake :
139141 return {"Authorization" : f"Snowflake Token={ api_key } " }
142+ elif self .is_snowflake_internal :
143+ return {}
140144 else :
141145 return {"Authorization" : f"Bearer { api_key } " }
142146
@@ -245,8 +249,9 @@ class AsyncContextualAI(AsyncAPIClient):
245249 with_streaming_response : AsyncContextualAIWithStreamedResponse
246250
247251 # client options
248- api_key : str
249- is_snowflake : bool
252+ api_key : str | None = None
253+ is_snowflake : bool = False
254+ is_snowflake_internal : bool = False
250255
251256 def __init__ (
252257 self ,
@@ -278,9 +283,12 @@ def __init__(
278283 if api_key is None :
279284 api_key = os .environ .get ("CONTEXTUAL_API_KEY" )
280285 if api_key is None :
281- raise ContextualAIError (
282- "The api_key client option must be set either by passing api_key to the client or by setting the CONTEXTUAL_API_KEY environment variable"
283- )
286+ if os .getenv ('SNOWFLAKE_INTERNAL_API_SERVICE' , False ):
287+ self .is_snowflake_internal = True
288+ else :
289+ raise ContextualAIError (
290+ "The api_key client option must be set either by passing api_key to the client or by setting the CONTEXTUAL_API_KEY environment variable"
291+ )
284292 self .api_key = api_key
285293
286294 if base_url is None :
@@ -290,8 +298,6 @@ def __init__(
290298
291299 if 'snowflakecomputing.app' in str (base_url ):
292300 self .is_snowflake = True
293- else :
294- self .is_snowflake = False
295301
296302 super ().__init__ (
297303 version = __version__ ,
@@ -319,11 +325,13 @@ def qs(self) -> Querystring:
319325 return Querystring (array_format = "repeat" )
320326
321327 @property
322- @override
328+ @override
323329 def auth_headers (self ) -> dict [str , str ]:
324330 api_key = self .api_key
325331 if self .is_snowflake :
326332 return {"Authorization" : f"Snowflake Token={ api_key } " }
333+ elif self .is_snowflake_internal :
334+ return {}
327335 else :
328336 return {"Authorization" : f"Bearer { api_key } " }
329337
0 commit comments