Run it in the site repository
The key comes from the dashboard under Settings, then API Keys, with the content:manage scope.
BETTERCMS_API_KEY=bcms_xxx npx @bettercms-ai/codegen \
--out src/bettercms.generated.ts Codegen turns your BetterCMS content models into TypeScript. Your models are defined once, either in the dashboard schema builder or by an assistant through the MCP tools, and both write the same underlying field schema, so the generated types cannot drift from what your editors and agents actually create. This is the deterministic floor under the AI integration: if an agent mis-wires something, the committed types still say what the shape is.
One command, then a decision about where it runs.
Field types map predictably: text, date and datetime become string; richtext becomes RichText; image becomes BetterCMSImage; select becomes a union; a group becomes a nested object and a repeater becomes an array of one.
The key comes from the dashboard under Settings, then API Keys, with the content:manage scope.
BETTERCMS_API_KEY=bcms_xxx npx @bettercms-ai/codegen \
--out src/bettercms.generated.ts The output is source. Committing it means a fresh clone type checks without a network call, and a schema change shows up as a reviewable diff rather than as a surprise at build time.
A CI step does this, and the BetterCMS GitHub Action does it on every build. Either way the committed types track the models.
The generated BetterCMSSchema registry is what lets the Next.js adapter type getEntry by model slug.
Pass a second output path and codegen also emits a schema derived binding helper. Spread a binding onto the element that renders a field, and the resulting data attribute is what makes the running site editable in place.
npx @bettercms-ai/codegen \
--out src/bettercms.generated.ts \
--bindings-out src/bettercms.bindings.generated.ts A reference field generates a string and a multi reference generates an array of strings. Hydrating them is a read time concern, which the Next.js adapter handles with its depth option.
There is no watch mode. Codegen runs when you run it, or when CI runs it. A schema change made while the dev server is up does not update the types on its own.
The output describes field shapes. It cannot tell you that a required field is empty on forty entries, because it never looks at an entry.
Reading the schema needs content:manage, which is more privilege than a delivery key. Keep it in CI secrets rather than in a developer shell profile.
Run npx @bettercms-ai/codegen with a content:manage key and an output path. It reads the content models and writes an interface per model plus a BetterCMSSchema registry that maps model slugs to their field types. Commit the output and rerun after a schema change.
Yes, once you rerun codegen. The schema builder and the MCP tools write the same underlying field schema, so there is one source and the generated types describe it either way. That is the point of running codegen in CI: it is the deterministic floor under the agent.
Live Preview. The bindings file is a small schema derived helper you spread onto the element that renders each field, which stamps a data attribute the editor reads to make the running site editable in place. It is off by default and turns on with the bindings output flag.
REST reads with a typed client: one page, a paginated list, or an iterator that follows pagination for you.
First party adapter: a bettercms() integration, typed loaders, draft preview, and components that render page blocks.
First party App Router adapter: typed cache aware reads, tag revalidation, draft mode, and a generated llms.txt route.
See BetterCMS running on your pages, not on a sample site.