ListFiles icon
OutputValues icon
Switch icon
Log icon
Loop icon
If icon
DeleteFile icon
SlackIncomingWebhook icon
Schedule icon

Anthropic Files API Stale File Retention Compliance Gate

Audit Anthropic Files API uploads for retention compliance, alert Slack or auto-delete stale files, and log the result for AI platform teams.

Categories
AI

Every file uploaded to the Anthropic Files API for use as Claude prompt context sits there indefinitely unless something explicitly deletes it. A team that uploads PDFs, transcripts, or datasets for one-off analysis accumulates files nobody is tracking, some of which may hold data that should not be retained past a policy window. This blueprint lists what is actually stored right now, measures each file's real age against the retention window you set, and only deletes the stale ones once you have explicitly said this flow is allowed to.

This blueprint was created by Mohit Jeswani.

How it works

  1. list_files (io.kestra.plugin.anthropic.ListFiles) reads up to 100 files from the Anthropic Files API. Read-only; nothing is deleted here. allowFailure: true covers an API or auth error without failing the flow outright.
  2. evaluate (io.kestra.plugin.core.output.OutputValues) compares each file's real createdAt timestamp against retention_days with a jq filter, and classifies the result as WITHIN_RETENTION, OVER_RETENTION_AUTO_DELETE, OVER_RETENTION_NEEDS_HUMAN, or PROBE_FAILED, folding confirm_delete into the over-retention classification itself.
  3. route (io.kestra.plugin.core.flow.Switch):
    • WITHIN_RETENTION: logs that nothing is past the retention window.
    • OVER_RETENTION_AUTO_DELETE: loops over every listed file, deletes only the ones past retention_days with io.kestra.plugin.anthropic.DeleteFile (the safe remediation, since removing an already-expired file is the already-correct outcome), then posts a Slack notice.
    • OVER_RETENTION_NEEDS_HUMAN / PROBE_FAILED: posts a Slack alert instead of deleting.
  4. summary logs the count and severity, closing the governance cycle.
  5. errors alerts Slack if the flow itself fails, for example an expired API key.

What you get

  • A retention check against each file's real upload timestamp, not a guess based on when someone remembers uploading it.
  • A deletion that only ever removes a file already past the policy window, and only once you have explicitly set confirm_delete to allow it.
  • A Slack alert naming the exact stale file IDs and filenames, so a human can review or act without listing files manually first.

Who it's for

  • AI platform and data governance teams who use the Anthropic Files API for document context and need uploads cleaned up on a real retention policy, not left indefinitely.
  • Teams evaluating the Anthropic plugin who want a worked example of ListFiles and DeleteFile used together as a compliance gate, distinct from this repo's existing Anthropic blueprints, which call ChatCompletion and MessageBatch rather than managing the Files API's own lifecycle.

Why orchestrate this with Kestra

The Anthropic Files API can list and delete files on request, but it has no retention policy, no scheduler, and no Slack integration of its own. Kestra keeps retention_days and confirm_delete as flow inputs, turns a raw file listing into a retention decision, and keeps a full execution history of every file this flow has seen and what happened to it.

Prerequisites

  • An Anthropic API key with access to the Files API (beta).
  • At least one file uploaded to the Files API old enough to confirm the stale-file path, via curl or the Anthropic SDK's files.upload endpoint.
  • A Slack incoming webhook URL.

The Anthropic API is a hosted service with no official standalone Docker image, so list_files cannot be exercised against a local container; validate against a real Anthropic account on a low-traffic API key first.

Secrets

  • ANTHROPIC_API_KEY: the Anthropic API key used by list_files and delete_file. In Kestra OSS, provide it as the base64-encoded environment variable SECRET_ANTHROPIC_API_KEY.
  • SLACK_WEBHOOK_URL: used by all three Slack alert cases and the errors block. In Kestra OSS, provide it as the base64-encoded environment variable SECRET_SLACK_WEBHOOK_URL.

Inputs

Input Default Purpose
retention_days 30 Age in days past which a file is classified stale
confirm_delete false Authorizes this flow to delete stale files itself

Outputs

  • {{ outputs.list_files.files }}: every listed file (fileId, filename, mimeType, size, createdAt, downloadable, scopeId), as the Files API reports them.
  • {{ outputs.evaluate.values.stale_count }} / .stale_summary: how many files are stale and a semicolon-joined id (filename, created at) summary of each.
  • {{ outputs.evaluate.values.severity }}: WITHIN_RETENTION, OVER_RETENTION_AUTO_DELETE, OVER_RETENTION_NEEDS_HUMAN, or PROBE_FAILED.

Pitfalls

  • ListFiles returns at most limit files (max 1000) per run with no built-in pagination loop in this blueprint; a Files API store larger than one page needs afterId chained across repeated runs to audit in full.
  • createdAt is an RFC 3339 timestamp parsed with jq's fromdateiso8601, which expects whole-second precision; verified against the actual Java Instant.toString() output in AbstractAnthropicFiles.toMetadataInfo(), not assumed from the Javadoc, which does not document the exact timestamp format.
  • confirm_delete applies to every stale file found on a run, not one specific file; a scheduled run with it set to true deletes every file past retention_days each time it fires, so treat it as "this retention policy is fully enforced," not a one-time approval.

Quick start

  1. Add the ANTHROPIC_API_KEY and SLACK_WEBHOOK_URL secrets.
  2. Upload a test file to the Files API and, if possible, backdate or wait for it to age past a short retention_days value for testing.
  3. Run the flow manually with confirm_delete: false and confirm alert_over_retention fires once the file is stale.
  4. Run again with confirm_delete: true and confirm delete_file removes it and alert_auto_deleted fires.
  5. Run a third time and confirm log_within_retention fires now that the file is gone.
  6. Enable the weekly trigger once retention_days reflects your real policy.

How to extend

  • Chain afterId across repeated executions (persisted via a KV entry) to page through a Files API store larger than one limit-sized call.
  • Filter by scopeId before classifying, so a session-scoped batch of files can be retained on a shorter policy than general-purpose uploads.
  • Add a size-based budget alongside the age-based one, alerting when total stored bytes across all listed files crosses a threshold, not just when an individual file ages out.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.