Enabling log retention

Last updated Apr 23, 2026 By default, your HTTP request logs are not retained. When using the Logpull API for the first time, you will need to enable retention. You can also turn off retention at any time. Note that after retention is turned off, previously saved logs will be available until the retention period expires (refer to Data retention period).

Endpoints

There are two endpoints for managing log retention:

  • GET /logs/control/retention/flag - returns the current status of retention
  • POST /logs/control/retention/flag - turns retention on or off

Note

In the Linux examples below we use the optional jq tool to help parse the response data.

To make a POST call, you must have zone-scoped edit permissions, such as Super Administrator, Administrator, or Log Share. Refer to Make API calls for more information.

Example API requests using cURL

Check log retention status

<details>

<summary>

Required API token permissions

</summary>

At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:

  • <code>Logs Write</code>
  • <code>Logs Read</code>

</details>

Get log retention flagbash

curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/logs/control/retention/flag" \
    --request GET \
    --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
curl.exe "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag" ^
--header "Authorization: Bearer <API_TOKEN>"
$uri = "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag"
$headers = @{"Authorization" = "Bearer <API_TOKEN>"}
Invoke-RestMethod -Uri $uri -Method Get -Headers $headers

If the zone has log retention enabled you get the value true, whereas a value of false is returned when it is disabled.

Turn on log retention

<details>

<summary>

Required API token permissions

</summary>

At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:

  • <code>Logs Write</code>

</details>

Update log retention flagbash

curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/logs/control/retention/flag" \
    --request POST \
    --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
    --json '{
        "flag": true
    }'
curl.exe "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag" ^
--request POST ^
--header "Authorization: Bearer <API_TOKEN>" ^
--header "Content-Type: application/json" ^
--data "{""flag"": true}"
$uri = "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag"
$headers = @{"Authorization" = "Bearer <API_TOKEN>"}
$bodyFlag = @{flag = $true} | ConvertTo-Json
Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $bodyFlag -ContentType "application/json"

Enabled response

{
    "flag": true
}

Turn off log retention

<details>

<summary>

Required API token permissions

</summary>

At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:

  • <code>Logs Write</code>

</details>

Update log retention flagbash

curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/logs/control/retention/flag" \
    --request POST \
    --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
    --json '{
        "flag": false
    }'
curl.exe "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag" ^
--header "Authorization: Bearer <API_TOKEN>" ^
--header "Content-Type: application/json" ^
--data "{""flag"": false}"
$uri = "https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/control/retention/flag"
$headers = @{"Authorization" = "Bearer <API_TOKEN>"}
$bodyFlag = @{flag = $false} | ConvertTo-Json
Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $bodyFlag -ContentType "application/json"

Disabled response

{
    "flag": false
}

Audit

Turning log retention on or off is recorded in Cloudflare Audit Logs.

Was this helpful?

YesNo

On this page

Enabling log retention - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/logs/logpull/enabling-log-retention/#page","headline":"Enabling log retention","description":"Turn log retention on or off for Logpull.","url":"https://developers.cloudflare.com/logs/logpull/enabling-log-retention/","inLanguage":"en","image":"https://developers.cloudflare.com/logs/logpull/enabling-log-retention/og.png?v=61825fc82e518220","dateModified":"2026-04-23","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}


description: Use Logpull API endpoints to request log data. title: Requesting logs image: https://developers.cloudflare.com/logs/logpull/requesting-logs/og.png?v=53343d71ffbc560f


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/logs/llms.txt
Use this file to discover all available pages before exploring further.