@databricks/sdk-modelserving 0.0.0-dev → 0.1.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,984 @@
1
+ // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
+
3
+ import {VERSION as AUTH_VERSION} from '@databricks/sdk-auth';
4
+ import type {Call} from '@databricks/sdk-core/api';
5
+ import {retryOn} from '@databricks/sdk-core/api';
6
+ import {createDefault} from '@databricks/sdk-core/clientinfo';
7
+ import type {Logger} from '@databricks/sdk-core/logger';
8
+ import {NoOpLogger} from '@databricks/sdk-core/logger';
9
+ import type {CallOptions} from '@databricks/sdk-options/call';
10
+ import type {ClientOptions} from '@databricks/sdk-options/client';
11
+ import type {HttpClient} from '@databricks/sdk-core/http';
12
+ import {newHttpClient} from './transport';
13
+ import {
14
+ buildHttpRequest,
15
+ executeCall,
16
+ executeHttpCall,
17
+ sendAndCheckError,
18
+ marshalRequest,
19
+ parseResponse,
20
+ } from './utils';
21
+ import pkgJson from '../../package.json' with {type: 'json'};
22
+ import type {
23
+ CreateInferenceEndpointRequest,
24
+ CreatePtEndpointRequest,
25
+ DeleteInferenceEndpointRequest,
26
+ DeleteInferenceEndpointRequest_Response,
27
+ ExportMetricsResponse,
28
+ ExternalFunctionRequest,
29
+ ExternalFunctionResponse,
30
+ GetExportEndpointMetricsRequest,
31
+ GetInferenceEndpointRequest,
32
+ GetInferenceEndpointSchemaRequest,
33
+ GetOpenApiResponse,
34
+ GetServedModelBuildLogsRequest,
35
+ GetServedModelBuildLogsRequest_Response,
36
+ GetServedModelLogsRequest,
37
+ GetServedModelLogsRequest_Response,
38
+ InferenceEndpointDetailed,
39
+ ListInferenceEndpointsRequest,
40
+ ListInferenceEndpointsRequest_Response,
41
+ PatchInferenceEndpointTagsRequest,
42
+ PatchInferenceEndpointTagsRequest_Response,
43
+ PutInferenceEndpointAiGatewayRequest,
44
+ PutInferenceEndpointAiGatewayRequest_Response,
45
+ PutInferenceEndpointConfigRequest,
46
+ PutInferenceEndpointRateLimitsRequest,
47
+ PutInferenceEndpointRateLimitsRequest_Response,
48
+ PutPtEndpointConfigRequest,
49
+ UpdateInferenceEndpointNotificationsRequest,
50
+ UpdateInferenceEndpointNotificationsRequest_Response,
51
+ } from './model';
52
+ import {
53
+ InferenceEndpointState_ConfigUpdateState,
54
+ marshalCreateInferenceEndpointRequestSchema,
55
+ marshalCreatePtEndpointRequestSchema,
56
+ marshalExternalFunctionRequestSchema,
57
+ marshalPatchInferenceEndpointTagsRequestSchema,
58
+ marshalPutInferenceEndpointAiGatewayRequestSchema,
59
+ marshalPutInferenceEndpointConfigRequestSchema,
60
+ marshalPutInferenceEndpointRateLimitsRequestSchema,
61
+ marshalPutPtEndpointConfigRequestSchema,
62
+ marshalUpdateInferenceEndpointNotificationsRequestSchema,
63
+ unmarshalDeleteInferenceEndpointRequest_ResponseSchema,
64
+ unmarshalGetServedModelBuildLogsRequest_ResponseSchema,
65
+ unmarshalGetServedModelLogsRequest_ResponseSchema,
66
+ unmarshalInferenceEndpointDetailedSchema,
67
+ unmarshalListInferenceEndpointsRequest_ResponseSchema,
68
+ unmarshalPatchInferenceEndpointTagsRequest_ResponseSchema,
69
+ unmarshalPutInferenceEndpointAiGatewayRequest_ResponseSchema,
70
+ unmarshalPutInferenceEndpointRateLimitsRequest_ResponseSchema,
71
+ unmarshalUpdateInferenceEndpointNotificationsRequest_ResponseSchema,
72
+ } from './model';
73
+
74
+ // Package identity segment for this client to be used in the User-Agent header.
75
+ const PACKAGE_SEGMENT = {
76
+ key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
77
+ value: pkgJson.version,
78
+ };
79
+
80
+ class StillRunningError extends Error {}
81
+
82
+ export class ModelservingClient {
83
+ private readonly host: string;
84
+ // Workspace ID used to route workspace-level calls on unified hosts (SPOG).
85
+ // When set, workspace-level methods send X-Databricks-Org-Id on every
86
+ // request.
87
+ private readonly workspaceId: string | undefined;
88
+ private readonly httpClient: HttpClient;
89
+ private readonly logger: Logger;
90
+ // User-Agent header value. Composed once at construction from
91
+ // createDefault() merged with this package's identity and the active
92
+ // credential's name.
93
+ private readonly userAgent: string;
94
+
95
+ constructor(options: ClientOptions) {
96
+ if (options.host === undefined) {
97
+ throw new Error('Host is required.');
98
+ }
99
+ this.host = options.host.replace(/\/$/, '');
100
+ this.workspaceId = options.workspaceId;
101
+ this.logger = options.logger ?? new NoOpLogger();
102
+ const info = createDefault()
103
+ .with(PACKAGE_SEGMENT)
104
+ .with({key: 'sdk-js-auth', value: AUTH_VERSION})
105
+ .with({key: 'auth', value: options.credentials?.name() ?? 'default'});
106
+ this.userAgent = info.toString();
107
+ this.httpClient = newHttpClient(options);
108
+ }
109
+
110
+ /** Create a new serving endpoint. */
111
+ async createInferenceEndpoint(
112
+ req: CreateInferenceEndpointRequest,
113
+ options?: CallOptions
114
+ ): Promise<InferenceEndpointDetailed> {
115
+ const url = `${this.host}/api/2.0/serving-endpoints`;
116
+ const body = marshalRequest(
117
+ req,
118
+ marshalCreateInferenceEndpointRequestSchema
119
+ );
120
+ let resp: InferenceEndpointDetailed | undefined;
121
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
122
+ const headers = new Headers({'Content-Type': 'application/json'});
123
+ if (this.workspaceId !== undefined) {
124
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
125
+ }
126
+ headers.set('User-Agent', this.userAgent);
127
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
128
+ const respBody = await executeHttpCall({
129
+ request: httpReq,
130
+ httpClient: this.httpClient,
131
+ logger: this.logger,
132
+ });
133
+ resp = parseResponse(respBody, unmarshalInferenceEndpointDetailedSchema);
134
+ };
135
+ await executeCall(call, options);
136
+ if (resp === undefined) {
137
+ throw new Error('API call completed without a result.');
138
+ }
139
+ return resp;
140
+ }
141
+
142
+ async createInferenceEndpointWaiter(
143
+ req: CreateInferenceEndpointRequest,
144
+ options?: CallOptions
145
+ ): Promise<CreateInferenceEndpointWaiter> {
146
+ await this.createInferenceEndpoint(req, options);
147
+ if (req.name === undefined) {
148
+ throw new Error('request field name required for polling is missing');
149
+ }
150
+ return new CreateInferenceEndpointWaiter(this, req.name);
151
+ }
152
+
153
+ /** Create a new PT serving endpoint. */
154
+ async createProvisionedThroughputInferenceEndpoint(
155
+ req: CreatePtEndpointRequest,
156
+ options?: CallOptions
157
+ ): Promise<InferenceEndpointDetailed> {
158
+ const url = `${this.host}/api/2.0/serving-endpoints/pt`;
159
+ const body = marshalRequest(req, marshalCreatePtEndpointRequestSchema);
160
+ let resp: InferenceEndpointDetailed | undefined;
161
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
162
+ const headers = new Headers({'Content-Type': 'application/json'});
163
+ if (this.workspaceId !== undefined) {
164
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
165
+ }
166
+ headers.set('User-Agent', this.userAgent);
167
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
168
+ const respBody = await executeHttpCall({
169
+ request: httpReq,
170
+ httpClient: this.httpClient,
171
+ logger: this.logger,
172
+ });
173
+ resp = parseResponse(respBody, unmarshalInferenceEndpointDetailedSchema);
174
+ };
175
+ await executeCall(call, options);
176
+ if (resp === undefined) {
177
+ throw new Error('API call completed without a result.');
178
+ }
179
+ return resp;
180
+ }
181
+
182
+ async createProvisionedThroughputInferenceEndpointWaiter(
183
+ req: CreatePtEndpointRequest,
184
+ options?: CallOptions
185
+ ): Promise<CreateProvisionedThroughputInferenceEndpointWaiter> {
186
+ await this.createProvisionedThroughputInferenceEndpoint(req, options);
187
+ if (req.name === undefined) {
188
+ throw new Error('request field name required for polling is missing');
189
+ }
190
+ return new CreateProvisionedThroughputInferenceEndpointWaiter(
191
+ this,
192
+ req.name
193
+ );
194
+ }
195
+
196
+ /** Delete a serving endpoint. */
197
+ async deleteInferenceEndpoint(
198
+ req: DeleteInferenceEndpointRequest,
199
+ options?: CallOptions
200
+ ): Promise<DeleteInferenceEndpointRequest_Response> {
201
+ const url = `${this.host}/api/2.0/serving-endpoints/${req.name ?? ''}`;
202
+ let resp: DeleteInferenceEndpointRequest_Response | undefined;
203
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
204
+ const headers = new Headers();
205
+ if (this.workspaceId !== undefined) {
206
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
207
+ }
208
+ headers.set('User-Agent', this.userAgent);
209
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
210
+ const respBody = await executeHttpCall({
211
+ request: httpReq,
212
+ httpClient: this.httpClient,
213
+ logger: this.logger,
214
+ });
215
+ resp = parseResponse(
216
+ respBody,
217
+ unmarshalDeleteInferenceEndpointRequest_ResponseSchema
218
+ );
219
+ };
220
+ await executeCall(call, options);
221
+ if (resp === undefined) {
222
+ throw new Error('API call completed without a result.');
223
+ }
224
+ return resp;
225
+ }
226
+
227
+ /** Retrieves the metrics associated with the provided serving endpoint in either Prometheus or OpenMetrics exposition format. */
228
+ async getExportEndpointMetrics(
229
+ req: GetExportEndpointMetricsRequest,
230
+ options?: CallOptions
231
+ ): Promise<ExportMetricsResponse> {
232
+ const url = `${this.host}/api/2.0/serving-endpoints/${req.name ?? ''}/metrics`;
233
+ let resp: ExportMetricsResponse | undefined;
234
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
235
+ const headers = new Headers();
236
+ if (this.workspaceId !== undefined) {
237
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
238
+ }
239
+ headers.set('User-Agent', this.userAgent);
240
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
241
+ const httpResp = await sendAndCheckError({
242
+ request: httpReq,
243
+ httpClient: this.httpClient,
244
+ logger: this.logger,
245
+ });
246
+ resp = {
247
+ contents: httpResp.body ?? undefined,
248
+ };
249
+ };
250
+ await executeCall(call, options);
251
+ if (resp === undefined) {
252
+ throw new Error('API call completed without a result.');
253
+ }
254
+ return resp;
255
+ }
256
+
257
+ /** Retrieves the details for a single serving endpoint. */
258
+ async getInferenceEndpoint(
259
+ req: GetInferenceEndpointRequest,
260
+ options?: CallOptions
261
+ ): Promise<InferenceEndpointDetailed> {
262
+ const url = `${this.host}/api/2.0/serving-endpoints/${req.name ?? ''}`;
263
+ let resp: InferenceEndpointDetailed | undefined;
264
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
265
+ const headers = new Headers();
266
+ if (this.workspaceId !== undefined) {
267
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
268
+ }
269
+ headers.set('User-Agent', this.userAgent);
270
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
271
+ const respBody = await executeHttpCall({
272
+ request: httpReq,
273
+ httpClient: this.httpClient,
274
+ logger: this.logger,
275
+ });
276
+ resp = parseResponse(respBody, unmarshalInferenceEndpointDetailedSchema);
277
+ };
278
+ await executeCall(call, options);
279
+ if (resp === undefined) {
280
+ throw new Error('API call completed without a result.');
281
+ }
282
+ return resp;
283
+ }
284
+
285
+ /** Get the query schema of the serving endpoint in OpenAPI format. The schema contains information for the supported paths, input and output format and datatypes. */
286
+ async getInferenceEndpointSchema(
287
+ req: GetInferenceEndpointSchemaRequest,
288
+ options?: CallOptions
289
+ ): Promise<GetOpenApiResponse> {
290
+ const url = `${this.host}/api/2.0/serving-endpoints/${req.name ?? ''}/openapi`;
291
+ let resp: GetOpenApiResponse | undefined;
292
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
293
+ const headers = new Headers();
294
+ if (this.workspaceId !== undefined) {
295
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
296
+ }
297
+ headers.set('User-Agent', this.userAgent);
298
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
299
+ const httpResp = await sendAndCheckError({
300
+ request: httpReq,
301
+ httpClient: this.httpClient,
302
+ logger: this.logger,
303
+ });
304
+ resp = {
305
+ contents: httpResp.body ?? undefined,
306
+ };
307
+ };
308
+ await executeCall(call, options);
309
+ if (resp === undefined) {
310
+ throw new Error('API call completed without a result.');
311
+ }
312
+ return resp;
313
+ }
314
+
315
+ /** Retrieves the build logs associated with the provided served model. */
316
+ async getServedModelBuildLogs(
317
+ req: GetServedModelBuildLogsRequest,
318
+ options?: CallOptions
319
+ ): Promise<GetServedModelBuildLogsRequest_Response> {
320
+ const url = `${this.host}/api/2.0/serving-endpoints/${req.name ?? ''}/served-models/${req.servedModelName ?? ''}/build-logs`;
321
+ let resp: GetServedModelBuildLogsRequest_Response | undefined;
322
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
323
+ const headers = new Headers();
324
+ if (this.workspaceId !== undefined) {
325
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
326
+ }
327
+ headers.set('User-Agent', this.userAgent);
328
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
329
+ const respBody = await executeHttpCall({
330
+ request: httpReq,
331
+ httpClient: this.httpClient,
332
+ logger: this.logger,
333
+ });
334
+ resp = parseResponse(
335
+ respBody,
336
+ unmarshalGetServedModelBuildLogsRequest_ResponseSchema
337
+ );
338
+ };
339
+ await executeCall(call, options);
340
+ if (resp === undefined) {
341
+ throw new Error('API call completed without a result.');
342
+ }
343
+ return resp;
344
+ }
345
+
346
+ /** Retrieves the service logs associated with the provided served model. */
347
+ async getServedModelLogs(
348
+ req: GetServedModelLogsRequest,
349
+ options?: CallOptions
350
+ ): Promise<GetServedModelLogsRequest_Response> {
351
+ const url = `${this.host}/api/2.0/serving-endpoints/${req.name ?? ''}/served-models/${req.servedModelName ?? ''}/logs`;
352
+ let resp: GetServedModelLogsRequest_Response | undefined;
353
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
354
+ const headers = new Headers();
355
+ if (this.workspaceId !== undefined) {
356
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
357
+ }
358
+ headers.set('User-Agent', this.userAgent);
359
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
360
+ const respBody = await executeHttpCall({
361
+ request: httpReq,
362
+ httpClient: this.httpClient,
363
+ logger: this.logger,
364
+ });
365
+ resp = parseResponse(
366
+ respBody,
367
+ unmarshalGetServedModelLogsRequest_ResponseSchema
368
+ );
369
+ };
370
+ await executeCall(call, options);
371
+ if (resp === undefined) {
372
+ throw new Error('API call completed without a result.');
373
+ }
374
+ return resp;
375
+ }
376
+
377
+ /** Get all serving endpoints. */
378
+ async listInferenceEndpoints(
379
+ _req: ListInferenceEndpointsRequest,
380
+ options?: CallOptions
381
+ ): Promise<ListInferenceEndpointsRequest_Response> {
382
+ const url = `${this.host}/api/2.0/serving-endpoints`;
383
+ let resp: ListInferenceEndpointsRequest_Response | undefined;
384
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
385
+ const headers = new Headers();
386
+ if (this.workspaceId !== undefined) {
387
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
388
+ }
389
+ headers.set('User-Agent', this.userAgent);
390
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
391
+ const respBody = await executeHttpCall({
392
+ request: httpReq,
393
+ httpClient: this.httpClient,
394
+ logger: this.logger,
395
+ });
396
+ resp = parseResponse(
397
+ respBody,
398
+ unmarshalListInferenceEndpointsRequest_ResponseSchema
399
+ );
400
+ };
401
+ await executeCall(call, options);
402
+ if (resp === undefined) {
403
+ throw new Error('API call completed without a result.');
404
+ }
405
+ return resp;
406
+ }
407
+
408
+ /** Used to batch add and delete tags from a serving endpoint with a single API call. */
409
+ async patchInferenceEndpointTags(
410
+ req: PatchInferenceEndpointTagsRequest,
411
+ options?: CallOptions
412
+ ): Promise<PatchInferenceEndpointTagsRequest_Response> {
413
+ const url = `${this.host}/api/2.0/serving-endpoints/${req.name ?? ''}/tags`;
414
+ const body = marshalRequest(
415
+ req,
416
+ marshalPatchInferenceEndpointTagsRequestSchema
417
+ );
418
+ let resp: PatchInferenceEndpointTagsRequest_Response | undefined;
419
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
420
+ const headers = new Headers({'Content-Type': 'application/json'});
421
+ if (this.workspaceId !== undefined) {
422
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
423
+ }
424
+ headers.set('User-Agent', this.userAgent);
425
+ const httpReq = buildHttpRequest('PATCH', url, headers, callSignal, body);
426
+ const respBody = await executeHttpCall({
427
+ request: httpReq,
428
+ httpClient: this.httpClient,
429
+ logger: this.logger,
430
+ });
431
+ resp = parseResponse(
432
+ respBody,
433
+ unmarshalPatchInferenceEndpointTagsRequest_ResponseSchema
434
+ );
435
+ };
436
+ await executeCall(call, options);
437
+ if (resp === undefined) {
438
+ throw new Error('API call completed without a result.');
439
+ }
440
+ return resp;
441
+ }
442
+
443
+ /** Used to update the AI Gateway of a serving endpoint. NOTE: External model, provisioned throughput, and pay-per-token endpoints are fully supported; agent endpoints currently only support inference tables. */
444
+ async putInferenceEndpointAiGateway(
445
+ req: PutInferenceEndpointAiGatewayRequest,
446
+ options?: CallOptions
447
+ ): Promise<PutInferenceEndpointAiGatewayRequest_Response> {
448
+ const url = `${this.host}/api/2.0/serving-endpoints/${req.name ?? ''}/ai-gateway`;
449
+ const body = marshalRequest(
450
+ req,
451
+ marshalPutInferenceEndpointAiGatewayRequestSchema
452
+ );
453
+ let resp: PutInferenceEndpointAiGatewayRequest_Response | undefined;
454
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
455
+ const headers = new Headers({'Content-Type': 'application/json'});
456
+ if (this.workspaceId !== undefined) {
457
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
458
+ }
459
+ headers.set('User-Agent', this.userAgent);
460
+ const httpReq = buildHttpRequest('PUT', url, headers, callSignal, body);
461
+ const respBody = await executeHttpCall({
462
+ request: httpReq,
463
+ httpClient: this.httpClient,
464
+ logger: this.logger,
465
+ });
466
+ resp = parseResponse(
467
+ respBody,
468
+ unmarshalPutInferenceEndpointAiGatewayRequest_ResponseSchema
469
+ );
470
+ };
471
+ await executeCall(call, options);
472
+ if (resp === undefined) {
473
+ throw new Error('API call completed without a result.');
474
+ }
475
+ return resp;
476
+ }
477
+
478
+ /** Updates any combination of the serving endpoint's served entities, the compute configuration of those served entities, and the endpoint's traffic config. An endpoint that already has an update in progress can not be updated until the current update completes or fails. */
479
+ async putInferenceEndpointConfig(
480
+ req: PutInferenceEndpointConfigRequest,
481
+ options?: CallOptions
482
+ ): Promise<InferenceEndpointDetailed> {
483
+ const url = `${this.host}/api/2.0/serving-endpoints/${req.name ?? ''}/config`;
484
+ const body = marshalRequest(
485
+ req,
486
+ marshalPutInferenceEndpointConfigRequestSchema
487
+ );
488
+ let resp: InferenceEndpointDetailed | undefined;
489
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
490
+ const headers = new Headers({'Content-Type': 'application/json'});
491
+ if (this.workspaceId !== undefined) {
492
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
493
+ }
494
+ headers.set('User-Agent', this.userAgent);
495
+ const httpReq = buildHttpRequest('PUT', url, headers, callSignal, body);
496
+ const respBody = await executeHttpCall({
497
+ request: httpReq,
498
+ httpClient: this.httpClient,
499
+ logger: this.logger,
500
+ });
501
+ resp = parseResponse(respBody, unmarshalInferenceEndpointDetailedSchema);
502
+ };
503
+ await executeCall(call, options);
504
+ if (resp === undefined) {
505
+ throw new Error('API call completed without a result.');
506
+ }
507
+ return resp;
508
+ }
509
+
510
+ async putInferenceEndpointConfigWaiter(
511
+ req: PutInferenceEndpointConfigRequest,
512
+ options?: CallOptions
513
+ ): Promise<PutInferenceEndpointConfigWaiter> {
514
+ await this.putInferenceEndpointConfig(req, options);
515
+ if (req.name === undefined) {
516
+ throw new Error('request field name required for polling is missing');
517
+ }
518
+ return new PutInferenceEndpointConfigWaiter(this, req.name);
519
+ }
520
+
521
+ /** Deprecated: Please use AI Gateway to manage rate limits instead. */
522
+ async putInferenceEndpointRateLimits(
523
+ req: PutInferenceEndpointRateLimitsRequest,
524
+ options?: CallOptions
525
+ ): Promise<PutInferenceEndpointRateLimitsRequest_Response> {
526
+ const url = `${this.host}/api/2.0/serving-endpoints/${req.name ?? ''}/rate-limits`;
527
+ const body = marshalRequest(
528
+ req,
529
+ marshalPutInferenceEndpointRateLimitsRequestSchema
530
+ );
531
+ let resp: PutInferenceEndpointRateLimitsRequest_Response | undefined;
532
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
533
+ const headers = new Headers({'Content-Type': 'application/json'});
534
+ if (this.workspaceId !== undefined) {
535
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
536
+ }
537
+ headers.set('User-Agent', this.userAgent);
538
+ const httpReq = buildHttpRequest('PUT', url, headers, callSignal, body);
539
+ const respBody = await executeHttpCall({
540
+ request: httpReq,
541
+ httpClient: this.httpClient,
542
+ logger: this.logger,
543
+ });
544
+ resp = parseResponse(
545
+ respBody,
546
+ unmarshalPutInferenceEndpointRateLimitsRequest_ResponseSchema
547
+ );
548
+ };
549
+ await executeCall(call, options);
550
+ if (resp === undefined) {
551
+ throw new Error('API call completed without a result.');
552
+ }
553
+ return resp;
554
+ }
555
+
556
+ /** Updates any combination of the pt endpoint's served entities, the compute configuration of those served entities, and the endpoint's traffic config. Updates are instantaneous and endpoint should be updated instantly */
557
+ async putProvisionedThroughputInferenceEndpointConfig(
558
+ req: PutPtEndpointConfigRequest,
559
+ options?: CallOptions
560
+ ): Promise<InferenceEndpointDetailed> {
561
+ const url = `${this.host}/api/2.0/serving-endpoints/pt/${req.name ?? ''}/config`;
562
+ const body = marshalRequest(req, marshalPutPtEndpointConfigRequestSchema);
563
+ let resp: InferenceEndpointDetailed | undefined;
564
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
565
+ const headers = new Headers({'Content-Type': 'application/json'});
566
+ if (this.workspaceId !== undefined) {
567
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
568
+ }
569
+ headers.set('User-Agent', this.userAgent);
570
+ const httpReq = buildHttpRequest('PUT', url, headers, callSignal, body);
571
+ const respBody = await executeHttpCall({
572
+ request: httpReq,
573
+ httpClient: this.httpClient,
574
+ logger: this.logger,
575
+ });
576
+ resp = parseResponse(respBody, unmarshalInferenceEndpointDetailedSchema);
577
+ };
578
+ await executeCall(call, options);
579
+ if (resp === undefined) {
580
+ throw new Error('API call completed without a result.');
581
+ }
582
+ return resp;
583
+ }
584
+
585
+ async putProvisionedThroughputInferenceEndpointConfigWaiter(
586
+ req: PutPtEndpointConfigRequest,
587
+ options?: CallOptions
588
+ ): Promise<PutProvisionedThroughputInferenceEndpointConfigWaiter> {
589
+ await this.putProvisionedThroughputInferenceEndpointConfig(req, options);
590
+ if (req.name === undefined) {
591
+ throw new Error('request field name required for polling is missing');
592
+ }
593
+ return new PutProvisionedThroughputInferenceEndpointConfigWaiter(
594
+ this,
595
+ req.name
596
+ );
597
+ }
598
+
599
+ /** Updates the email and webhook notification settings for an endpoint. */
600
+ async updateInferenceEndpointNotifications(
601
+ req: UpdateInferenceEndpointNotificationsRequest,
602
+ options?: CallOptions
603
+ ): Promise<UpdateInferenceEndpointNotificationsRequest_Response> {
604
+ const url = `${this.host}/api/2.0/serving-endpoints/${req.name ?? ''}/notifications`;
605
+ const body = marshalRequest(
606
+ req,
607
+ marshalUpdateInferenceEndpointNotificationsRequestSchema
608
+ );
609
+ let resp: UpdateInferenceEndpointNotificationsRequest_Response | undefined;
610
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
611
+ const headers = new Headers({'Content-Type': 'application/json'});
612
+ if (this.workspaceId !== undefined) {
613
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
614
+ }
615
+ headers.set('User-Agent', this.userAgent);
616
+ const httpReq = buildHttpRequest('PATCH', url, headers, callSignal, body);
617
+ const respBody = await executeHttpCall({
618
+ request: httpReq,
619
+ httpClient: this.httpClient,
620
+ logger: this.logger,
621
+ });
622
+ resp = parseResponse(
623
+ respBody,
624
+ unmarshalUpdateInferenceEndpointNotificationsRequest_ResponseSchema
625
+ );
626
+ };
627
+ await executeCall(call, options);
628
+ if (resp === undefined) {
629
+ throw new Error('API call completed without a result.');
630
+ }
631
+ return resp;
632
+ }
633
+
634
+ /** Make external services call using the credentials stored in UC Connection. */
635
+ async httpRequest(
636
+ req: ExternalFunctionRequest,
637
+ options?: CallOptions
638
+ ): Promise<ExternalFunctionResponse> {
639
+ const url = `${this.host}/api/2.0/external-function`;
640
+ const body = marshalRequest(req, marshalExternalFunctionRequestSchema);
641
+ let resp: ExternalFunctionResponse | undefined;
642
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
643
+ const headers = new Headers({'Content-Type': 'application/json'});
644
+ if (this.workspaceId !== undefined) {
645
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
646
+ }
647
+ headers.set('User-Agent', this.userAgent);
648
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
649
+ const httpResp = await sendAndCheckError({
650
+ request: httpReq,
651
+ httpClient: this.httpClient,
652
+ logger: this.logger,
653
+ });
654
+ resp = {
655
+ contents: httpResp.body ?? undefined,
656
+ };
657
+ };
658
+ await executeCall(call, options);
659
+ if (resp === undefined) {
660
+ throw new Error('API call completed without a result.');
661
+ }
662
+ return resp;
663
+ }
664
+ }
665
+
666
+ export class CreateInferenceEndpointWaiter {
667
+ constructor(
668
+ private readonly client: ModelservingClient,
669
+ readonly name: string
670
+ ) {}
671
+
672
+ /**
673
+ * Polls until the operation reaches a terminal state.
674
+ *
675
+ * Throws if a failure state is reached.
676
+ */
677
+ async wait(options?: CallOptions): Promise<InferenceEndpointDetailed> {
678
+ let result: InferenceEndpointDetailed | undefined;
679
+
680
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
681
+ const pollResp = await this.client.getInferenceEndpoint(
682
+ {
683
+ name: this.name,
684
+ },
685
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
686
+ );
687
+
688
+ const status = pollResp.state?.configUpdate;
689
+ if (status === undefined) {
690
+ throw new Error('response missing required status field');
691
+ }
692
+
693
+ switch (status) {
694
+ case InferenceEndpointState_ConfigUpdateState.NOT_UPDATING:
695
+ result = pollResp;
696
+ return;
697
+ case InferenceEndpointState_ConfigUpdateState.UPDATE_FAILED:
698
+ case InferenceEndpointState_ConfigUpdateState.UPDATE_CANCELED: {
699
+ const msg = '(no message)';
700
+ throw new Error(`terminal state ${status}: ${msg}`);
701
+ }
702
+ default:
703
+ throw new StillRunningError();
704
+ }
705
+ };
706
+
707
+ const retryOptions: CallOptions = {
708
+ ...(options?.signal !== undefined && {signal: options.signal}),
709
+ retrier: () =>
710
+ retryOn({}, (err: Error) => {
711
+ return err instanceof StillRunningError;
712
+ }),
713
+ };
714
+ await executeCall(call, retryOptions);
715
+ if (result === undefined) {
716
+ throw new Error('API call completed without a result.');
717
+ }
718
+ return result;
719
+ }
720
+
721
+ /** Checks whether the operation has reached a terminal state. */
722
+ async done(options?: CallOptions): Promise<boolean> {
723
+ const pollResp = await this.client.getInferenceEndpoint(
724
+ {
725
+ name: this.name,
726
+ },
727
+ options
728
+ );
729
+
730
+ const status = pollResp.state?.configUpdate;
731
+ if (status === undefined) {
732
+ throw new Error('response missing required status field');
733
+ }
734
+
735
+ switch (status) {
736
+ case InferenceEndpointState_ConfigUpdateState.NOT_UPDATING:
737
+ case InferenceEndpointState_ConfigUpdateState.UPDATE_FAILED:
738
+ case InferenceEndpointState_ConfigUpdateState.UPDATE_CANCELED:
739
+ return true;
740
+ default:
741
+ return false;
742
+ }
743
+ }
744
+ }
745
+
746
+ export class CreateProvisionedThroughputInferenceEndpointWaiter {
747
+ constructor(
748
+ private readonly client: ModelservingClient,
749
+ readonly name: string
750
+ ) {}
751
+
752
+ /**
753
+ * Polls until the operation reaches a terminal state.
754
+ *
755
+ * Throws if a failure state is reached.
756
+ */
757
+ async wait(options?: CallOptions): Promise<InferenceEndpointDetailed> {
758
+ let result: InferenceEndpointDetailed | undefined;
759
+
760
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
761
+ const pollResp = await this.client.getInferenceEndpoint(
762
+ {
763
+ name: this.name,
764
+ },
765
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
766
+ );
767
+
768
+ const status = pollResp.state?.configUpdate;
769
+ if (status === undefined) {
770
+ throw new Error('response missing required status field');
771
+ }
772
+
773
+ switch (status) {
774
+ case InferenceEndpointState_ConfigUpdateState.NOT_UPDATING:
775
+ result = pollResp;
776
+ return;
777
+ case InferenceEndpointState_ConfigUpdateState.UPDATE_FAILED:
778
+ case InferenceEndpointState_ConfigUpdateState.UPDATE_CANCELED: {
779
+ const msg = '(no message)';
780
+ throw new Error(`terminal state ${status}: ${msg}`);
781
+ }
782
+ default:
783
+ throw new StillRunningError();
784
+ }
785
+ };
786
+
787
+ const retryOptions: CallOptions = {
788
+ ...(options?.signal !== undefined && {signal: options.signal}),
789
+ retrier: () =>
790
+ retryOn({}, (err: Error) => {
791
+ return err instanceof StillRunningError;
792
+ }),
793
+ };
794
+ await executeCall(call, retryOptions);
795
+ if (result === undefined) {
796
+ throw new Error('API call completed without a result.');
797
+ }
798
+ return result;
799
+ }
800
+
801
+ /** Checks whether the operation has reached a terminal state. */
802
+ async done(options?: CallOptions): Promise<boolean> {
803
+ const pollResp = await this.client.getInferenceEndpoint(
804
+ {
805
+ name: this.name,
806
+ },
807
+ options
808
+ );
809
+
810
+ const status = pollResp.state?.configUpdate;
811
+ if (status === undefined) {
812
+ throw new Error('response missing required status field');
813
+ }
814
+
815
+ switch (status) {
816
+ case InferenceEndpointState_ConfigUpdateState.NOT_UPDATING:
817
+ case InferenceEndpointState_ConfigUpdateState.UPDATE_FAILED:
818
+ case InferenceEndpointState_ConfigUpdateState.UPDATE_CANCELED:
819
+ return true;
820
+ default:
821
+ return false;
822
+ }
823
+ }
824
+ }
825
+
826
+ export class PutInferenceEndpointConfigWaiter {
827
+ constructor(
828
+ private readonly client: ModelservingClient,
829
+ readonly name: string
830
+ ) {}
831
+
832
+ /**
833
+ * Polls until the operation reaches a terminal state.
834
+ *
835
+ * Throws if a failure state is reached.
836
+ */
837
+ async wait(options?: CallOptions): Promise<InferenceEndpointDetailed> {
838
+ let result: InferenceEndpointDetailed | undefined;
839
+
840
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
841
+ const pollResp = await this.client.getInferenceEndpoint(
842
+ {
843
+ name: this.name,
844
+ },
845
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
846
+ );
847
+
848
+ const status = pollResp.state?.configUpdate;
849
+ if (status === undefined) {
850
+ throw new Error('response missing required status field');
851
+ }
852
+
853
+ switch (status) {
854
+ case InferenceEndpointState_ConfigUpdateState.NOT_UPDATING:
855
+ result = pollResp;
856
+ return;
857
+ case InferenceEndpointState_ConfigUpdateState.UPDATE_FAILED:
858
+ case InferenceEndpointState_ConfigUpdateState.UPDATE_CANCELED: {
859
+ const msg = '(no message)';
860
+ throw new Error(`terminal state ${status}: ${msg}`);
861
+ }
862
+ default:
863
+ throw new StillRunningError();
864
+ }
865
+ };
866
+
867
+ const retryOptions: CallOptions = {
868
+ ...(options?.signal !== undefined && {signal: options.signal}),
869
+ retrier: () =>
870
+ retryOn({}, (err: Error) => {
871
+ return err instanceof StillRunningError;
872
+ }),
873
+ };
874
+ await executeCall(call, retryOptions);
875
+ if (result === undefined) {
876
+ throw new Error('API call completed without a result.');
877
+ }
878
+ return result;
879
+ }
880
+
881
+ /** Checks whether the operation has reached a terminal state. */
882
+ async done(options?: CallOptions): Promise<boolean> {
883
+ const pollResp = await this.client.getInferenceEndpoint(
884
+ {
885
+ name: this.name,
886
+ },
887
+ options
888
+ );
889
+
890
+ const status = pollResp.state?.configUpdate;
891
+ if (status === undefined) {
892
+ throw new Error('response missing required status field');
893
+ }
894
+
895
+ switch (status) {
896
+ case InferenceEndpointState_ConfigUpdateState.NOT_UPDATING:
897
+ case InferenceEndpointState_ConfigUpdateState.UPDATE_FAILED:
898
+ case InferenceEndpointState_ConfigUpdateState.UPDATE_CANCELED:
899
+ return true;
900
+ default:
901
+ return false;
902
+ }
903
+ }
904
+ }
905
+
906
+ export class PutProvisionedThroughputInferenceEndpointConfigWaiter {
907
+ constructor(
908
+ private readonly client: ModelservingClient,
909
+ readonly name: string
910
+ ) {}
911
+
912
+ /**
913
+ * Polls until the operation reaches a terminal state.
914
+ *
915
+ * Throws if a failure state is reached.
916
+ */
917
+ async wait(options?: CallOptions): Promise<InferenceEndpointDetailed> {
918
+ let result: InferenceEndpointDetailed | undefined;
919
+
920
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
921
+ const pollResp = await this.client.getInferenceEndpoint(
922
+ {
923
+ name: this.name,
924
+ },
925
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
926
+ );
927
+
928
+ const status = pollResp.state?.configUpdate;
929
+ if (status === undefined) {
930
+ throw new Error('response missing required status field');
931
+ }
932
+
933
+ switch (status) {
934
+ case InferenceEndpointState_ConfigUpdateState.NOT_UPDATING:
935
+ result = pollResp;
936
+ return;
937
+ case InferenceEndpointState_ConfigUpdateState.UPDATE_FAILED:
938
+ case InferenceEndpointState_ConfigUpdateState.UPDATE_CANCELED: {
939
+ const msg = '(no message)';
940
+ throw new Error(`terminal state ${status}: ${msg}`);
941
+ }
942
+ default:
943
+ throw new StillRunningError();
944
+ }
945
+ };
946
+
947
+ const retryOptions: CallOptions = {
948
+ ...(options?.signal !== undefined && {signal: options.signal}),
949
+ retrier: () =>
950
+ retryOn({}, (err: Error) => {
951
+ return err instanceof StillRunningError;
952
+ }),
953
+ };
954
+ await executeCall(call, retryOptions);
955
+ if (result === undefined) {
956
+ throw new Error('API call completed without a result.');
957
+ }
958
+ return result;
959
+ }
960
+
961
+ /** Checks whether the operation has reached a terminal state. */
962
+ async done(options?: CallOptions): Promise<boolean> {
963
+ const pollResp = await this.client.getInferenceEndpoint(
964
+ {
965
+ name: this.name,
966
+ },
967
+ options
968
+ );
969
+
970
+ const status = pollResp.state?.configUpdate;
971
+ if (status === undefined) {
972
+ throw new Error('response missing required status field');
973
+ }
974
+
975
+ switch (status) {
976
+ case InferenceEndpointState_ConfigUpdateState.NOT_UPDATING:
977
+ case InferenceEndpointState_ConfigUpdateState.UPDATE_FAILED:
978
+ case InferenceEndpointState_ConfigUpdateState.UPDATE_CANCELED:
979
+ return true;
980
+ default:
981
+ return false;
982
+ }
983
+ }
984
+ }