# Platform APIs on a published site

> The JavaScript methods ESTAGE gives every published site — window.estageAI, estageConnector, estageBlog, estageCommunity, estageSetLocale, estagePersonalize, estageFunnel — with signatures and what each one does.

Source: https://knowledge.estage.com/platform/apis/
Part of the ESTAGE knowledge base (https://knowledge.estage.com). Full corpus: https://knowledge.estage.com/llms-full.txt

---
A site built on ESTAGE is not a static export: the platform installs runtime modules into it, and
those modules expose globals your pages can call. The AI wires them for you when you describe
what you want — "email me on Telegram when someone submits this form", "add a chatbot", "show my
three latest posts on the homepage" — but they are ordinary JavaScript, so hand-written code and
custom components can call them too.

Two rules apply to all of them:

- **A global exists only when its feature is enabled** on the project. Call defensively
  (`window.estageAI?.ask?.(…)`) so a page never crashes when a feature is off.
- **Never hand-roll the thing a module already does.** Credentials live server-side; an API key
  pasted into site code is exposed to every visitor. The modules exist precisely so keys never
  reach the bundle.

## window.estageAI — AI without an API key

Available when the [AI Assistant](/ai-assistant/) is enabled. Calls run server-side against the
platform's AI and are billed to the project owner, bounded by a monthly cap.

| Method | Returns | What it does |
| --- | --- | --- |
| `chat(messages, { onToken })` | full text | Streaming conversation. `messages` is `[{ role: 'user' \| 'assistant', content }]`; `onToken(text)` fires per chunk. |
| `ask(prompt)` | string | One-shot question. |
| `generate(prompt)` | string | One-shot generation — a headline, a summary line, a reply draft. |
| `classify(text, ['A','B','C'])` | one category | Picks exactly one of the categories you pass. |
| `extract(text, ['name','email'])` | object | Pulls named fields out of free text. |
| `summarize(text)` | string | Condenses text. |
| `translate(text, 'Spanish')` | string | Translates text. |
| `vision(image, prompt)` | string | Describes or analyses an image. `image` is a URL or `{ base64, mediaType }`. Also available as `analyzeImage`. |
| `readDocument(file, prompt)` | string | Answers questions about a PDF or text document. Also available as `askDocument`. |
| `image(prompt)` | image URL | Generates an image, hosted on the CDN. Requires image generation to be enabled. |
| `config` | object | The assistant's greeting, starter suggestions, and widget settings. |

More on what to build with these: [AI Assistant examples](/ai-assistant/examples/).

## window.estageConnector — call an external service safely

Available when at least one [connector](/connectors/) is configured. The secret stays encrypted
server-side; the call goes through a relay that pins the destination.

| Method | What it does |
| --- | --- |
| `estageConnector(connector, action, params)` | Fire-and-forget action, e.g. `estageConnector('telegram', 'sendMessage', { text })`. |
| `estageConnectorFetch(connector, action, params)` | Same, but returns the relay's response envelope when you need the result. |
| `estageConnectorPresign(connector, action, params)` | Requests a signed URL — used by storage connectors for direct uploads. |

## window.estageBlog — read your posts anywhere

Available when the [blog](/blog/) is enabled. Blog pages use hooks directly; this global is for
everything outside `/blog` — a homepage "latest posts" strip, a footer list.

| Method | Returns | What it does |
| --- | --- | --- |
| `posts(options?)` | array | Published posts, with the same filters as the blog pages (limit, category, author). Drafts are hidden. |
| `post(slug)` | object | One post by slug. |
| `authors()` / `categories()` | array | The author and category lists. |
| `ready` | promise | Resolves once the post snapshot has loaded. |
| `reload()` | promise | Re-fetches the snapshot. |

## window.estageCommunity — community data on your site

Available when the [Community toolkit](/community/) is installed. Reads work for anonymous
visitors; writes require a signed-in member, and the member's credential never touches your page —
the browser holds only an opaque, community-scoped handle.

| Method | What it does |
| --- | --- |
| `fetchThreads({ filter, channel, category, cursor })` | A page of the feed, with a cursor for the next one. |
| `fetchThread(id)` / `fetchComments(id)` | One post and its comments. |
| `fetchProfileThreads(...)` | Posts by one member. |
| `createPost(...)` / `createComment(...)` | Publish a post or a comment as the signed-in member. |
| `uploadImage(...)` | Attach an image to a post. |

## Localization — window.estageSetLocale, estageGetLocale, estageI18n

Available when [localization](/platform/) is set up. Translations are applied to the rendered DOM,
so your JSX stays untouched.

| Method | What it does |
| --- | --- |
| `estageSetLocale(code)` | Switches the site to a locale and remembers the choice. |
| `estageGetLocale()` | The active locale code. |
| `estageI18n.locales()` | Every locale the site has, default first. |
| `estageI18n.current()` / `getDefault()` | Active and default locale codes. |
| `estageI18n.name(code)` | The language's native name, for a custom switcher. |

Build your own language switcher by calling `estageSetLocale` — never hand-roll a translation
layer next to this one.

## window.estagePersonalize — audience variants

Available when personalization is set up. Copy variants are data, chosen per audience.

| Method | What it does |
| --- | --- |
| `audience()` | The active audience id, or null. |
| `set(id)` | Forces an audience — useful for previewing a variant. |
| `off()` | Clears the audience and restores the default copy. |

## window.estageFunnel — funnel tracking from any element

Available on pages that are part of a [funnel](/funnels/). Lets a hand-written or AI-generated
button report into funnel analytics without importing anything.

| Method | What it does |
| --- | --- |
| `trackEvent(name, data?)` | Records a custom event, e.g. `trackEvent('upgrade-clicked', { variant: 'a' })`. |
| `captureLead(...)` | Records a lead against the current step. |
| `recordVisit(...)` | Records a visit to the current step. |

## Building against the platform from outside

Beyond runtime globals, a project can be driven programmatically: connect it to the Claude app as
a custom connector and an assistant can read files, edit pages, generate images, and publish
through the platform's own validated write path. See [Connect Claude Code](/claude-code/).
