---
title: "AI Studio Full-Stack Development: SSR, Server Functions, REST APIs and Secrets"
description: "Build full-stack AI Studio apps with server rendering, server functions, REST API endpoints and secrets, and migrate an older React project to the new architecture."
url: https://help.aesthetixcrm.com/en/articles/2244-ai-studio-full-stack-development-ssr-server-functions-rest-apis-and-secrets
collection: "AI Studio"
updated: 2026-11-20
language: en
---

# AI Studio Full-Stack Development: SSR, Server Functions, REST APIs and Secrets

Build full-stack AI Studio apps with server rendering, server functions, REST API endpoints and secrets, and migrate an older React project to the new architecture.

AI Studio projects can do more than draw pages. New projects render pages on the server, run private logic on the server, expose HTTP endpoints, and store credentials outside browser code, all in one project. You work with this in AI Agents > AI Studio, in the project builder and its chat.

> **Protect patient privacy:** AI Studio is an AI feature and is not approved for Protected Health Information (PHI). Never put PHI or live patient data into prompts, the AI Studio chat, server functions, REST endpoints, secrets, or anything an AI Studio app stores or sends. Use full-stack features for non-PHI purposes such as marketing sites, event pages, lead capture and public tools. Secrets keep credentials out of the browser; they do not make an app safe for patient records.

## The four building blocks

<table style="min-width: 75px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><th colspan="1" rowspan="1"><p><strong>Capability</strong></p></th><th colspan="1" rowspan="1"><p><strong>Primary purpose</strong></p></th><th colspan="1" rowspan="1"><p><strong>Typical use</strong></p></th></tr><tr><td colspan="1" rowspan="1"><p><strong>SSR (server-side rendering)</strong></p></td><td colspan="1" rowspan="1"><p>Render pages on the server</p></td><td colspan="1" rowspan="1"><p>SEO, public pages, social previews</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>Server functions</strong></p></td><td colspan="1" rowspan="1"><p>Run private application logic</p></td><td colspan="1" rowspan="1"><p>Internal backend operations, protected integrations</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>REST APIs</strong></p></td><td colspan="1" rowspan="1"><p>Expose HTTP endpoints</p></td><td colspan="1" rowspan="1"><p>Webhooks, integrations, external applications</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>Secrets</strong></p></td><td colspan="1" rowspan="1"><p>Protect sensitive configuration</p></td><td colspan="1" rowspan="1"><p>API keys, tokens, credentials</p></td></tr></tbody></table>

### Server-side rendering (SSR)

SSR generates page HTML on the server before it is sent to the visitor. Search engines, social platforms and browsers receive real page content without depending on JavaScript to build the page. It is especially useful for marketing sites and landing pages, multi-page sites, public pages with unique URLs and metadata, search-focused content, and pages shared through services that build link previews (for example a "Spring Skin Event" page shared in a text message).

### Server functions

Server functions let your app's own front end request server-side work without placing the implementation in the browser. Use them to:

-   Call external services with private credentials.
    
-   Load protected data.
    
-   Validate submitted information.
    
-   Perform server-side calculations.
    
-   Transform data before returning it to the front end.
    
-   Keep sensitive logic off the client.
    

Security tip: server functions keep implementation details on the server, but credentials should still be stored as secrets. Return only the information the browser actually needs.

### REST APIs

REST API routes create HTTP endpoints that services outside your AI Studio app can call. Routes use paths such as `/api/...` and can support methods such as GET or POST depending on the app. Use them for:

-   Receiving webhooks.
    
-   Connecting third-party applications.
    
-   Building public or authenticated APIs.
    
-   Accepting information from another service.
    
-   Returning structured data such as JSON.
    

### Secrets

Secrets provide server-side storage for values that must not be in front-end code: API keys, authentication tokens, webhook signing secrets, integration credentials and private service configuration. Server-side code can use them without exposing them in the client bundle. Secrets are never sent to the browser.

## Key benefits

-   **Server-rendered content** for visitors, search engines and link previews.
    
-   **Private backend logic** away from browser code.
    
-   **Secure credentials** stored as secrets instead of the client bundle.
    
-   **External integrations** through REST endpoints for webhooks and third-party services.
    
-   **Unified development:** front end and supported backend in one project.
    
-   **Integrated publishing:** the app and its supported server functionality publish from the same workflow.
    
-   **Backward compatibility:** existing Vite/React projects keep working and are not converted automatically.
    

## Choosing between server functions and REST APIs

Use server functions for private logic called by your own front end, and REST APIs when an outside system needs a callable HTTP endpoint.

