# Logs ## List Gateway Logs `ai_gateway.logs.list(strgateway_id, LogListParams**kwargs) -> SyncV4PagePaginationArray[LogListResponse]` **get** `/accounts/{account_id}/ai-gateway/gateways/{gateway_id}/logs` List Gateway Logs ### Parameters - `account_id: str` - `gateway_id: str` gateway id - `cached: Optional[bool]` - `direction: Optional[Literal["asc", "desc"]]` - `"asc"` - `"desc"` - `end_date: Optional[Union[str, datetime]]` - `feedback: Optional[Literal[0, 1]]` - `0` - `1` - `filters: Optional[Iterable[Filter]]` - `key: Literal["id", "created_at", "request_content_type", 20 more]` - `"id"` - `"created_at"` - `"request_content_type"` - `"response_content_type"` - `"request_type"` - `"success"` - `"cached"` - `"provider"` - `"model"` - `"model_type"` - `"cost"` - `"tokens"` - `"tokens_in"` - `"tokens_out"` - `"duration"` - `"feedback"` - `"event_id"` - `"metadata.key"` - `"metadata.value"` - `"authentication"` - `"wholesale"` - `"compatibilityMode"` - `"dlp_action"` - `operator: Literal["eq", "neq", "contains", 2 more]` - `"eq"` - `"neq"` - `"contains"` - `"lt"` - `"gt"` - `value: SequenceNotStr[Union[Optional[str], float, bool]]` - `Optional[str]` - `float` - `bool` - `max_cost: Optional[float]` - `max_duration: Optional[float]` - `max_tokens_in: Optional[float]` - `max_tokens_out: Optional[float]` - `max_total_tokens: Optional[float]` - `meta_info: Optional[bool]` - `min_cost: Optional[float]` - `min_duration: Optional[float]` - `min_tokens_in: Optional[float]` - `min_tokens_out: Optional[float]` - `min_total_tokens: Optional[float]` - `model: Optional[str]` - `model_type: Optional[str]` - `order_by: Optional[Literal["created_at", "provider", "model", 3 more]]` - `"created_at"` - `"provider"` - `"model"` - `"model_type"` - `"success"` - `"cached"` - `order_by_direction: Optional[Literal["asc", "desc"]]` - `"asc"` - `"desc"` - `page: Optional[int]` - `per_page: Optional[int]` - `provider: Optional[str]` - `request_content_type: Optional[str]` - `response_content_type: Optional[str]` - `search: Optional[str]` - `start_date: Optional[Union[str, datetime]]` - `success: Optional[bool]` ### Returns - `class LogListResponse: …` - `id: str` - `cached: bool` - `created_at: datetime` - `duration: int` - `model: str` - `path: str` - `provider: str` - `success: bool` - `tokens_in: Optional[int]` - `tokens_out: Optional[int]` - `cost: Optional[float]` - `custom_cost: Optional[bool]` - `metadata: Optional[str]` - `model_type: Optional[str]` - `request_content_type: Optional[str]` - `request_type: Optional[str]` - `response_content_type: Optional[str]` - `status_code: Optional[int]` - `step: Optional[int]` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) page = client.ai_gateway.logs.list( gateway_id="my-gateway", account_id="0d37909e38d3e99c29fa2cd343ac421a", ) page = page.result[0] print(page.id) ``` #### Response ```json { "result": [ { "id": "id", "cached": true, "created_at": "2019-12-27T18:11:19.117Z", "duration": 0, "model": "model", "path": "path", "provider": "provider", "success": true, "tokens_in": 0, "tokens_out": 0, "cost": 0, "custom_cost": true, "metadata": "metadata", "model_type": "model_type", "request_content_type": "request_content_type", "request_type": "request_type", "response_content_type": "response_content_type", "status_code": 0, "step": 0 } ], "result_info": { "count": 0, "max_cost": 0, "max_duration": 0, "max_tokens_in": 0, "max_tokens_out": 0, "max_total_tokens": 0, "min_cost": 0, "min_duration": 0, "min_tokens_in": 0, "min_tokens_out": 0, "min_total_tokens": 0, "page": 0, "per_page": 0, "total_count": 0 }, "success": true } ``` ## Get Gateway Log Detail `ai_gateway.logs.get(strid, LogGetParams**kwargs) -> LogGetResponse` **get** `/accounts/{account_id}/ai-gateway/gateways/{gateway_id}/logs/{id}` Retrieves detailed information for a specific AI Gateway log entry. ### Parameters - `account_id: str` - `gateway_id: str` gateway id - `id: str` ### Returns - `class LogGetResponse: …` - `id: str` - `cached: bool` - `created_at: datetime` - `duration: int` - `model: str` - `path: str` - `provider: str` - `success: bool` - `tokens_in: Optional[int]` - `tokens_out: Optional[int]` - `cost: Optional[float]` - `custom_cost: Optional[bool]` - `metadata: Optional[str]` - `model_type: Optional[str]` - `request_content_type: Optional[str]` - `request_head: Optional[str]` - `request_head_complete: Optional[bool]` - `request_size: Optional[int]` - `request_type: Optional[str]` - `response_content_type: Optional[str]` - `response_head: Optional[str]` - `response_head_complete: Optional[bool]` - `response_size: Optional[int]` - `status_code: Optional[int]` - `step: Optional[int]` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) log = client.ai_gateway.logs.get( id="id", account_id="0d37909e38d3e99c29fa2cd343ac421a", gateway_id="my-gateway", ) print(log.id) ``` #### Response ```json { "result": { "id": "id", "cached": true, "created_at": "2019-12-27T18:11:19.117Z", "duration": 0, "model": "model", "path": "path", "provider": "provider", "success": true, "tokens_in": 0, "tokens_out": 0, "cost": 0, "custom_cost": true, "metadata": "metadata", "model_type": "model_type", "request_content_type": "request_content_type", "request_head": "request_head", "request_head_complete": true, "request_size": 0, "request_type": "request_type", "response_content_type": "response_content_type", "response_head": "response_head", "response_head_complete": true, "response_size": 0, "status_code": 0, "step": 0 }, "success": true } ``` ## Patch Gateway Log `ai_gateway.logs.edit(strid, LogEditParams**kwargs) -> object` **patch** `/accounts/{account_id}/ai-gateway/gateways/{gateway_id}/logs/{id}` Updates metadata for an AI Gateway log entry. ### Parameters - `account_id: str` - `gateway_id: str` gateway id - `id: str` - `feedback: Optional[float]` - `metadata: Optional[Dict[str, Union[str, float, bool]]]` - `str` - `float` - `bool` - `score: Optional[float]` ### Returns - `object` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) response = client.ai_gateway.logs.edit( id="id", account_id="0d37909e38d3e99c29fa2cd343ac421a", gateway_id="my-gateway", ) print(response) ``` #### Response ```json { "result": {}, "success": true } ``` ## Delete Gateway Logs `ai_gateway.logs.delete(strgateway_id, LogDeleteParams**kwargs) -> LogDeleteResponse` **delete** `/accounts/{account_id}/ai-gateway/gateways/{gateway_id}/logs` Delete Gateway Logs ### Parameters - `account_id: str` - `gateway_id: str` gateway id - `filters: Optional[Iterable[Filter]]` - `key: Literal["id", "created_at", "request_content_type", 20 more]` - `"id"` - `"created_at"` - `"request_content_type"` - `"response_content_type"` - `"request_type"` - `"success"` - `"cached"` - `"provider"` - `"model"` - `"model_type"` - `"cost"` - `"tokens"` - `"tokens_in"` - `"tokens_out"` - `"duration"` - `"feedback"` - `"event_id"` - `"metadata.key"` - `"metadata.value"` - `"authentication"` - `"wholesale"` - `"compatibilityMode"` - `"dlp_action"` - `operator: Literal["eq", "neq", "contains", 2 more]` - `"eq"` - `"neq"` - `"contains"` - `"lt"` - `"gt"` - `value: SequenceNotStr[Union[Optional[str], float, bool]]` - `Optional[str]` - `float` - `bool` - `limit: Optional[int]` - `order_by: Optional[Literal["created_at", "provider", "model", 8 more]]` - `"created_at"` - `"provider"` - `"model"` - `"model_type"` - `"success"` - `"cached"` - `"cost"` - `"tokens_in"` - `"tokens_out"` - `"duration"` - `"feedback"` - `order_by_direction: Optional[Literal["asc", "desc"]]` - `"asc"` - `"desc"` ### Returns - `class LogDeleteResponse: …` - `success: bool` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) log = client.ai_gateway.logs.delete( gateway_id="my-gateway", account_id="0d37909e38d3e99c29fa2cd343ac421a", ) print(log.success) ``` #### Response ```json { "success": true } ``` ## Get Gateway Log Request `ai_gateway.logs.request(strid, LogRequestParams**kwargs) -> object` **get** `/accounts/{account_id}/ai-gateway/gateways/{gateway_id}/logs/{id}/request` Retrieves the original request payload for an AI Gateway log entry. ### Parameters - `account_id: str` - `gateway_id: str` gateway id - `id: str` ### Returns - `object` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) response = client.ai_gateway.logs.request( id="id", account_id="0d37909e38d3e99c29fa2cd343ac421a", gateway_id="my-gateway", ) print(response) ``` #### Response ```json {} ``` ## Get Gateway Log Response `ai_gateway.logs.response(strid, LogResponseParams**kwargs) -> object` **get** `/accounts/{account_id}/ai-gateway/gateways/{gateway_id}/logs/{id}/response` Retrieves the response payload for an AI Gateway log entry. ### Parameters - `account_id: str` - `gateway_id: str` gateway id - `id: str` ### Returns - `object` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) response = client.ai_gateway.logs.response( id="id", account_id="0d37909e38d3e99c29fa2cd343ac421a", gateway_id="my-gateway", ) print(response) ``` #### Response ```json {} ``` ## Domain Types ### Log List Response - `class LogListResponse: …` - `id: str` - `cached: bool` - `created_at: datetime` - `duration: int` - `model: str` - `path: str` - `provider: str` - `success: bool` - `tokens_in: Optional[int]` - `tokens_out: Optional[int]` - `cost: Optional[float]` - `custom_cost: Optional[bool]` - `metadata: Optional[str]` - `model_type: Optional[str]` - `request_content_type: Optional[str]` - `request_type: Optional[str]` - `response_content_type: Optional[str]` - `status_code: Optional[int]` - `step: Optional[int]` ### Log Get Response - `class LogGetResponse: …` - `id: str` - `cached: bool` - `created_at: datetime` - `duration: int` - `model: str` - `path: str` - `provider: str` - `success: bool` - `tokens_in: Optional[int]` - `tokens_out: Optional[int]` - `cost: Optional[float]` - `custom_cost: Optional[bool]` - `metadata: Optional[str]` - `model_type: Optional[str]` - `request_content_type: Optional[str]` - `request_head: Optional[str]` - `request_head_complete: Optional[bool]` - `request_size: Optional[int]` - `request_type: Optional[str]` - `response_content_type: Optional[str]` - `response_head: Optional[str]` - `response_head_complete: Optional[bool]` - `response_size: Optional[int]` - `status_code: Optional[int]` - `step: Optional[int]` ### Log Delete Response - `class LogDeleteResponse: …` - `success: bool`