ai-persistence/build-cloudflare-artifact-store

ai-persistence/build-cloudflare-artifact-store is a skill for Claude Code, Codex from TanStack/ai. It costs 104 tokens per session (7,594 once invoked), scanned A, original, MIT.

A storage setup for Cloudflare Workers that saves generated media bytes in R2 and their descriptions in D1. Cloudflare Workers are server-side programs, R2 stores files, and D1 is a SQL database.

In plain words
What is it for?
Use it to add media storage to TanStack AI generation persistence and serve saved artifacts through a GET route.
Why use it?
It gives generated images, audio, video, and transcripts a durable place to live instead of keeping them only during a request.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/tanstack/ai/build-cloudflare-artifact-store
Any agent
npx skills add TanStack/ai --skill build-cloudflare-artifact-store
Clone the repo
git clone --depth 1 https://github.com/TanStack/ai

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for ai-persistence/build-cloudflare-artifact-store

README.md
[![agentmods](https://agentmods.dev/badge/skills/tanstack/ai/build-cloudflare-artifact-store.svg)](https://agentmods.dev/skills/tanstack/ai/build-cloudflare-artifact-store)
Your own site
<a href="https://agentmods.dev/skills/tanstack/ai/build-cloudflare-artifact-store"><img src="https://agentmods.dev/badge/skills/tanstack/ai/build-cloudflare-artifact-store.svg" alt="Measured on agentmods" height="20"></a>
Per session 104 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 7,594 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00104 $0.07594
Opus 5 $0.00052 $0.03797
Sonnet 5 $0.00021 $0.01519
Haiku 4.5 $0.00010 $0.00759

Measured 4d ago against content hash 61f02020ee85, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

ai-persistence/build-cloudflare-artifact-store scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

async fetch(request: Request, env: Env) {
packages/ai-persistence/skills/ai-persistence/build-cloudflare-artifact-store/SKILL.md · 716 lines

How it starts

The opening of the file, as written. The whole thing — 716 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Cloudflare Artifact + Blob Store

withGenerationPersistence(persistence) needs only stores.generationRuns to track a generation's lifecycle. Add stores.artifacts (metadata) and stores.blobs (the bytes) — both, or neither — and the middleware also persists the generated media: image/audio/TTS/video/transcription bytes land at blob key artifacts/<runId>/<artifactId>, with an ArtifactRecord row describing each.

The deliverable is one file in the Worker — e.g. src/lib/generation-persistence.ts — exporting a factory that builds an AIPersistence from the request's R2 + D1 bindings, plus a GET route that serves artifact bytes with retrieveArtifact / retrieveBlob.

Read the sibling ai-persistence/build-cloudflare-adapter skill for the per-request-binding rule, wrangler config shape, D1 migration workflow, and the chat (generation-run/message) side. This skill covers only the two byte-storage stores and how to compose them.

The two contracts

Both come from @tanstack/ai-persistence. defineBlobStore / defineArtifactStore type an object literal inline (autocomplete + contract checking, no separate annotation).

// BlobStore — the byte layer. R2 backs it.
interface BlobStore {
  put: (
    key: string,
    body: BlobBody,
    options?: BlobPutOptions,
  ) => Promise<BlobRecord>
  // metadata + byte accessors; `options.range` reads one slice (for `206`s)
  get: (key: string, options?: BlobGetOptions) => Promise<BlobObject | null>
  head: (key: string) => Promise<BlobRecord | null> // metadata only
  delete: (key: string) => Promise<void> // no-op if absent
  list: (options?: BlobListOptions) => Promise<BlobListPage>
}

// ArtifactStore — the metadata layer. D1 backs it.
interface ArtifactStore {
  save: (record: ArtifactRecord) => Promise<void> // insert or overwrite
  get: (artifactId: string) => Promise<ArtifactRecord | null>
  list: (runId: string) => Promise<Array<ArtifactRecord>> // [] when none
  listForThread: (threadId: string) => Promise<Array<ArtifactRecord>>
  delete: (artifactId: string) => Promise<void>
  deleteForRun: (runId: string) => Promise<void>
}

Read the full file on GitHub · 716 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 716 lines · 104 tokens per session scan A 61f02020ee85

Subscribe to this mod's changes

ai-persistence/build-cloudflare-artifact-store is a skill published in the GitHub repository TanStack/ai (3,060 stars, last pushed today), licensed MIT. It adds 104 tokens to every session and 7,594 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.