<table style="min-width: 50px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><th colspan="1" rowspan="1"><p><strong>Need</strong></p></th><th colspan="1" rowspan="1"><p><strong>Recommended approach</strong></p></th></tr><tr><td colspan="1" rowspan="1"><p>Front end securely calls its own backend logic</p></td><td colspan="1" rowspan="1"><p>Server function</p></td></tr><tr><td colspan="1" rowspan="1"><p>External service sends data into the app</p></td><td colspan="1" rowspan="1"><p>REST API</p></td></tr><tr><td colspan="1" rowspan="1"><p>Third-party system needs an HTTP endpoint</p></td><td colspan="1" rowspan="1"><p>REST API</p></td></tr><tr><td colspan="1" rowspan="1"><p>Internal operation requires a private API key</p></td><td colspan="1" rowspan="1"><p>Server function plus a secret</p></td></tr><tr><td colspan="1" rowspan="1"><p>Webhook provider needs a callback URL</p></td><td colspan="1" rowspan="1"><p>REST API</p></td></tr><tr><td colspan="1" rowspan="1"><p>Sensitive value must stay outside browser code</p></td><td colspan="1" rowspan="1"><p>Secret</p></td></tr></tbody></table>

## New projects vs existing projects

All newly created AI Studio projects use the TanStack Start full-stack architecture by default (projects created on or after September 8, 2026).

<table style="min-width: 50px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><th colspan="1" rowspan="1"><p><strong>Project type</strong></p></th><th colspan="1" rowspan="1"><p><strong>Behavior</strong></p></th></tr><tr><td colspan="1" rowspan="1"><p>New AI Studio project</p></td><td colspan="1" rowspan="1"><p>Uses TanStack Start full-stack architecture</p></td></tr><tr><td colspan="1" rowspan="1"><p>Existing Vite/React project</p></td><td colspan="1" rowspan="1"><p>Keeps its existing architecture; not migrated automatically</p></td></tr><tr><td colspan="1" rowspan="1"><p>Existing project that needs the new stack</p></td><td colspan="1" rowspan="1"><p>Needs the separate Migrate to SSR process (below)</p></td></tr></tbody></table>

Recommendation: do not recreate or migrate a project only because the new architecture exists. First decide whether the app really needs SSR, private server logic, REST endpoints or secrets.

## Build a full-stack project step by step

Start from what the app must do, not just how it looks. Identify private operations, external integrations and sensitive credentials first so AI Studio can place each in the right part of the app.

### Step 1: Create a new project

1.  In your account, open **AI Agents** and select **AI Studio**.
    
2.  Create a new project.
    
3.  Describe the website or application you want.
    

### Step 2: Describe the full behavior

Mention external services, private credentials, incoming webhooks, protected processing and public API needs. Example prompt for a non-PHI use:

`Build an event sign-up site with a public landing page, a server-side check that a promo code is valid, and an API endpoint that receives sign-up webhooks from our scheduling tool.`

### Step 3: Add secrets for protected credentials

1.  Identify the private credential the integration needs.
    
