cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
src/resources/ai-gateway/logs.ts
562lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | import { APIResource } from '../../resource'; |
| 4 | import * as Core from '../../core'; |
| 5 | import { V4PagePaginationArray, type V4PagePaginationArrayParams } from '../../pagination'; |
| 6 | |
| 7 | export 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 | |
| 163 | export class LogListResponsesV4PagePaginationArray extends V4PagePaginationArray<LogListResponse> {} |
| 164 | |
| 165 | export 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 | |
| 205 | export interface LogDeleteResponse { |
| 206 | success: boolean; |
| 207 | } |
| 208 | |
| 209 | export type LogEditResponse = unknown; |
| 210 | |
| 211 | export 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 | |
| 263 | export type LogRequestResponse = unknown; |
| 264 | |
| 265 | export type LogResponseResponse = unknown; |
| 266 | |
| 267 | export 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 | |
| 404 | export 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 | | 'user_agent'; |
| 431 | |
| 432 | operator: 'eq' | 'neq' | 'contains' | 'lt' | 'gt'; |
| 433 | |
| 434 | value: Array<string | null | number | boolean>; |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | export interface LogDeleteParams { |
| 439 | /** |
| 440 | * Path param |
| 441 | */ |
| 442 | account_id: string; |
| 443 | |
| 444 | /** |
| 445 | * Query param |
| 446 | */ |
| 447 | filters?: Array<LogDeleteParams.Filter>; |
| 448 | |
| 449 | /** |
| 450 | * Query param |
| 451 | */ |
| 452 | limit?: number; |
| 453 | |
| 454 | /** |
| 455 | * Query param |
| 456 | */ |
| 457 | order_by?: |
| 458 | | 'created_at' |
| 459 | | 'provider' |
| 460 | | 'model' |
| 461 | | 'model_type' |
| 462 | | 'success' |
| 463 | | 'cached' |
| 464 | | 'cost' |
| 465 | | 'tokens_in' |
| 466 | | 'tokens_out' |
| 467 | | 'duration' |
| 468 | | 'feedback'; |
| 469 | |
| 470 | /** |
| 471 | * Query param |
| 472 | */ |
| 473 | order_by_direction?: 'asc' | 'desc'; |
| 474 | } |
| 475 | |
| 476 | export namespace LogDeleteParams { |
| 477 | export interface Filter { |
| 478 | key: |
| 479 | | 'id' |
| 480 | | 'created_at' |
| 481 | | 'request_content_type' |
| 482 | | 'response_content_type' |
| 483 | | 'request_type' |
| 484 | | 'success' |
| 485 | | 'cached' |
| 486 | | 'provider' |
| 487 | | 'model' |
| 488 | | 'model_type' |
| 489 | | 'cost' |
| 490 | | 'tokens' |
| 491 | | 'tokens_in' |
| 492 | | 'tokens_out' |
| 493 | | 'duration' |
| 494 | | 'feedback' |
| 495 | | 'event_id' |
| 496 | | 'metadata.key' |
| 497 | | 'metadata.value' |
| 498 | | 'authentication' |
| 499 | | 'wholesale' |
| 500 | | 'compatibilityMode' |
| 501 | | 'dlp_action' |
| 502 | | 'user_agent'; |
| 503 | |
| 504 | operator: 'eq' | 'neq' | 'contains' | 'lt' | 'gt'; |
| 505 | |
| 506 | value: Array<string | null | number | boolean>; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | export interface LogEditParams { |
| 511 | /** |
| 512 | * Path param |
| 513 | */ |
| 514 | account_id: string; |
| 515 | |
| 516 | /** |
| 517 | * Body param |
| 518 | */ |
| 519 | feedback?: number | null; |
| 520 | |
| 521 | /** |
| 522 | * Body param |
| 523 | */ |
| 524 | metadata?: { [key: string]: string | number | boolean } | null; |
| 525 | |
| 526 | /** |
| 527 | * Body param |
| 528 | */ |
| 529 | score?: number | null; |
| 530 | } |
| 531 | |
| 532 | export interface LogGetParams { |
| 533 | account_id: string; |
| 534 | } |
| 535 | |
| 536 | export interface LogRequestParams { |
| 537 | account_id: string; |
| 538 | } |
| 539 | |
| 540 | export interface LogResponseParams { |
| 541 | account_id: string; |
| 542 | } |
| 543 | |
| 544 | Logs.LogListResponsesV4PagePaginationArray = LogListResponsesV4PagePaginationArray; |
| 545 | |
| 546 | export declare namespace Logs { |
| 547 | export { |
| 548 | type LogListResponse as LogListResponse, |
| 549 | type LogDeleteResponse as LogDeleteResponse, |
| 550 | type LogEditResponse as LogEditResponse, |
| 551 | type LogGetResponse as LogGetResponse, |
| 552 | type LogRequestResponse as LogRequestResponse, |
| 553 | type LogResponseResponse as LogResponseResponse, |
| 554 | LogListResponsesV4PagePaginationArray as LogListResponsesV4PagePaginationArray, |
| 555 | type LogListParams as LogListParams, |
| 556 | type LogDeleteParams as LogDeleteParams, |
| 557 | type LogEditParams as LogEditParams, |
| 558 | type LogGetParams as LogGetParams, |
| 559 | type LogRequestParams as LogRequestParams, |
| 560 | type LogResponseParams as LogResponseParams, |
| 561 | }; |
| 562 | } |
| 563 | |