cloudflare/cloudflare-typescript

Public

mirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v6.0.0-beta.2

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/resources/ai-gateway/logs.ts

622lines · modecode

1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3import { APIResource } from '../../resource';
4import { isRequestOptions } from '../../core';
5import * as Core from '../../core';
6import { V4PagePaginationArray, type V4PagePaginationArrayParams } from '../../pagination';
7
8export class Logs extends APIResource {
9 /**
10 * List Gateway Logs
11 *
12 * @example
13 * ```ts
14 * // Automatically fetches more pages as needed.
15 * for await (const logListResponse of client.aiGateway.logs.list(
16 * 'my-gateway',
17 * { account_id: '0d37909e38d3e99c29fa2cd343ac421a' },
18 * )) {
19 * // ...
20 * }
21 * ```
22 */
23 list(
24 gatewayId: string,
25 params?: LogListParams,
26 options?: Core.RequestOptions,
27 ): Core.PagePromise<LogListResponsesV4PagePaginationArray, LogListResponse>;
28 list(
29 gatewayId: string,
30 options?: Core.RequestOptions,
31 ): Core.PagePromise<LogListResponsesV4PagePaginationArray, LogListResponse>;
32 list(
33 gatewayId: string,
34 params: LogListParams | Core.RequestOptions = {},
35 options?: Core.RequestOptions,
36 ): Core.PagePromise<LogListResponsesV4PagePaginationArray, LogListResponse> {
37 if (isRequestOptions(params)) {
38 return this.list(gatewayId, {}, params);
39 }
40 const { account_id = this._client.accountId, ...query } = params;
41 return this._client.getAPIList(
42 `/accounts/${account_id}/ai-gateway/gateways/${gatewayId}/logs`,
43 LogListResponsesV4PagePaginationArray,
44 { query, ...options },
45 );
46 }
47
48 /**
49 * Delete Gateway Logs
50 *
51 * @example
52 * ```ts
53 * const log = await client.aiGateway.logs.delete(
54 * 'my-gateway',
55 * { account_id: '0d37909e38d3e99c29fa2cd343ac421a' },
56 * );
57 * ```
58 */
59 delete(
60 gatewayId: string,
61 params?: LogDeleteParams,
62 options?: Core.RequestOptions,
63 ): Core.APIPromise<LogDeleteResponse>;
64 delete(gatewayId: string, options?: Core.RequestOptions): Core.APIPromise<LogDeleteResponse>;
65 delete(
66 gatewayId: string,
67 params: LogDeleteParams | Core.RequestOptions = {},
68 options?: Core.RequestOptions,
69 ): Core.APIPromise<LogDeleteResponse> {
70 if (isRequestOptions(params)) {
71 return this.delete(gatewayId, {}, params);
72 }
73 const { account_id = this._client.accountId, filters, limit, order_by, order_by_direction } = params;
74 return this._client.delete(`/accounts/${account_id}/ai-gateway/gateways/${gatewayId}/logs`, {
75 query: { filters, limit, order_by, order_by_direction },
76 ...options,
77 });
78 }
79
80 /**
81 * Updates metadata for an AI Gateway log entry.
82 *
83 * @example
84 * ```ts
85 * const response = await client.aiGateway.logs.edit(
86 * 'my-gateway',
87 * 'id',
88 * { account_id: '0d37909e38d3e99c29fa2cd343ac421a' },
89 * );
90 * ```
91 */
92 edit(
93 gatewayId: string,
94 id: string,
95 params?: LogEditParams,
96 options?: Core.RequestOptions,
97 ): Core.APIPromise<LogEditResponse>;
98 edit(gatewayId: string, id: string, options?: Core.RequestOptions): Core.APIPromise<LogEditResponse>;
99 edit(
100 gatewayId: string,
101 id: string,
102 params: LogEditParams | Core.RequestOptions = {},
103 options?: Core.RequestOptions,
104 ): Core.APIPromise<LogEditResponse> {
105 if (isRequestOptions(params)) {
106 return this.edit(gatewayId, id, {}, params);
107 }
108 const { account_id = this._client.accountId, ...body } = params;
109 return (
110 this._client.patch(`/accounts/${account_id}/ai-gateway/gateways/${gatewayId}/logs/${id}`, {
111 body,
112 ...options,
113 }) as Core.APIPromise<{ result: LogEditResponse }>
114 )._thenUnwrap((obj) => obj.result);
115 }
116
117 /**
118 * Retrieves detailed information for a specific AI Gateway log entry.
119 *
120 * @example
121 * ```ts
122 * const log = await client.aiGateway.logs.get(
123 * 'my-gateway',
124 * 'id',
125 * { account_id: '0d37909e38d3e99c29fa2cd343ac421a' },
126 * );
127 * ```
128 */
129 get(
130 gatewayId: string,
131 id: string,
132 params?: LogGetParams,
133 options?: Core.RequestOptions,
134 ): Core.APIPromise<LogGetResponse>;
135 get(gatewayId: string, id: string, options?: Core.RequestOptions): Core.APIPromise<LogGetResponse>;
136 get(
137 gatewayId: string,
138 id: string,
139 params: LogGetParams | Core.RequestOptions = {},
140 options?: Core.RequestOptions,
141 ): Core.APIPromise<LogGetResponse> {
142 if (isRequestOptions(params)) {
143 return this.get(gatewayId, id, {}, params);
144 }
145 const { account_id = this._client.accountId } = params;
146 return (
147 this._client.get(
148 `/accounts/${account_id}/ai-gateway/gateways/${gatewayId}/logs/${id}`,
149 options,
150 ) as Core.APIPromise<{ result: LogGetResponse }>
151 )._thenUnwrap((obj) => obj.result);
152 }
153
154 /**
155 * Retrieves the original request payload for an AI Gateway log entry.
156 *
157 * @example
158 * ```ts
159 * const response = await client.aiGateway.logs.request(
160 * 'my-gateway',
161 * 'id',
162 * { account_id: '0d37909e38d3e99c29fa2cd343ac421a' },
163 * );
164 * ```
165 */
166 request(
167 gatewayId: string,
168 id: string,
169 params?: LogRequestParams,
170 options?: Core.RequestOptions,
171 ): Core.APIPromise<unknown>;
172 request(gatewayId: string, id: string, options?: Core.RequestOptions): Core.APIPromise<unknown>;
173 request(
174 gatewayId: string,
175 id: string,
176 params: LogRequestParams | Core.RequestOptions = {},
177 options?: Core.RequestOptions,
178 ): Core.APIPromise<unknown> {
179 if (isRequestOptions(params)) {
180 return this.request(gatewayId, id, {}, params);
181 }
182 const { account_id = this._client.accountId } = params;
183 return this._client.get(
184 `/accounts/${account_id}/ai-gateway/gateways/${gatewayId}/logs/${id}/request`,
185 options,
186 );
187 }
188
189 /**
190 * Retrieves the response payload for an AI Gateway log entry.
191 *
192 * @example
193 * ```ts
194 * const response = await client.aiGateway.logs.response(
195 * 'my-gateway',
196 * 'id',
197 * { account_id: '0d37909e38d3e99c29fa2cd343ac421a' },
198 * );
199 * ```
200 */
201 response(
202 gatewayId: string,
203 id: string,
204 params?: LogResponseParams,
205 options?: Core.RequestOptions,
206 ): Core.APIPromise<unknown>;
207 response(gatewayId: string, id: string, options?: Core.RequestOptions): Core.APIPromise<unknown>;
208 response(
209 gatewayId: string,
210 id: string,
211 params: LogResponseParams | Core.RequestOptions = {},
212 options?: Core.RequestOptions,
213 ): Core.APIPromise<unknown> {
214 if (isRequestOptions(params)) {
215 return this.response(gatewayId, id, {}, params);
216 }
217 const { account_id = this._client.accountId } = params;
218 return this._client.get(
219 `/accounts/${account_id}/ai-gateway/gateways/${gatewayId}/logs/${id}/response`,
220 options,
221 );
222 }
223}
224
225export class LogListResponsesV4PagePaginationArray extends V4PagePaginationArray<LogListResponse> {}
226
227export interface LogListResponse {
228 id: string;
229
230 cached: boolean;
231
232 created_at: string;
233
234 duration: number;
235
236 model: string;
237
238 path: string;
239
240 provider: string;
241
242 success: boolean;
243
244 tokens_in: number | null;
245
246 tokens_out: number | null;
247
248 cost?: number;
249
250 custom_cost?: boolean;
251
252 metadata?: string;
253
254 model_type?: string;
255
256 request_content_type?: string;
257
258 request_type?: string;
259
260 response_content_type?: string;
261
262 status_code?: number;
263
264 step?: number;
265}
266
267export interface LogDeleteResponse {
268 success: boolean;
269}
270
271export type LogEditResponse = unknown;
272
273export interface LogGetResponse {
274 id: string;
275
276 cached: boolean;
277
278 created_at: string;
279
280 duration: number;
281
282 model: string;
283
284 path: string;
285
286 provider: string;
287
288 success: boolean;
289
290 tokens_in: number | null;
291
292 tokens_out: number | null;
293
294 cost?: number;
295
296 custom_cost?: boolean;
297
298 metadata?: string;
299
300 model_type?: string;
301
302 request_content_type?: string;
303
304 request_head?: string;
305
306 request_head_complete?: boolean;
307
308 request_size?: number;
309
310 request_type?: string;
311
312 response_content_type?: string;
313
314 response_head?: string;
315
316 response_head_complete?: boolean;
317
318 response_size?: number;
319
320 status_code?: number;
321
322 step?: number;
323}
324
325export type LogRequestResponse = unknown;
326
327export type LogResponseResponse = unknown;
328
329export interface LogListParams extends V4PagePaginationArrayParams {
330 /**
331 * Path param
332 */
333 account_id?: string;
334
335 /**
336 * @deprecated Query param
337 */
338 cached?: boolean;
339
340 /**
341 * @deprecated Query param
342 */
343 direction?: 'asc' | 'desc';
344
345 /**
346 * @deprecated Query param
347 */
348 end_date?: string;
349
350 /**
351 * @deprecated Query param
352 */
353 feedback?: 0 | 1;
354
355 /**
356 * Query param
357 */
358 filters?: Array<LogListParams.Filter>;
359
360 /**
361 * @deprecated Query param
362 */
363 max_cost?: number;
364
365 /**
366 * @deprecated Query param
367 */
368 max_duration?: number;
369
370 /**
371 * @deprecated Query param
372 */
373 max_tokens_in?: number;
374
375 /**
376 * @deprecated Query param
377 */
378 max_tokens_out?: number;
379
380 /**
381 * @deprecated Query param
382 */
383 max_total_tokens?: number;
384
385 /**
386 * Query param
387 */
388 meta_info?: boolean;
389
390 /**
391 * @deprecated Query param
392 */
393 min_cost?: number;
394
395 /**
396 * @deprecated Query param
397 */
398 min_duration?: number;
399
400 /**
401 * @deprecated Query param
402 */
403 min_tokens_in?: number;
404
405 /**
406 * @deprecated Query param
407 */
408 min_tokens_out?: number;
409
410 /**
411 * @deprecated Query param
412 */
413 min_total_tokens?: number;
414
415 /**
416 * @deprecated Query param
417 */
418 model?: string;
419
420 /**
421 * @deprecated Query param
422 */
423 model_type?: string;
424
425 /**
426 * Query param
427 */
428 order_by?: 'created_at' | 'provider' | 'model' | 'model_type' | 'success' | 'cached';
429
430 /**
431 * Query param
432 */
433 order_by_direction?: 'asc' | 'desc';
434
435 /**
436 * @deprecated Query param
437 */
438 provider?: string;
439
440 /**
441 * @deprecated Query param
442 */
443 request_content_type?: string;
444
445 /**
446 * @deprecated Query param
447 */
448 response_content_type?: string;
449
450 /**
451 * Query param
452 */
453 search?: string;
454
455 /**
456 * @deprecated Query param
457 */
458 start_date?: string;
459
460 /**
461 * @deprecated Query param
462 */
463 success?: boolean;
464}
465
466export namespace LogListParams {
467 export interface Filter {
468 key:
469 | 'id'
470 | 'created_at'
471 | 'request_content_type'
472 | 'response_content_type'
473 | 'request_type'
474 | 'success'
475 | 'cached'
476 | 'provider'
477 | 'model'
478 | 'model_type'
479 | 'cost'
480 | 'tokens'
481 | 'tokens_in'
482 | 'tokens_out'
483 | 'duration'
484 | 'feedback'
485 | 'event_id'
486 | 'metadata.key'
487 | 'metadata.value'
488 | 'authentication'
489 | 'wholesale'
490 | 'compatibilityMode'
491 | 'dlp_action';
492
493 operator: 'eq' | 'neq' | 'contains' | 'lt' | 'gt';
494
495 value: Array<string | null | number | boolean>;
496 }
497}
498
499export interface LogDeleteParams {
500 /**
501 * Path param
502 */
503 account_id?: string;
504
505 /**
506 * Query param
507 */
508 filters?: Array<LogDeleteParams.Filter>;
509
510 /**
511 * Query param
512 */
513 limit?: number;
514
515 /**
516 * Query param
517 */
518 order_by?:
519 | 'created_at'
520 | 'provider'
521 | 'model'
522 | 'model_type'
523 | 'success'
524 | 'cached'
525 | 'cost'
526 | 'tokens_in'
527 | 'tokens_out'
528 | 'duration'
529 | 'feedback';
530
531 /**
532 * Query param
533 */
534 order_by_direction?: 'asc' | 'desc';
535}
536
537export namespace LogDeleteParams {
538 export interface Filter {
539 key:
540 | 'id'
541 | 'created_at'
542 | 'request_content_type'
543 | 'response_content_type'
544 | 'request_type'
545 | 'success'
546 | 'cached'
547 | 'provider'
548 | 'model'
549 | 'model_type'
550 | 'cost'
551 | 'tokens'
552 | 'tokens_in'
553 | 'tokens_out'
554 | 'duration'
555 | 'feedback'
556 | 'event_id'
557 | 'metadata.key'
558 | 'metadata.value'
559 | 'authentication'
560 | 'wholesale'
561 | 'compatibilityMode'
562 | 'dlp_action';
563
564 operator: 'eq' | 'neq' | 'contains' | 'lt' | 'gt';
565
566 value: Array<string | null | number | boolean>;
567 }
568}
569
570export interface LogEditParams {
571 /**
572 * Path param
573 */
574 account_id?: string;
575
576 /**
577 * Body param
578 */
579 feedback?: number | null;
580
581 /**
582 * Body param
583 */
584 metadata?: { [key: string]: string | number | boolean } | null;
585
586 /**
587 * Body param
588 */
589 score?: number | null;
590}
591
592export interface LogGetParams {
593 account_id?: string;
594}
595
596export interface LogRequestParams {
597 account_id?: string;
598}
599
600export interface LogResponseParams {
601 account_id?: string;
602}
603
604Logs.LogListResponsesV4PagePaginationArray = LogListResponsesV4PagePaginationArray;
605
606export declare namespace Logs {
607 export {
608 type LogListResponse as LogListResponse,
609 type LogDeleteResponse as LogDeleteResponse,
610 type LogEditResponse as LogEditResponse,
611 type LogGetResponse as LogGetResponse,
612 type LogRequestResponse as LogRequestResponse,
613 type LogResponseResponse as LogResponseResponse,
614 LogListResponsesV4PagePaginationArray as LogListResponsesV4PagePaginationArray,
615 type LogListParams as LogListParams,
616 type LogDeleteParams as LogDeleteParams,
617 type LogEditParams as LogEditParams,
618 type LogGetParams as LogGetParams,
619 type LogRequestParams as LogRequestParams,
620 type LogResponseParams as LogResponseParams,
621 };
622}
623