2.  Add it through the Secrets workflow when AI Studio prompts you.
    
    ![](https://files.us.gleap.ai/pf/g/640067b236b432d4bc3c20bb-cQFw7oOzfVP4LR7efRoALIWyBrvqtohmUFG3NwEUxoQqh5TJlHy6giQNvg1LyJi0jRZmXwNzzwn.png?v=1&k=us1&s=api&e=1795348800&sig=NE9cVs9L9I2v8SUJiLo3cjDIl5PtMZWG_1VWry6iho8)
3.  Give the secret a clear, recognizable name.
    
4.  Reference the secret only from the server-side code that needs it.
    
5.  Test the integration without returning the credential to the browser.
    

### Step 4: Build and review server functions

1.  Verify sensitive processing runs on the server.
    
2.  Confirm private credentials come from secrets.
    
3.  Return only the information the front end needs.
    
4.  Test successful and unsuccessful requests.
    
5.  Review the generated code (see the AI Studio Code Editor) when you need more validation or customization.
    

### Step 5: Create REST APIs for external requests

1.  Define the endpoint path (for example `/api/...`).
    
2.  Define the supported HTTP method.
    
3.  Define the expected request payload.
    
4.  Add authentication or signature validation when required.
    
5.  Process the request on the server.
    
6.  Return an appropriate response.
    

Webhook security: when the provider supports signatures or authentication, validate them before processing any protected operation.

### Step 6: Preview and test

-   Confirm public pages load correctly.
    
-   Test server functions with expected and unexpected inputs.
    
-   Test REST endpoints with the intended requests.
    
-   Confirm secrets are not exposed in browser-visible output.
    
-   Verify important error states are handled safely.
    
-   Review page titles, headings and metadata.
    

### Step 7: Publish

1.  Click **Publish**.
    
2.  Review or update the generated website address.
    
3.  Confirm publication.
    
4.  Open the published URL and test the live app.
    

### Step 8: Connect a custom domain

1.  Open **Publish**.
    
2.  Select **Add Custom Domain**.
    
3.  Enter the domain you want to use.
    
4.  Add the DNS records AI Studio provides at your domain provider, if required.
    
5.  Click **Verify DNS**.
    
6.  Wait for certificate provisioning to finish.
    
7.  Test the app through the connected domain.
    

You can also connect a domain from **Settings** > **Domains & URL Redirects** > **\+ Connect a domain** > **AI Studio**. The Domain Hub flow verifies DNS first, then lets you pick the AI Studio project to link.

If your app takes payments, see the note below.

> **Taking payments?** AX Pay is Aesthetix CRM's own payment provider, with better rates than Stripe. See the AX Pay Overview and Setup Guide for setup. Never store card data or patient payment records in your own server functions; use a payment provider's hosted checkout.

## SEO for full-stack projects

New full-stack projects use server rendering, so crawlers receive finished HTML. Before publishing important public pages, review titles, meta descriptions, heading structure, canonical URLs, social preview information, sitemap behavior, and the rendered content on the live page. See the guide "AI Studio SEO and Server Rendering" for the SEO & AI search panel, sitemaps, Search Console and llms.txt.

## Migrate an existing React project to SSR

The **Migrate to SSR** feature converts an existing React/Vite project to TanStack Start by creating a separate copy. Your original project, connected domains and version history are untouched. Migration is optional; projects that do not need SSR, server functions, REST APIs or secrets can stay as they are.

### Eligibility

The **Migrate to SSR** option (marked **Advanced** in Project Settings) is available when:

-   The project uses the existing React/Vite architecture.
    
-   You have permission to edit the project.
    
-   You open it from the project's settings.
    

### What happens to the original project

1.  AI Studio creates a new project in the same account.
    
2.  The pages from your original project are copied into it.
    
3.  AI Studio suggests the name `{project name} (TanStack)`, which you can edit.
    
4.  The new project starts as a draft and is not published automatically.
    
5.  The original keeps its version history.
    
6.  The new project starts with a separate AI Studio chat.
    
7.  Your original published site and connected domains stay unchanged.
    

<table style="min-width: 75px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><th colspan="1" rowspan="1"><p><strong>Component</strong></p></th><th colspan="1" rowspan="1"><p><strong>Original React project</strong></p></th><th colspan="1" rowspan="1"><p><strong>Migrated project</strong></p></th></tr><tr><td colspan="1" rowspan="1"><p>Architecture</p></td><td colspan="1" rowspan="1"><p>Stays React/Vite</p></td><td colspan="1" rowspan="1"><p>Converted to TanStack Start</p></td></tr><tr><td colspan="1" rowspan="1"><p>Pages</p></td><td colspan="1" rowspan="1"><p>Preserved</p></td><td colspan="1" rowspan="1"><p>Copied into the new project</p></td></tr><tr><td colspan="1" rowspan="1"><p>Name</p></td><td colspan="1" rowspan="1"><p>Unchanged</p></td><td colspan="1" rowspan="1"><p>Customizable before migration</p></td></tr><tr><td colspan="1" rowspan="1"><p>Publishing status</p></td><td colspan="1" rowspan="1"><p>Unchanged</p></td><td colspan="1" rowspan="1"><p>Starts as a draft</p></td></tr><tr><td colspan="1" rowspan="1"><p>Connected domains</p></td><td colspan="1" rowspan="1"><p>Stay connected</p></td><td colspan="1" rowspan="1"><p>Not transferred automatically</p></td></tr><tr><td colspan="1" rowspan="1"><p>Version history</p></td><td colspan="1" rowspan="1"><p>Retained</p></td><td colspan="1" rowspan="1"><p>Begins separately</p></td></tr><tr><td colspan="1" rowspan="1"><p>AI Studio chat</p></td><td colspan="1" rowspan="1"><p>Existing chat remains</p></td><td colspan="1" rowspan="1"><p>New chat starts</p></td></tr><tr><td colspan="1" rowspan="1"><p>Workflow associations</p></td><td colspan="1" rowspan="1"><p>Remain</p></td><td colspan="1" rowspan="1"><p>Need review and updates</p></td></tr></tbody></table>

Migrating does not replace your published site or move its domains. Publishing the converted project and moving a domain are separate actions. If you decide not to use the migrated project, the original stays available and unchanged.

### Migration status and available actions

While agents convert the copy, the project card shows **Migrating to SSR** and some actions are restricted. The restrictions apply only to the copy.

<table style="min-width: 50px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><th colspan="1" rowspan="1"><p><strong>Action</strong></p></th><th colspan="1" rowspan="1"><p><strong>During migration</strong></p></th></tr><tr><td colspan="1" rowspan="1"><p>Preview the project</p></td><td colspan="1" rowspan="1"><p>Available</p></td></tr><tr><td colspan="1" rowspan="1"><p>Use AI Studio chat</p></td><td colspan="1" rowspan="1"><p>Available</p></td></tr><tr><td colspan="1" rowspan="1"><p>Delete the migrated project</p></td><td colspan="1" rowspan="1"><p>Available</p></td></tr><tr><td colspan="1" rowspan="1"><p>Publish the project</p></td><td colspan="1" rowspan="1"><p>Unavailable</p></td></tr><tr><td colspan="1" rowspan="1"><p>Save code changes</p></td><td colspan="1" rowspan="1"><p>Unavailable</p></td></tr><tr><td colspan="1" rowspan="1"><p>Restore previous versions</p></td><td colspan="1" rowspan="1"><p>Unavailable</p></td></tr><tr><td colspan="1" rowspan="1"><p>Modify domain settings</p></td><td colspan="1" rowspan="1"><p>Unavailable</p></td></tr><tr><td colspan="1" rowspan="1"><p>Change slugs</p></td><td colspan="1" rowspan="1"><p>Unavailable</p></td></tr><tr><td colspan="1" rowspan="1"><p>Remix the project</p></td><td colspan="1" rowspan="1"><p>Unavailable</p></td></tr></tbody></table>

When migration succeeds, the status clears and the project becomes a normal TanStack Start app. If it stops before completing, open the migrated project's chat and enter `continue the migration`. AI Studio resumes using the same copy. Starting another migration from the original project creates an additional copy, so resume from the existing migrated project instead.

### Steps

1.  In your account, open **AI Agents** and select **AI Studio**, then open the React/Vite project you want to migrate.
    
2.  Open **Project Settings** and find **Migrate to SSR**.
    
    ![](https://files.us.gleap.ai/pf/g/640067b236b432d4bc3c20bb-AzHc8KPPWs03IL4fkuJiuiPe9yTBeqrJg5FRmlV3i4SWijcqbcLrzaB22ETqIAEkOBj91My5UAB.png?v=1&k=us1&s=api&e=1795348800&sig=BUNt4GszIXk6jvjkZBh7ZT7hV1MfxCJ-EC0HBrVZ19w)
3.  Review the suggested name (`{project name} (TanStack)`), edit it if you like, and confirm the new project is created separately.
    
    ![](https://files.us.gleap.ai/pf/g/640067b236b432d4bc3c20bb-EhuLJk0SOnnYdMjxqVNuTgybjsvdjoC1qruRES6sBt1nXFg13VihIh33I7MMk3C428R9YObIbEk.png?v=1&k=us1&s=api&e=1795348800&sig=qvWAVieDMg8S9Y840Dt880f-3MhHxbsHPN7rmmrViYY)
4.  Review the migration notes (new project is a draft; original site unchanged; domains stay on the original; history stays with the original; new chat; some actions unavailable) and accept them.
    
5.  Click **Migrate**. AI Studio creates the project, opens it and starts the conversion through its chat.
    
    ![](https://files.us.gleap.ai/pf/g/640067b236b432d4bc3c20bb-eyO9jRNdAPCoN96OfbGejpSN9fQ6rmFYZGmTL2M2SkATw1C4GTVExeRNqQHNOtJLVHasKKgZOtS.png?v=1&k=us1&s=api&e=1795348800&sig=LTKhuYDKmwnVolQABSKlL5RHeAc--01DMlCs-tBxyfE)
6.  Follow progress in the chat and watch for the **Migrating to SSR** status on the dashboard. Use Preview when available. Let the conversion finish before publishing.
    
7.  After the status clears, preview pages and navigation, test the features that needed SSR, and use the chat or editing tools to fix anything missing or changed.
    

A completed migration does not guarantee everything works exactly as before. Test before publishing.

### Review forms, calendars and workflow connections

Migration does not redirect workflow triggers from the original project to the new one.

1.  List the forms and calendars the original app used.
    
2.  Confirm they work in the migrated project, and check any CRM connections behind them.
    
3.  Go to **Marketing** > **Workflows**.
    
4.  Open workflows tied to the original AI Studio project.
    
5.  Review trigger filters for project, form, page path and domain.
    
6.  Update them to the migrated project when you switch.
    
7.  After publishing, submit test entries and confirm the workflows run.
    

Project-specific triggers stay associated with the original project until you update them. See the guide on the AI Studio Form Submitted workflow trigger. If your site books appointments, remember that AI Studio calendar booking works with native Aesthetix CRM calendars, not EMR calendars.

### Review publishing and domain connections

Before publishing the migrated project: confirm it works, decide which domain or URL to use, verify workflows and integrations, review titles, metadata and SEO settings, and plan the domain move separately so your live site is not disrupted. The original site and domains remain unchanged until you make separate publishing or domain changes.

## Troubleshooting

<table style="min-width: 50px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><th colspan="1" rowspan="1"><p><strong>Issue</strong></p></th><th colspan="1" rowspan="1"><p><strong>What to check</strong></p></th></tr><tr><td colspan="1" rowspan="1"><p>Server function fails</p></td><td colspan="1" rowspan="1"><p>Function inputs, required secrets, server-side errors, and the data returned to the front end</p></td></tr><tr><td colspan="1" rowspan="1"><p>REST endpoint cannot be called</p></td><td colspan="1" rowspan="1"><p>Endpoint path, HTTP method, that the app is published, request format and authentication</p></td></tr><tr><td colspan="1" rowspan="1"><p>External API authentication fails</p></td><td colspan="1" rowspan="1"><p>The correct secret exists and server code references the intended value</p></td></tr><tr><td colspan="1" rowspan="1"><p>Webhook verification fails</p></td><td colspan="1" rowspan="1"><p>Signing secret, request headers, signature-validation logic and callback URL</p></td></tr><tr><td colspan="1" rowspan="1"><p>Custom domain does not load</p></td><td colspan="1" rowspan="1"><p>DNS records exactly match those provided; run <strong>Verify DNS</strong> after propagation</p></td></tr><tr><td colspan="1" rowspan="1"><p>Existing project does not show new architecture behavior</p></td><td colspan="1" rowspan="1"><p>It may be a Vite/React project; existing projects are not migrated automatically</p></td></tr><tr><td colspan="1" rowspan="1"><p>Migration appears stuck</p></td><td colspan="1" rowspan="1"><p>Enter <code>continue the migration</code> in the migrated project's chat; do not start a second migration</p></td></tr><tr><td colspan="1" rowspan="1"><p>Publish, save or restore greyed out</p></td><td colspan="1" rowspan="1"><p>The copy is still migrating; wait for <strong>Migrating to SSR</strong> to clear</p></td></tr><tr><td colspan="1" rowspan="1"><p>Form submissions no longer trigger workflows</p></td><td colspan="1" rowspan="1"><p>Update workflow trigger filters to the migrated project</p></td></tr><tr><td colspan="1" rowspan="1"><p>Integrations or keys missing after migration</p></td><td colspan="1" rowspan="1"><p>Re-add secrets and reconnect integrations; credentials are not guaranteed to transfer</p></td></tr></tbody></table>

## Frequently Asked Questions

**Do existing AI Studio projects automatically move to TanStack Start?**

No. Existing Vite/React projects keep their architecture. You can migrate one yourself with Migrate to SSR.

**What is the difference between a server function and a REST API?**

Server functions are for private backend logic your own front end calls. REST APIs expose HTTP endpoints that external systems can call.

**Can a server function use a secret?**

Yes. This is the usual way to use a private API key, token or other protected credential.

**Can I create webhook endpoints in AI Studio?**

Yes. REST API routes can provide callback URLs for supported webhook providers. Validate signatures when the provider offers them.

**Should I put a secret directly in front-end code?**

No. Keep it in secrets and reference it only from server-side code.

**Does SSR replace the Advanced SEO workflow for older projects?**

No. Older projects keep their architecture, so the Advanced SEO Support tools still apply to them.

**Can I edit generated backend code?**

Yes. The AI Studio Code Editor gives direct access to project code for manual changes and validation.

**Can I download my project code?**

Yes. See the guide "AI Studio Git Sync and Code Download" for ZIP download, including versions from Version History.

**Should I migrate my React project just because it is available?**

No. Migration is optional. If your project already meets your needs, keep it.

**Can I migrate the same project more than once?**

Yes. Each migration from the original creates another separate copy. To finish an incomplete one, resume the existing copy.

**Do I need to recreate API keys and integrations after migrating?**

Possibly. Credentials and integrations are not guaranteed to transfer, so re-add secrets and reconnect integrations before publishing.
