71
71
72
72
class Gradient (SyncAPIClient ):
73
73
# client options
74
- api_key : str | None
75
- inference_key : str | None
76
- agent_key : str | None
74
+ access_token : str | None
75
+ model_access_key : str | None
76
+ agent_access_key : str | None
77
77
_agent_endpoint : str | None
78
+ inference_endpoint : str | None
78
79
79
80
def __init__ (
80
81
self ,
81
82
* ,
82
- api_key : str | None = None ,
83
- inference_key : str | None = None ,
84
- agent_key : str | None = None ,
83
+ api_key : str | None = None , # deprecated, use `access_token` instead
84
+ inference_key : str | None = None , # deprecated, use `model_access_key` instead
85
+ agent_key : str | None = None , # deprecated, use `agent_access_key` instead
86
+ access_token : str | None = None ,
87
+ model_access_key : str | None = None ,
88
+ agent_access_key : str | None = None ,
85
89
agent_endpoint : str | None = None ,
90
+ inference_endpoint : str | None = None ,
86
91
base_url : str | httpx .URL | None = None ,
87
92
timeout : Union [float , Timeout , None , NotGiven ] = NOT_GIVEN ,
88
93
max_retries : int = DEFAULT_MAX_RETRIES ,
@@ -105,34 +110,45 @@ def __init__(
105
110
"""Construct a new synchronous Gradient client instance.
106
111
107
112
This automatically infers the following arguments from their corresponding environment variables if they are not provided:
108
- - `api_key ` from `DIGITALOCEAN_ACCESS_TOKEN`
109
- - `inference_key ` from `GRADIENT_MODEL_ACCESS_KEY`
110
- - `agent_key ` from `GRADIENT_AGENT_ACCESS_KEY`
113
+ - `access_token ` from `DIGITALOCEAN_ACCESS_TOKEN`
114
+ - `model_access_key ` from `GRADIENT_MODEL_ACCESS_KEY`
115
+ - `agent_access_key ` from `GRADIENT_AGENT_ACCESS_KEY`
111
116
"""
112
- if api_key is None :
113
- api_key = os .environ .get ("DIGITALOCEAN_ACCESS_TOKEN" )
114
- # support for legacy environment variable
115
- if api_key is None :
116
- api_key = os .environ .get ("GRADIENT_API_KEY" )
117
- self .api_key = api_key
118
-
119
- if inference_key is None :
120
- inference_key = os .environ .get ("GRADIENT_MODEL_ACCESS_KEY" )
121
- # support for legacy environment variable
122
- if inference_key is None :
123
- inference_key = os .environ .get ("GRADIENT_INFERENCE_KEY" )
124
-
125
- self .inference_key = inference_key
126
-
127
- if agent_key is None :
128
- agent_key = os .environ .get ("GRADIENT_AGENT_ACCESS_KEY" )
129
- # support for legacy environment variable
130
- if agent_key is None :
131
- agent_key = os .environ .get ("GRADIENT_AGENT_KEY" )
132
- self .agent_key = agent_key
117
+ if access_token is None :
118
+ if api_key is not None :
119
+ access_token = api_key
120
+ else :
121
+ access_token = os .environ .get ("DIGITALOCEAN_ACCESS_TOKEN" )
122
+ # support for legacy environment variable
123
+ if access_token is None :
124
+ access_token = os .environ .get ("GRADIENT_API_KEY" )
125
+ self .access_token = access_token
126
+
127
+
128
+ if model_access_key is None :
129
+ if inference_key is not None :
130
+ model_access_key = inference_key
131
+ else :
132
+ model_access_key = os .environ .get ("GRADIENT_INFERENCE_KEY" )
133
+ # support for legacy environment variable
134
+ if model_access_key is None :
135
+ model_access_key = os .environ .get ("GRADIENT_MODEL_ACCESS_KEY" )
136
+ self .model_access_key = model_access_key
137
+
138
+ if agent_access_key is None :
139
+ if agent_key is not None :
140
+ agent_access_key = agent_key
141
+ else :
142
+ agent_access_key = os .environ .get ("GRADIENT_AGENT_ACCESS_KEY" )
143
+ # support for legacy environment variable
144
+ if agent_access_key is None :
145
+ agent_access_key = os .environ .get ("GRADIENT_AGENT_KEY" )
146
+ self .agent_access_key = agent_access_key
133
147
134
148
self ._agent_endpoint = agent_endpoint
135
149
150
+ self .inference_endpoint = inference_endpoint
151
+
136
152
if base_url is None :
137
153
base_url = os .environ .get ("GRADIENT_BASE_URL" )
138
154
self ._base_url_overridden = base_url is not None
@@ -229,10 +245,10 @@ def qs(self) -> Querystring:
229
245
@property
230
246
@override
231
247
def auth_headers (self ) -> dict [str , str ]:
232
- api_key = self .api_key
233
- if api_key is None :
248
+ access_token = self .access_token
249
+ if access_token is None :
234
250
return {}
235
- return {"Authorization" : f"Bearer { api_key } " }
251
+ return {"Authorization" : f"Bearer { access_token } " }
236
252
237
253
@property
238
254
@override
@@ -245,24 +261,28 @@ def default_headers(self) -> dict[str, str | Omit]:
245
261
246
262
@override
247
263
def _validate_headers (self , headers : Headers , custom_headers : Headers ) -> None :
248
- if (self . api_key or self . agent_key or self . inference_key ) and headers . get (
249
- "Authorization"
250
- ):
264
+ if (
265
+ self . access_token or self . agent_access_key or self . model_access_key
266
+ ) and headers . get ( "Authorization" ) :
251
267
return
252
268
if isinstance (custom_headers .get ("Authorization" ), Omit ):
253
269
return
254
270
255
271
raise TypeError (
256
- '"Could not resolve authentication method. Expected api_key, agent_key , or inference_key to be set. Or for the `Authorization` headers to be explicitly omitted"'
272
+ '"Could not resolve authentication method. Expected access_token, agent_access_key , or model_access_key to be set. Or for the `Authorization` headers to be explicitly omitted"'
257
273
)
258
274
259
275
def copy (
260
276
self ,
261
277
* ,
262
- api_key : str | None = None ,
263
- inference_key : str | None = None ,
264
- agent_key : str | None = None ,
278
+ api_key : str | None = None , # deprecated, use `access_token` instead
279
+ inference_key : str | None = None , # deprecated, use `model_access_key` instead
280
+ agent_key : str | None = None , # deprecated, use `agent_access_key` instead
281
+ access_token : str | None = None ,
282
+ model_access_key : str | None = None ,
283
+ agent_access_key : str | None = None ,
265
284
agent_endpoint : str | None = None ,
285
+ inference_endpoint : str | None = None ,
266
286
base_url : str | httpx .URL | None = None ,
267
287
timeout : float | Timeout | None | NotGiven = NOT_GIVEN ,
268
288
http_client : httpx .Client | None = None ,
@@ -300,10 +320,11 @@ def copy(
300
320
301
321
http_client = http_client or self ._client
302
322
client = self .__class__ (
303
- api_key = api_key or self .api_key ,
304
- inference_key = inference_key or self .inference_key ,
305
- agent_key = agent_key or self .agent_key ,
306
- agent_endpoint = agent_endpoint or self ._agent_endpoint ,
323
+ access_token = access_token or api_key or self .access_token ,
324
+ model_access_key = model_access_key or inference_key or self .model_access_key ,
325
+ agent_access_key = agent_access_key or agent_key or self .agent_access_key ,
326
+ agent_endpoint = agent_endpoint or self .agent_endpoint ,
327
+ inference_endpoint = inference_endpoint or self .inference_endpoint ,
307
328
base_url = base_url or self .base_url ,
308
329
timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
309
330
http_client = http_client ,
@@ -363,18 +384,23 @@ def _make_status_error(
363
384
364
385
class AsyncGradient (AsyncAPIClient ):
365
386
# client options
366
- api_key : str | None
367
- inference_key : str | None
368
- agent_key : str | None
387
+ access_token : str | None
388
+ model_access_key : str | None
389
+ agent_access_key : str | None
369
390
_agent_endpoint : str | None
391
+ inference_endpoint : str | None
370
392
371
393
def __init__ (
372
394
self ,
373
395
* ,
374
- api_key : str | None = None ,
375
- inference_key : str | None = None ,
376
- agent_key : str | None = None ,
396
+ api_key : str | None = None , # deprecated, use `access_token` instead
397
+ inference_key : str | None = None , # deprecated, use `model_access_key` instead
398
+ agent_key : str | None = None , # deprecated, use `agent_access_key` instead
399
+ access_token : str | None = None ,
400
+ model_access_key : str | None = None ,
401
+ agent_access_key : str | None = None ,
377
402
agent_endpoint : str | None = None ,
403
+ inference_endpoint : str | None = None ,
378
404
base_url : str | httpx .URL | None = None ,
379
405
timeout : Union [float , Timeout , None , NotGiven ] = NOT_GIVEN ,
380
406
max_retries : int = DEFAULT_MAX_RETRIES ,
@@ -397,34 +423,45 @@ def __init__(
397
423
"""Construct a new async AsyncGradient client instance.
398
424
399
425
This automatically infers the following arguments from their corresponding environment variables if they are not provided:
400
- - `api_key ` from `DIGITALOCEAN_ACCESS_TOKEN`
401
- - `inference_key ` from `GRADIENT_MODEL_ACCESS_KEY`
402
- - `agent_key ` from `GRADIENT_AGENT_ACCESS_KEY`
426
+ - `access_token ` from `DIGITALOCEAN_ACCESS_TOKEN`
427
+ - `model_access_key ` from `GRADIENT_MODEL_ACCESS_KEY`
428
+ - `agent_access_key ` from `GRADIENT_AGENT_ACCESS_KEY`
403
429
"""
404
- if api_key is None :
405
- api_key = os .environ .get ("DIGITALOCEAN_ACCESS_TOKEN" )
406
- # support for legacy environment variable
407
- if api_key is None :
408
- api_key = os .environ .get ("GRADIENT_API_KEY" )
409
- self .api_key = api_key
410
-
411
- if inference_key is None :
412
- inference_key = os .environ .get ("GRADIENT_MODEL_ACCESS_KEY" )
413
- # support for legacy environment variable
414
- if inference_key is None :
415
- inference_key = os .environ .get ("GRADIENT_INFERENCE_KEY" )
416
- self .api_key = api_key
417
- self .inference_key = inference_key
418
-
419
- if agent_key is None :
420
- agent_key = os .environ .get ("GRADIENT_AGENT_ACCESS_KEY" )
421
- # support for legacy environment variable
422
- if agent_key is None :
423
- agent_key = os .environ .get ("GRADIENT_AGENT_KEY" )
424
- self .agent_key = agent_key
430
+ if access_token is None :
431
+ if api_key is not None :
432
+ access_token = api_key
433
+ else :
434
+ access_token = os .environ .get ("DIGITALOCEAN_ACCESS_TOKEN" )
435
+ # support for legacy environment variable
436
+ if access_token is None :
437
+ access_token = os .environ .get ("GRADIENT_API_KEY" )
438
+ self .access_token = access_token
439
+
440
+
441
+ if model_access_key is None :
442
+ if inference_key is not None :
443
+ model_access_key = inference_key
444
+ else :
445
+ model_access_key = os .environ .get ("GRADIENT_INFERENCE_KEY" )
446
+ # support for legacy environment variable
447
+ if model_access_key is None :
448
+ model_access_key = os .environ .get ("GRADIENT_MODEL_ACCESS_KEY" )
449
+ self .model_access_key = model_access_key
450
+
451
+ if agent_access_key is None :
452
+ if agent_key is not None :
453
+ agent_access_key = agent_key
454
+ else :
455
+ agent_access_key = os .environ .get ("GRADIENT_AGENT_ACCESS_KEY" )
456
+ # support for legacy environment variable
457
+ if agent_access_key is None :
458
+ agent_access_key = os .environ .get ("GRADIENT_AGENT_KEY" )
459
+ self .agent_access_key = agent_access_key
425
460
426
461
self ._agent_endpoint = agent_endpoint
427
462
463
+ self .inference_endpoint = inference_endpoint
464
+
428
465
if base_url is None :
429
466
base_url = os .environ .get ("GRADIENT_BASE_URL" )
430
467
self ._base_url_overridden = base_url is not None
@@ -521,10 +558,10 @@ def qs(self) -> Querystring:
521
558
@property
522
559
@override
523
560
def auth_headers (self ) -> dict [str , str ]:
524
- api_key = self .api_key
525
- if api_key is None :
561
+ access_token = self .access_token
562
+ if access_token is None :
526
563
return {}
527
- return {"Authorization" : f"Bearer { api_key } " }
564
+ return {"Authorization" : f"Bearer { access_token } " }
528
565
529
566
@property
530
567
@override
@@ -537,24 +574,28 @@ def default_headers(self) -> dict[str, str | Omit]:
537
574
538
575
@override
539
576
def _validate_headers (self , headers : Headers , custom_headers : Headers ) -> None :
540
- if (self . api_key or self . agent_key or self . inference_key ) and headers . get (
541
- "Authorization"
542
- ):
577
+ if (
578
+ self . access_token or self . agent_access_key or self . model_access_key
579
+ ) and headers . get ( "Authorization" ) :
543
580
return
544
581
if isinstance (custom_headers .get ("Authorization" ), Omit ):
545
582
return
546
583
547
584
raise TypeError (
548
- '"Could not resolve authentication method. Expected api_key, agent_key , or inference_key to be set. Or for the `Authorization` headers to be explicitly omitted"'
585
+ '"Could not resolve authentication method. Expected access_token, agent_access_key , or model_access_key to be set. Or for the `Authorization` headers to be explicitly omitted"'
549
586
)
550
587
551
588
def copy (
552
589
self ,
553
590
* ,
554
- api_key : str | None = None ,
555
- inference_key : str | None = None ,
556
- agent_key : str | None = None ,
591
+ api_key : str | None = None , # deprecated, use `access_token` instead
592
+ inference_key : str | None = None , # deprecated, use `model_access_key` instead
593
+ agent_key : str | None = None , # deprecated, use `agent_access_key` instead
557
594
agent_endpoint : str | None = None ,
595
+ access_token : str | None = None ,
596
+ model_access_key : str | None = None ,
597
+ agent_access_key : str | None = None ,
598
+ inference_endpoint : str | None = None ,
558
599
base_url : str | httpx .URL | None = None ,
559
600
timeout : float | Timeout | None | NotGiven = NOT_GIVEN ,
560
601
http_client : httpx .AsyncClient | None = None ,
@@ -592,10 +633,23 @@ def copy(
592
633
593
634
http_client = http_client or self ._client
594
635
client = self .__class__ (
636
+ << << << < HEAD
595
637
api_key = api_key or self .api_key ,
596
638
inference_key = inference_key or self .inference_key ,
597
639
agent_key = agent_key or self .agent_key ,
598
640
agent_endpoint = agent_endpoint or self ._agent_endpoint ,
641
+ | | | | | | | eb1dcf7
642
+ api_key = api_key or self .api_key ,
643
+ inference_key = inference_key or self .inference_key ,
644
+ agent_key = agent_key or self .agent_key ,
645
+ agent_domain = agent_domain or self .agent_domain ,
646
+ == == == =
647
+ access_token = access_token or self .access_token ,
648
+ model_access_key = model_access_key or self .model_access_key ,
649
+ agent_access_key = agent_access_key or self .agent_access_key ,
650
+ agent_endpoint = agent_endpoint or self .agent_endpoint ,
651
+ inference_endpoint = inference_endpoint or self .inference_endpoint ,
652
+ >> >> >> > origin / generated - - merge - conflict
599
653
base_url = base_url or self .base_url ,
600
654
timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
601
655
http_client = http_client ,
0 commit comments