Artifacts
Step results, state and call inputs live in the journal, and the journal is replayed on every turn. Large values there make every turn slower and more expensive. Artifacts keep the bytes in object storage and put only a small reference in the journal.
const ref = await ctx.run("render", async () => ctx.artifact.put(await renderChart(data), { contentType: "image/png" }),);// ref = { sha256: "…", size: 48213, contentType: "image/png" }Return the reference from ctx.run, not the bytes. The journal then holds a few dozen bytes, and
the step is not re-run on replay.
interface ArtifactRef { readonly sha256: string; // hex SHA-256 of the content readonly size: number; readonly contentType: string;}
ctx.artifact.put(bytes: Uint8Array | string, opts?: { contentType?: string }): Promise<ArtifactRef>;ctx.artifact.get(ref: ArtifactRef | string): Promise<Uint8Array>;putaccepts bytes or a string (encoded as UTF-8).contentTypedefaults toapplication/octet-stream.- The reference is computed locally from the content; cairnflow stores the bytes before it processes the invocation’s next command.
- Content-addressed: putting the same bytes twice gives the same
sha256. getaccepts a reference or a baresha256string.
Limits
Section titled “Limits”- One artifact can be at most 16 MiB minus 1 KiB. The SDK exports this as
ARTIFACT_MAX_BYTES;putthrows aRangeErrorabove it. - Your environment may also cap the total artifact bytes it keeps; on Cairnflow Cloud, see Beta limits.
Reading an artifact back
Section titled “Reading an artifact back”ctx.artifact.get(ref) first looks in the SDK process’s own memory (a 64 MiB cache of recent
artifacts). On a different process — after a restart, or on another replica — it fetches the
artifact from cairnflow, which you must configure once at startup:
import { configureArtifacts } from "@cairnflow/sdk";
configureArtifacts({ baseUrl: process.env.CAIRN_URL!, headers: { authorization: `Bearer ${process.env.CAIRN_KEY}` },});Use a key that can invoke handlers. Without this, get throws when the artifact is not in memory.
Reading artifacts over HTTP
Section titled “Reading artifacts over HTTP”With a key that can invoke handlers:
# List the artifacts of an invocation.curl "$CAIRN_URL/invocations/$ID/artifacts" -H "authorization: Bearer $CAIRN_KEY"# -> {"artifacts": [{"sha256": "...", "size": 48213, "contentType": "image/png"}]}
# Download one.curl "$CAIRN_URL/invocations/$ID/artifacts/$SHA256" \ -H "authorization: Bearer $CAIRN_KEY" -o chart.pngThe response carries the content type given to put and is served as inert content: HTML, SVG,
XML and PDF artifacts are always sent as downloads, never rendered in place.
Lifetime
Section titled “Lifetime”Artifacts belong to the invocation that created them. When the invocation is purged — explicitly or
when its retention period ends — its artifacts go with it, and the HTTP routes answer 404.
When to use them
Section titled “When to use them”- Files and images produced or consumed by a step.
- Documents and model outputs that later steps of the same invocation, or a UI, read back.
Not for values carried from one invocation to the next, such as a chat history kept in state:
ctx.artifact.get cannot read another invocation’s artifacts, and artifacts are purged with the
invocation that wrote them. Keep such values in state; large ones are stored as segments
automatically (see Virtual objects and state).
On serverless platforms (fetchHandler), where the journal travels on every request, this matters
even more — see Serverless.