cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v4.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/ai-gateway/logs.ts

556lines · 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 * Patch Gateway Log
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 * Get Gateway Log Detail
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 * Get Gateway Log Request
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 * Get Gateway Log Response
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 | 'success'
412 | 'cached'
413 | 'provider'
414 | 'model'
415 | 'model_type'
416 | 'cost'
417 | 'tokens'
418 | 'tokens_in'
419 | 'tokens_out'
420 | 'duration'
421 | 'feedback'
422 | 'event_id'
423 | 'request_type'
424 | 'metadata.key'
425 | 'metadata.value'
426 | 'prompts.prompt_id'
427 | 'prompts.version_id';
428
429 operator: 'eq' | 'neq' | 'contains' | 'lt' | 'gt';
430
431 value: Array<string | null | number | boolean>;
432 }
433}
434
435export interface LogDeleteParams {
436 /**
437 * Path param:
438 */
439 account_id: string;
440
441 /**
442 * Query param:
443 */
444 filters?: Array<LogDeleteParams.Filter>;
445
446 /**
447 * Query param:
448 */
449 limit?: number;
450
451 /**
452 * Query param:
453 */
454 order_by?:
455 | 'created_at'
456 | 'provider'
457 | 'model'
458 | 'model_type'
459 | 'success'
460 | 'cached'
461 | 'cost'
462 | 'tokens_in'
463 | 'tokens_out'
464 | 'duration'
465 | 'feedback';
466
467 /**
468 * Query param:
469 */
470 order_by_direction?: 'asc' | 'desc';
471}
472
473export namespace LogDeleteParams {
474 export interface Filter {
475 key:
476 | 'id'
477 | 'created_at'
478 | 'request_content_type'
479 | 'response_content_type'
480 | 'success'
481 | 'cached'
482 | 'provider'
483 | 'model'
484 | 'model_type'
485 | 'cost'
486 | 'tokens'
487 | 'tokens_in'
488 | 'tokens_out'
489 | 'duration'
490 | 'feedback'
491 | 'event_id'
492 | 'request_type'
493 | 'metadata.key'
494 | 'metadata.value'
495 | 'prompts.prompt_id'
496 | 'prompts.version_id';
497
498 operator: 'eq' | 'neq' | 'contains' | 'lt' | 'gt';
499
500 value: Array<string | null | number | boolean>;
501 }
502}
503
504export interface LogEditParams {
505 /**
506 * Path param:
507 */
508 account_id: string;
509
510 /**
511 * Body param:
512 */
513 feedback?: number | null;
514
515 /**
516 * Body param:
517 */
518 metadata?: Record<string, string | number | boolean> | null;
519
520 /**
521 * Body param:
522 */
523 score?: number | null;
524}
525
526export interface LogGetParams {
527 account_id: string;
528}
529
530export interface LogRequestParams {
531 account_id: string;
532}
533
534export interface LogResponseParams {
535 account_id: string;
536}
537
538Logs.LogListResponsesV4PagePaginationArray = LogListResponsesV4PagePaginationArray;
539
540export declare namespace Logs {
541 export {
542 type LogListResponse as LogListResponse,
543 type LogDeleteResponse as LogDeleteResponse,
544 type LogEditResponse as LogEditResponse,
545 type LogGetResponse as LogGetResponse,
546 type LogRequestResponse as LogRequestResponse,
547 type LogResponseResponse as LogResponseResponse,
548 LogListResponsesV4PagePaginationArray as LogListResponsesV4PagePaginationArray,
549 type LogListParams as LogListParams,
550 type LogDeleteParams as LogDeleteParams,
551 type LogEditParams as LogEditParams,
552 type LogGetParams as LogGetParams,
553 type LogRequestParams as LogRequestParams,
554 type LogResponseParams as LogResponseParams,
555 };
556}
557