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