> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mixpeek.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Apps

> Host a search front end at {slug}.mxp.co: deploy a built static site, call retrievers without exposing your key, add sign-in and domains.

Deploy a front end you built (React, Vue, Svelte or plain HTML) to `https://{slug}.mxp.co`, where it calls your retrievers through a proxy that adds your API key on the server. Mixpeek hosts the files, versions every deploy, and can add sign-in, a custom domain and server functions.

**Prerequisites**

* A Mixpeek API key in `MIXPEEK_API_KEY` and a namespace with a retriever. The [Quickstart](https://docs.mixpeek.com/docs/overview/quickstart.md) creates both.
* A front end that builds to static files with an `index.html`, for example `npm create vite@latest`.
* A plan that allows another app: Free allows 1 app, Pro 10, Enterprise unlimited. Custom domains, per-user sign-in management and GitHub deploys need Enterprise.

## Deploy an app

**1. Create the app**

The slug is globally unique and becomes the URL. Only `slug` and `meta` are required.

```bash cURL theme={null}
APP_ID=$(curl -s -X POST https://api.mixpeek.com/v1/apps \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"slug": "night-scene-search", "meta": {"title": "Night scene search"}}' \
  | jq -r .app_id)
echo "$APP_ID"
```

In Studio: **Apps**, then **Create App**.

**2. Build and zip your front end**

```bash Shell theme={null}
npm run build
cd dist && zip -r ../app.zip . && cd ..
```

**3. Upload the bundle and start the deploy**

The upload URL is valid for 3,600 seconds.

```bash cURL theme={null}
UPLOAD=$(curl -s -X POST "https://api.mixpeek.com/v1/apps/$APP_ID/deploy/upload-url" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"filename": "app.zip", "content_type": "application/zip"}')

curl -X PUT "$(echo "$UPLOAD" | jq -r .upload_url)" \
  -H "Content-Type: application/zip" --data-binary @app.zip

DEPLOY_ID=$(curl -s -X POST "https://api.mixpeek.com/v1/apps/$APP_ID/deploy" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"bundle_s3_key\": \"$(echo "$UPLOAD" | jq -r .bundle_s3_key)\", \"environment\": \"production\", \"message\": \"First deploy\"}" \
  | jq -r .deploy_id)
```

`environment` is `production` (the default) or `staging`. In Studio, drop the zip on the app's **Deploy** panel instead. The [mixpeek CLI](https://docs.mixpeek.com/docs/tools/sdks-and-cli.md#mixpeek-cli) runs the build, zip, upload and deploy as `mixpeek apps deploy`.

**4. Wait for the build**

```bash cURL theme={null}
curl -s "https://api.mixpeek.com/v1/apps/$APP_ID/deploys/$DEPLOY_ID" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" | jq '{status, error}'
```

`status` moves from `queued` to `building` to `complete` or `failed`. A failed deploy leaves the previous version live.

## Check that it worked

Open `https://night-scene-search.mxp.co`. A staging deploy is at `https://staging-night-scene-search.mxp.co`. Every deploy also appears in `GET /v1/apps/{app_id}/versions` with its message.

## Call your retrievers from the app

Call Mixpeek through relative `/api/...` paths. The proxy forwards the request to `api.mixpeek.com` with the app owner's API key and namespace added on the server, so no key ships in your JavaScript and there is no CORS setup. Calls are billed to the organization that owns the app; visitors need no Mixpeek account.

```javascript JavaScript title="src/search.js" theme={null}
export async function search(query) {
  const retrieverId = window.__MIXPEEK__.RETRIEVER_ID; // set in build_config.env_vars below
  const res = await fetch(`/api/v1/retrievers/${retrieverId}/execute`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ inputs: { query } }),
  });
  const run = await res.json();
  if (run.status === "degraded") console.warn(run.warnings);
  return run.documents;
}
```

The proxy allows only the calls a public page needs, because anyone who can load the page can send them with your key. A path outside the list answers 403.

| Allowed through `/api` | Methods |
| - | - |
| `/v1/retrievers/{id}/execute`, `/v1/retrievers/{id}`, `/v1/retrievers` | execute: GET, POST; reads: GET |
| `/v1/retrievers/interactions` (record a click or view) | POST |
| `/v1/marketplace/catalog/{name}/execute` and `/config` | GET, POST |
| Collection and document reads: `/v1/collections`, `/v1/collections/{id}`, `/v1/collections/list`, `/v1/collections/{id}/documents/{doc}`, `/v1/collections/{id}/documents/list` and `/aggregate`, `/v1/documents/list` | GET or POST as listed |
| `/v1/namespaces/{id}`, taxonomy reads, cluster reads, `/v1/features` | GET, and POST for `/list` routes |
| Uploads: `/v1/buckets/{id}/objects`, `/v1/buckets/{id}/uploads` and confirm, batch status | POST and GET |

Create, update and delete routes, `/v1/namespaces/list` and organization routes are refused. To allow more paths for one app, set `build_config.api_allow` to a list of `{methods, pattern}` rules with `PATCH /v1/apps/{app_id}`.

## Configuration and secrets

`PATCH /v1/apps/{app_id}` sets two kinds of values in `build_config`:

| Field | Where it is readable | Use it for |
| - | - | - |
| `env_vars` | In the browser as `window.__MIXPEEK__.NAME`, and in server functions as `ctx.env.NAME` | Public settings: retriever ids, feature flags |
| `secrets` | Only in server functions, as `ctx.env.NAME`. Masked as `***` in API responses | Third-party keys, and a Mixpeek key a server function uses |

Every `env_vars` entry except `MIXPEEK_API_KEY` is sent to the browser, so never put a secret there. `window.__MIXPEEK__` also carries `apiUrl`, `proxyPrefix` (`/api`) and the app's `auth` settings. Do not read `process.env` in browser code; it is undefined there.

```bash cURL title="Set a public value and a secret" theme={null}
curl -X PATCH "https://api.mixpeek.com/v1/apps/$APP_ID" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"build_config": {"env_vars": {"RETRIEVER_ID": "failure-discovery"}, "secrets": {"SERPAPI_KEY": "replace_me"}}}'
```

## Server functions

A file under `api/` in your project becomes an endpoint at `/functions/...`: `api/hello.ts` answers `GET` and `POST /functions/hello`. Mixpeek compiles TypeScript with esbuild and runs the handler on the server. `mixpeek apps deploy` uploads `api/` with the bundle.

```typescript TypeScript title="api/visits.ts" theme={null}
export default async function handler(ctx) {
  const count = Number((await ctx.kv.get("visits")) ?? "0") + 1;
  await ctx.kv.set("visits", String(count));
  return { status: 200, body: { visits: count, from: ctx.req.query.ref ?? null } };
}
```

| `ctx` field | Contents |
| - | - |
| `ctx.req` | `method`, `path`, `query`, `body` (parsed JSON, up to 1 MB), `headers` (without cookies and forwarding headers) |
| `ctx.env` | `env_vars` plus `secrets` |
| `ctx.kv` | Per-app key-value store: `get(key)`, `set(key, value, ttlSeconds)`, `del(key)`, `keys()`. Values are strings |

Return `{status, body, headers}`; an object `body` is sent as JSON. `console.log`, `warn`, `error` and `info` go to the app's runtime logs.

## Sign-in, users and domains

> [accordion] Sign-in modes
>
> Set `auth_config.mode` with `PATCH /v1/apps/{app_id}`:
>
> | Mode | Who can open the app |
> | - | - |
> | `public` | Anyone |
> | `password` | Anyone with a shared password |
> | `api_key` | Requests with an `X-App-Key` header |
> | `clerk` | Signed-in users (Google, GitHub or email), managed per app |
> | `jwt` | Holders of tokens you issue |
> | `sso_oidc`, `sso_saml` | Users of your identity provider (Okta, Auth0, Azure AD, SAML 2.0) |
>
> With `clerk`, Mixpeek loads a sign-in script and exposes `window.MixpeekAuth`: `onReady(callback)`, `isSignedIn`, `user` (`id`, `email`, `name`, `avatar_url`), `showSignIn()`, `showSignUp()` and `signOut()`. `/_auth/me` returns the signed-in user.

> [accordion] Invite and manage users (Enterprise, clerk mode)
>
> | Action | Call |
> | - | - |
> | List members | `GET /v1/apps/{app_id}/users` |
> | Invite | `POST /v1/apps/{app_id}/users/invite` with `email_address` and `role` (`org:member` or `org:admin`) |
> | Change role | `PATCH /v1/apps/{app_id}/users/{user_id}/role` |
> | Remove | `DELETE /v1/apps/{app_id}/users/{user_id}` |
> | Pending invitations | `GET /v1/apps/{app_id}/users/invitations`, revoke with `DELETE .../invitations/{invitation_id}` |
>
> Invites answer 400 when the app's mode is not `clerk`. Studio shows a **Users** tab on `clerk` apps.

> [accordion] Custom domain (Enterprise)
>
> 1. `POST /v1/apps/{app_id}/domains` with `{"domain": "search.example.com"}`. The response has `verification_token` and `cname_target`.
> 2. Add a TXT record `_mixpeek-verify.search.example.com` with the value `mixpeek-site-verification={verification_token}`.
> 3. Add a CNAME from `search.example.com` to `cname_target`.
> 4. `POST /v1/apps/{app_id}/domains/search.example.com/verify`. Mixpeek checks DNS for up to 72 hours and issues the TLS certificate.
>
> Subdomains only; an apex domain cannot take a CNAME. The `{slug}.mxp.co` address keeps working.

> [accordion] Deploy from GitHub with pull-request previews (Enterprise)
>
> `POST /v1/apps/{app_id}/connect-repo` with `repo_url` and `branch` connects a repository. Each push to the branch runs `npm ci` and `npm run build`, then deploys `dist/`, `build/` or `out/` to production. Your `package.json` needs a `build` script. Each pull request gets a preview at `https://pr-{number}-{slug}.mxp.co`, rebuilt on new commits and removed when the pull request closes. `mixpeek apps preview` lists them.

## Versions, rollback and staging

Every deploy creates a numbered version with its message, file hashes and source files.

| Task | Call |
| - | - |
| List versions | `GET /v1/apps/{app_id}/versions` |
| Compare two | `GET /v1/apps/{app_id}/versions/{from}/diff/{to}` |
| Download a bundle | `GET /v1/apps/{app_id}/versions/{version}/download` |
| Roll back one version | `POST /v1/apps/{app_id}/rollback` |
| Restore any version | `POST /v1/apps/{app_id}/versions/{version}/restore` |
| Promote staging to production | `POST /v1/apps/{app_id}/promote` |

## Logs and monitoring

| What | Call |
| - | - |
| Build log, live | `GET /v1/apps/{app_id}/deploys/{deploy_id}/logs/stream` (Server-Sent Events; replays earlier lines on reconnect) |
| Request and server-function logs | `GET /v1/apps/{app_id}/logs?log_type=requests` or `runtime`, with `hours` (1 to 168), `level` and `limit` (up to 1,000) |
| Browser errors and web vitals | `GET /v1/apps/{app_id}/analytics?hours=1` |
| Error count | `GET /v1/apps/{app_id}/error-rate?minutes=60` |

Read an SSE stream with `fetch` and a reader; `EventSource` cannot send the `Authorization` header.

## What goes wrong

| Symptom | Cause | Fix |
| - | - | - |
| 422 on create | The plan's app limit is reached | `error.details` gives the limit and count. Delete an app or change plan. |
| Create fails on the slug | Slugs are unique across all organizations | Pick another slug. |
| Deploy `failed` | No `index.html` in the zip, or the build broke | Read `error` on the deploy, or stream its log. |
| `/api` call answers 403 | The path is outside the proxy's allowlist | Use an allowed read route, or add an `api_allow` rule for the app. |
| A value shows up in page source | It is in `env_vars` | Move it to `secrets` and read it in a server function. |
| Domain never turns active | TXT or CNAME record missing or wrong | Check both records, then call verify again. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.