Skip to content

Namespace

Source: src/Cloudflare/Artifacts/Namespace.ts

A Cloudflare Artifacts namespace — the top-level container for Git-compatible versioned repositories. See the {@link https://blog.cloudflare.com/artifacts-git-for-agents-beta/ | Artifacts launch post} and {@link https://developers.cloudflare.com/artifacts/concepts/namespaces/ | Namespaces docs}.

Namespaces on Cloudflare are implicit: there is no POST /namespaces endpoint. The namespace is conjured the first time a repo is created against it (either via the REST API or the Worker binding). Because of that, the Alchemy “resource” is a thin binding marker — there is nothing to provision at deploy time. Repos themselves are typically created at runtime through the bound Artifacts API.

Unlike the other Worker-only bindings, an Artifacts namespace does not auto-bind when yielded — it always requires an explicit access level via {@link ReadNamespace} / {@link WriteNamespace} / {@link ReadWriteNamespace}.

Default namespace (a unique physical name is generated)

const Repos = Cloudflare.Artifacts.Namespace("Repos");

Override the namespace name (must be lowercase, 3–63 chars)

const Repos = Cloudflare.Artifacts.Namespace("Repos", { namespace: "starter-repos" });

Wiring it into a Worker

export const Worker = Cloudflare.Worker("Worker", {
main: "./src/worker.ts",
bindings: { Repos },
});
export type WorkerEnv = Cloudflare.InferEnv<typeof Worker>;
// { Repos: Artifacts }

Async-style worker

export default {
async fetch(request: Request, env: WorkerEnv) {
const repo = await env.Repos.create("starter-repo");
return Response.json({ remote: repo.remote, token: repo.token });
},
};

Effect-style worker (explicit access level)

const artifacts = yield* Cloudflare.Artifacts.ReadWriteNamespace(Repos);
const repo = yield* artifacts.create("starter-repo", {
setDefaultBranch: "main",
});