cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v6.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/ai-gateway/logs.ts

560lines · modecode

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