Get started
Add @genko-me/astro to an Astro project, render a paginated list and a detail page with share buttons, and preview drafts.
This guide adds @genko-me/sdk and @genko-me/astro to an Astro project to show a list and a single entry. @genko-me/astro provides Astro components: Field, RichText, Pagination, ShareButtons, and PreviewNotice. You do not need React, Vue, or Svelte, and you do not register an integration. Both pages are built ahead of time with the default output: 'static'.
Steps 1–3 of the quickstart cover creating a workspace and blog API.
Prerequisites
- A genko.me account and workspace. Creating an API and issuing an API key require the owner role.
- An API with at least one entry that is saved and published. The delivery API cannot return a draft.
- Astro 7.4 or later in the 7.x line. The peer dependency of
@genko-me/astroisastro@^7.4.0. - Node.js 22.23.4 or later. This is the requirement of Astro 7.4.2, the latest version at the time of writing (7.4.0 and 7.4.1 require 22.22.0 or later). Astro supports even-numbered releases only, so odd versions such as
v23are not supported. Follow theenginesfield of the Astro version you use. - An existing Astro project, such as one created with
npm create astro@latest.
Replace your-workspace below with your workspace ID, and blog with your endpoint.
Install
npm install @genko-me/sdk @genko-me/astroThe @genko-me/astro components render static HTML. Only the share buttons' copy and share-sheet actions use a small script, so you do not need an integration such as @astrojs/react or a client:load directive.
Generate the connection and pages with the CLI
You can have the CLI generate the connection settings instead of writing them by hand. Run it at the root of the Astro project.
npx @genko-me/cli init --pagesWithout --pages, the CLI generates only these files:
src/lib/schema.ts: the API definitionssrc/lib/client.ts: a client that uses the workspace and the API key (getSecretfromastro:env/server)genko.config.json, andGENKO_API_KEYin.env.local
When package.json lists astro, the CLI also adds @genko-me/sdk, @genko-me/astro, and @genko-me/cli (as a dev dependency). With --pages, it also generates a list page at src/pages/genko/[...page].astro and a detail page at src/pages/genko/entries/[id].astro for the first list-type API you selected. It never overwrites existing pages, even with --force. --pages requires an Astro project and a list-type API, and works only with init.
To run it without prompts, set GENKO_API_KEY in the environment and pass --workspace <id> --yes. --apis blog chooses which APIs to sync.
The rest of this page builds the same files by hand.
Set up the API key and client
Issue an API key in the dashboard under Settings & plan → API keys (/w/your-workspace/settings/api-keys). For safety, choose "Selected APIs only" and allow just blog. The value shown right after creation cannot be shown again.
GENKO_API_KEY=the-key-you-issuedAstro frontmatter and pages run on the server (at build time or, later, on request), so do not add the PUBLIC_ prefix. PUBLIC_ is only for values that should also be embedded in client JavaScript. Adding it here would send the API key to the browser unnecessarily.
Put the connection settings in one place.
import { listApi } from "@genko-me/sdk";
export type Blog = { title: string; body: string };
export const apis = { blog: listApi<Blog>({ fields: [ { id: "title", type: "text" }, { id: "body", type: "richtext" }, ], }),};import { getSecret } from "astro:env/server";import { createGenko } from "@genko-me/sdk";import { apis } from "./schema";
export const genko = createGenko({ workspace: "your-workspace", apiKey: getSecret("GENKO_API_KEY")!, apis,});
export const client = genko.apis;The API key is read with getSecret from Astro's astro:env/server, not from import.meta.env or process.env. Import this client only from server-side code such as frontmatter. Do not pass it to browser scripts or to islands from other frameworks.
Set your public URL as site in astro.config.mjs. The share buttons use it to build absolute URLs.
import { defineConfig } from "astro/config";
export default defineConfig({ site: "https://your-site.example",});Show the list
Split the list with Astro's paginate() and use Pagination for page links. With [...page].astro, the route root (/blog) is page 1 and /blog/2 onward are the later pages.
---import type { GetStaticPaths, Page } from "astro";import { Field, Pagination } from "@genko-me/astro";import { client } from "../../lib/client";
export const getStaticPaths = (async ({ paginate }) => { const posts = await client.blog.getAll({ orders: "-publishedAt" }); return paginate(posts, { pageSize: 10 });}) satisfies GetStaticPaths;
type Post = Awaited<ReturnType<typeof client.blog.getAll>>[number];interface Props { page: Page<Post>;}const { page } = Astro.props;---<html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width" /> <title>Blog</title> </head> <body> <main> <h1>Blog ({page.total} entries)</h1> {page.data.length === 0 && <p>There are no published entries.</p>} <ul> {page.data.map((post) => ( <li> <a href={`/blog/entries/${post.id}`}> <Field api={client.blog} entry={post} id="title" /> </a> </li> ))} </ul> <Pagination page={page} lang="en" /> </main> </body></html>Pass api, entry, and id to Field, and it renders according to the field type (text, date and time, image, rich text, and so on). Text is always escaped, so HTML in an entry title is not executed. Pass the page from Astro's paginate() to Pagination as is. With a single page, it renders nothing.
getAll() fetches 100 entries at a time internally and returns all of them. It does not accept limit or offset.
Open /blog with npm run dev and confirm the list appears. The await in frontmatter also runs during astro build, and the result is baked into static HTML.
Show a single entry
Put the detail page in the dynamic route src/pages/blog/entries/[id].astro. With the default output: 'static', a dynamic route is generated at build time for each path that getStaticPaths() returns.
---import type { InferGetStaticPropsType } from "astro";import { Field, RichText, ShareButtons } from "@genko-me/astro";import { client } from "../../../lib/client";
export async function getStaticPaths() { const posts = await client.blog.getAll(); return posts.map((post) => ({ params: { id: post.id }, props: { post } }));}
type Props = InferGetStaticPropsType<typeof getStaticPaths>;const { post } = Astro.props;const url = new URL(Astro.url.pathname, Astro.site ?? Astro.url.origin).href;---<html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width" /> <title>{post.title}</title> <link rel="canonical" href={url} /> </head> <body> <main> <a href="/blog">All entries</a> <article> <h1><Field api={client.blog} entry={post} id="title" /></h1> <RichText html={post.body} class="prose" /> </article> <ShareButtons url={url} title={post.title} lang="en" /> </main> </body></html>getStaticPaths() can pass the post it fetched through props, so the page does not need to call get() again. post.body is an HTML string, and RichText inserts it as is (genko.me sanitizes rich text on the server when it is saved). as lets you choose div, article, or section, and HTML attributes such as class are passed through.
ShareButtons needs an absolute HTTP(S) URL in url. This example builds the current page's URL from site in astro.config.mjs. The buttons render as static HTML like the heading and body, and only the copy and share-sheet actions run a small script.
Run npm run build and confirm that dist/ contains one HTML file per entry. Then open a detail page with npm run preview and confirm that the share buttons work. Copying requires a secure context such as HTTPS.
Preview drafts
A draft's draftKey is unknown at build time, so render only the preview page on request. The public list and detail pages stay static. First add an SSR adapter. This example uses @astrojs/node; choose the adapter for your host if it differs.
npm install @astrojs/nodeimport { defineConfig } from "astro/config";import node from "@astrojs/node";
export default defineConfig({ site: "https://your-site.example", adapter: node({ mode: "standalone" }),});Create a route dedicated to previews. prerender = false renders only this route on request, and fetchGenkoEntry from @genko-me/astro/server fetches the entry with its draftKey.
---export const prerender = false;
import { Field, PreviewNotice } from "@genko-me/astro";import { fetchGenkoEntry } from "@genko-me/astro/server";import { client } from "../../../lib/client";
Astro.response.headers.set("Cache-Control", "private, no-store");Astro.response.headers.set("X-Robots-Tag", "noindex, nofollow");Astro.response.headers.set("Referrer-Policy", "no-referrer");
const result = Astro.url.searchParams.has("draftKey") ? await fetchGenkoEntry({ api: client.blog, id: Astro.params.id, searchParams: Astro.url.searchParams, }) : { status: "empty" as const };if (result.status === "empty") Astro.response.status = 404;if (result.status === "error") Astro.response.status = 503;---<html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width" /> <meta name="robots" content="noindex,nofollow" /> <title>Preview</title> </head> <body> <main> {result.status === "ok" ? ( <> <PreviewNotice lang="en" /> <article> <h1><Field api={client.blog} entry={result.data.entry} id="title" /></h1> <Field api={client.blog} entry={result.data.entry} id="body" /> </article> </> ) : ( <p>{result.status === "empty" ? "Entry not found." : "Could not load the entry."}</p> )} </main> </body></html>fetchGenkoEntry returns an object whose status is ok, empty, or error. When ok, data.entry is the entry, data.draft says whether it was fetched as a draft, and data.lang is set when you pass lang. A missing or invalid draftKey, or a missing entry, gives empty, and a failed fetch gives error. An invalid draftKey is never switched to the published version.
You set the page's response headers yourself. fetchGenkoEntry fetches from the API without caching, but it does not change the page's response headers. Always set these three on this route:
| Header | Value | Reason |
|---|---|---|
Cache-Control | private, no-store | Keep unpublished content out of CDN and browser caches |
X-Robots-Tag | noindex, nofollow | Keep the page out of search engines |
Referrer-Policy | no-referrer | Do not send URLs containing draftKey to other sites |
In the API settings in the dashboard (/w/your-workspace/apis/blog/settings), point the preview URL template at this route.
https://your-site.example/blog/preview/{id}?draftKey={key}When nothing appears
| Symptom | What to check |
|---|---|
| The list is empty | Is the entry saved and published? Has its unpublish date passed? |
401 | Is the API key within its validity period? Is .env kept out of Git, and is the same variable set in the build environment? |
403 | Does the key's workspace match the workspace you connect to? |
| The build does not show new entries | astro build bakes in the content at build time. Rebuild after publishing or changing an entry (see the webhook section of the tutorial) |
The preview returns 404 | Does the URL include draftKey? Is the entry a saved draft? |
The preview returns 503 | Check the connection to the delivery API and the API key. Logs never include response bodies, URLs, or keys |
| Copying with the share buttons fails | Is the page open in a secure context such as HTTPS? |
Next, the tutorial covers adjusting the components and reflecting content updates.
Last updated: October 27, 2026