---
title: "Fork every briq of a stack into a new stack"
method: POST
path: "/v1/stacks/{id}/fork"
tags: ["stacks"]
---

# Fork every briq of a stack into a new stack

`POST /v1/stacks/{id}/fork`

## Request

- Base URL: `https://api.briq.cloud`
- URL: `https://api.briq.cloud/v1/stacks/{id}/fork`
- Auth: HTTP bearer

## Path parameters

- `id` string, required

## Request body

- StackForkBody
  - `into` string
  - `expose` 'public' | 'private': Reach the fork from outside briq: database ports get TLS endpoints, front doors a URL in this mode ("private": only whoever has it). Outputs then use them. Waits for the forks
  - `sleep` string: When the briq goes to sleep: after this long without use (agent calls, visits to its stack's URLs). A string: "30m", "3h", "7d" or "never", never a number. A sleeping briq keeps its disk, costs nothing for compute, and the next use wakes it. "never" keeps it always on (Pro plan and above). Left out, the source's. A window longer than this key allows is refused
  - `wait` boolean
  - `waitTimeoutMs` integer

## Response `201`

created

- ForkResult
  - `briqs` Briq[], required
    - `id` string, required
    - `teamId` string, required
    - `stackId` string, required
    - `name` string, required
    - `image` string, required
    - `size` 'nano' | 'small' | 'medium' | 'large', required
    - `state` 'creating' | 'running' | 'stopping' | 'stopped' | 'sleeping' | 'starting' | 'destroying' | 'destroyed' | 'error', required
    - `internalHost` string, required: Its address on the team's private network
    - `endpoints` object[], required: Its URL, once published (one at most), and its TCP endpoint, once published
      - `id` string, required
      - `port` integer, required
      - `protocol` 'http' | 'postgres' | 'mysql' | 'redis' | 'mongodb' | 'amqp' | 'bolt' | 'grpc': http: a URL; a database protocol (postgres, mysql, redis, mongodb, amqp, bolt, grpc): a TCP endpoint, reachable from outside over TLS, url is its address without the password
      - `mode` 'public' | 'private', required: public: anyone can open the URL; private: only whoever has the URL, which carries a secret checked before a request reaches the briq
      - `url` string, uri, required
    - `ports` integer[]
    - `databasePorts` object[]: Its recipe's database ports: briq_expose one with its protocol for a TCP endpoint
      - `port` integer, required
      - `protocol` 'http' | 'postgres' | 'mysql' | 'redis' | 'mongodb' | 'amqp' | 'bolt' | 'grpc', required
    - `expose` integer, nullable
    - `env` object: As declared: plain values, and { secret: NAME } for secrets, whose values never appear
    - `createdAt` string, date-time, required
    - `startedAt` string, date-time, nullable, required: When its current run started (its last run, while it is not running)
    - `sleep` string, required: When the briq goes to sleep: after this long without use (agent calls, visits to its stack's URLs). A string: "30m", "3h", "7d" or "never", never a number. A sleeping briq keeps its disk, costs nothing for compute, and the next use wakes it. "never" keeps it always on (Pro plan and above)
    - `sleepsAt` string, date-time, nullable, required: When it goes to sleep unless it is used before then: every use moves this later. Null when it is not running or never sleeps
    - `lastUsedAt` string, date-time, nullable, required
    - `costCentsSoFar` number, required: Euro cents billed so far, fractions of a cent included
    - `error` string, nullable, required
    - `destroysAt` string, date-time, nullable: When a briq in error is destroyed automatically; null in any other state
    - `stoppedReason` 'idle' | 'cap' | 'credits' | 'user' | 'provider' | 'exited', nullable: Why it is stopped or sleeping. idle and provider: asleep, the next call or visit wakes it. cap and credits: a limit, asleep again once it has cleared. user and exited: only briq_start runs it again
    - `lastExit` object, nullable: The last time its process ended on its own: exit code (128 + n for signal n), whether it ran out of memory, and when
      - `code` integer, required
      - `oomKilled` boolean, required
      - `at` string, date-time, required
    - `files` object[]: Its boot files, by path and size; their content is not returned
      - `path` string, required
      - `bytes` integer, required
    - `forkedFrom` string, nullable
  - `copied` object, required
  - `outputs` object
  - `stack` string, required
  - `skipped` string[]
  - `warning` string
  - `costLine` string, required

## Other responses

- `400`: validation
- `401`: unauthorized
- `402`: policy_violation or quota_exceeded (the key's policy), or payment_required (no credits: retrying cannot help)
- `403`: forbidden, or plan_limit (the team's plan does not allow it)
- `404`: not found
- `409`: invalid_state: not possible in the briq's current state; the message says why
- `413`: validation: the body, the command or its output is too large
- `429`: rate limited: retry after the `retry-after` header
- `502`: provider_error: the infrastructure refused the change
- `503`: provider_error: the infrastructure did not answer; retry in a moment

---

[API](https://skmtc.dev/briq/apis/briq-api.md) · [All operations](https://skmtc.dev/briq/apis/briq-api/llms.txt) · [OpenAPI document](https://skmtc.dev/briq/apis/briq-api/revisions/609b424459cb?raw)
