# Preview apps

URL: https://docs.hanzo.ai/docs/openapi/platform/post-platform-projects-by-project-apps-by-app-preview

> Puts a branch on its own URL.

`POST /v1/platform/projects/{project}/apps/{app}/preview`

> [Platform →](https://docs.hanzo.ai/docs/openapi/platform) · [All API references →](https://docs.hanzo.ai/docs/openapi) · [Get started →](https://docs.hanzo.ai/docs/guides)

|               |                                                                          |
| ------------- | ------------------------------------------------------------------------ |
| **Address**   | `https://api.hanzo.ai/v1/platform/projects/{project}/apps/{app}/preview` |
| **Method**    | `POST`                                                                   |
| **Operation** | `post_platform_projects_by_project_apps_by_app_preview`                  |
| **Auth**      | `Authorization: Bearer $HANZO_API_KEY`                                   |

Puts a branch on its own URL.

It deploys an already-built `image` to a per-branch preview and answers its URL,
the branch, the preview's slug and the deployment. The preview is a FIRST-CLASS
application named `<app>-<branch>` in the same project and tenant namespace, with
its own default host — so it is completely isolated from production while reusing
the same deploy mechanic. Re-previewing a branch converges that same target in
place rather than stacking another one.

It carries NO environment variables, deliberately: a preview never inherits
production's secrets. It also does not build — `image` is required and must
already exist, and `branch` defaults to the parent app's. A branch that does not
resolve to a valid slug distinct from the parent's is 400. Requires a validated
principal; 401 without one.

## Request

6 fields, body `application/json` (required).

| Field     | In   | Type   | Required | Description                                                               |
| --------- | ---- | ------ | -------- | ------------------------------------------------------------------------- |
| `project` | path | string | yes      | Project is the project the parent application lives under, from the path. |
| `app`     | path | string | yes      | App is the parent application's slug, from the path.                      |
| `app`     | body | string | —        | App is the parent application's slug, from the path.                      |
| `branch`  | body | string | —        | Branch is the branch to preview; defaults to the parent app's branch.     |
| `image`   | body | string | —        | Image is the already-built image ref to deploy.                           |
| `project` | body | string | —        | Project is the project the parent application lives under, from the path. |

## Response

| Status    | Body                 | Meaning  |
| --------- | -------------------- | -------- |
| `202`     | platform.previewView | accepted |
| `default` | problem-details      | refused  |

`202` body — 16 fields.

| Field                      | In   | Type                    | Always | Description                                                                                                                                                                                                                                                                                             |
| -------------------------- | ---- | ----------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `app`                      | body | string                  | —      | App is the preview application's own slug, `&lt;app&gt;-&lt;branch&gt;`.                                                                                                                                                                                                                                |
| `branch`                   | body | string                  | —      | Branch is the branch this preview maps.                                                                                                                                                                                                                                                                 |
| `deployment`               | body | platform.deploymentView | —      |                                                                                                                                                                                                                                                                                                         |
| `deployment.applicationId` | body | string                  | —      | ApplicationID is the app this deployed — the app's `id`, not its slug.                                                                                                                                                                                                                                  |
| `deployment.buildId`       | body | string                  | —      | BuildID is the build record behind a git deploy, whose logs and status live at /v1/platform/builds.                                                                                                                                                                                                     |
| `deployment.commit`        | body | string                  | —      | Commit is the git ref this built — the commit a deploy or a push named, else the app's branch.                                                                                                                                                                                                          |
| `deployment.createdAt`     | body | integer (int64)         | —      | CreatedAt is when the attempt was recorded, unix seconds.                                                                                                                                                                                                                                               |
| `deployment.id`            | body | string                  | —      | ID is the deployment's id (`dep_…`), minted when the attempt is recorded.                                                                                                                                                                                                                               |
| `deployment.image`         | body | string                  | —      | Image is the full `repo:tag` this deployment put in the CR.                                                                                                                                                                                                                                             |
| `deployment.message`       | body | string                  | —      | Message is why this attempt is not live: the failure, or the note that a newer deployment went live before this build finished.                                                                                                                                                                         |
| `deployment.org`           | body | string                  | —      | Org is the tenant the deployment belongs to, from the validated identity.                                                                                                                                                                                                                               |
| `deployment.source`        | body | string                  | —      | Source is which lane produced it: `git` (built from the repo) or `image` (an already-built ref deployed as-is, including promote and rollback).                                                                                                                                                         |
| `deployment.status`        | body | string                  | —      | Status is where the attempt got to: `building` while its image is being built, `deploying` once its CR reached the cluster — which is the terminal success state, the app's own status is what turns `live` — `error` with the reason in Message, or `superseded` when a newer version went live first. |
| `deployment.updatedAt`     | body | integer (int64)         | —      | UpdatedAt is its last transition, unix seconds — so for a terminal deployment it is when it reached that state.                                                                                                                                                                                         |
| `deployment.version`       | body | integer (int64)         | —      | Version counts this app's deployments, from 1 and monotonically.                                                                                                                                                                                                                                        |
| `url`                      | body | string                  | —      | URL is the preview's live HTTPS address.                                                                                                                                                                                                                                                                |

Failure carries the platform error shape — see [Errors](https://docs.hanzo.ai/docs/errors).

## Examples

**CLI**

```bash
hanzo platform projects apps preview <project> <app>
```

**SDK**

**.ts**

```ts
import { Configuration, PlatformApi } from 'hanzoai';

const api = new PlatformApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.postPlatformProjectsByProjectAppsByAppPreview({ project: 'project', app: 'app', app: "<app>", branch: "<branch>" });
```

**.py**

```python
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import PlatformApi

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = PlatformApi(client).post_platform_projects_by_project_apps_by_app_preview(project='project', app='app', app="<app>", branch="<branch>")
```

**.go**

```go
cfg := hanzoai.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := hanzoai.NewAPIClient(cfg)

resp, _, err := client.PlatformAPI.PostPlatformProjectsByProjectAppsByAppPreview(context.Background()).Execute()
if err != nil {
	return err
}
```

**.rs**

```rust
use hanzo_client::apis::{configuration::Configuration, platform_api};

let mut cfg = Configuration::new();
cfg.bearer_access_token = std::env::var("HANZO_API_KEY").ok();

let result = platform_api::post_platform_projects_by_project_apps_by_app_preview(&cfg, Default::default()).await?;
```

**.java**

```java
import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.PlatformApi;

ApiClient client = new ApiClient();
client.setBearerToken(System.getenv("HANZO_API_KEY"));

var result = new PlatformApi(client).postPlatformProjectsByProjectAppsByAppPreview();
```

**HTTP**

```bash
curl -X POST https://api.hanzo.ai/v1/platform/projects/<project>/apps/<app>/preview \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "app": "<app>",
       "branch": "<branch>"
     }'
```

**MCP**

MCP reaches **platform** through the `platform` tool, which names its 38 operations with its own verbs — this one among them, under a name only MCP declares. `describe` explains any of them:

```bash
curl -X POST https://api.hanzo.ai/v1/mcp \
  -H "Content-Type: application/json" \
  -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "tools/call",
       "params": {
         "name": "describe",
         "arguments": {
           "op": "get_build"
         }
       }
     }'
```

---

[Platform API](https://docs.hanzo.ai/docs/openapi/platform) · [All Hanzo APIs](https://docs.hanzo.ai/docs/openapi) · [Interactive reference](https://docs.hanzo.ai/docs/openapi/reference)
