@@ -58,8 +58,9 @@ class ContextualAI(SyncAPIClient):
58
58
with_streaming_response : ContextualAIWithStreamedResponse
59
59
60
60
# 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
63
64
64
65
def __init__ (
65
66
self ,
@@ -91,9 +92,12 @@ def __init__(
91
92
if api_key is None :
92
93
api_key = os .environ .get ("CONTEXTUAL_API_KEY" )
93
94
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
+ )
97
101
self .api_key = api_key
98
102
99
103
if base_url is None :
@@ -103,8 +107,6 @@ def __init__(
103
107
104
108
if 'snowflakecomputing.app' in str (base_url ):
105
109
self .is_snowflake = True
106
- else :
107
- self .is_snowflake = False
108
110
109
111
super ().__init__ (
110
112
version = __version__ ,
@@ -137,6 +139,8 @@ def auth_headers(self) -> dict[str, str]:
137
139
api_key = self .api_key
138
140
if self .is_snowflake :
139
141
return {"Authorization" : f"Snowflake Token={ api_key } " }
142
+ elif self .is_snowflake_internal :
143
+ return {}
140
144
else :
141
145
return {"Authorization" : f"Bearer { api_key } " }
142
146
@@ -245,8 +249,9 @@ class AsyncContextualAI(AsyncAPIClient):
245
249
with_streaming_response : AsyncContextualAIWithStreamedResponse
246
250
247
251
# 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
250
255
251
256
def __init__ (
252
257
self ,
@@ -278,9 +283,12 @@ def __init__(
278
283
if api_key is None :
279
284
api_key = os .environ .get ("CONTEXTUAL_API_KEY" )
280
285
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
+ )
284
292
self .api_key = api_key
285
293
286
294
if base_url is None :
@@ -290,8 +298,6 @@ def __init__(
290
298
291
299
if 'snowflakecomputing.app' in str (base_url ):
292
300
self .is_snowflake = True
293
- else :
294
- self .is_snowflake = False
295
301
296
302
super ().__init__ (
297
303
version = __version__ ,
@@ -319,11 +325,13 @@ def qs(self) -> Querystring:
319
325
return Querystring (array_format = "repeat" )
320
326
321
327
@property
322
- @override
328
+ @override
323
329
def auth_headers (self ) -> dict [str , str ]:
324
330
api_key = self .api_key
325
331
if self .is_snowflake :
326
332
return {"Authorization" : f"Snowflake Token={ api_key } " }
333
+ elif self .is_snowflake_internal :
334
+ return {}
327
335
else :
328
336
return {"Authorization" : f"Bearer { api_key } " }
329
337
0 commit comments