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

# Roll back an environment

> Rolls this environment back to a prior pinned version (FR-018..FR-023). `target_version` must name a successful forward-promote deployment row on this env — rollback re-runs the deployment at that row's `commit_sha`. Rollback is a promote at an older commit: it writes a fresh env-keyed snapshot, commits the env pointer, and dispatches the build. Returns 202 with the created `deployment` row; poll `GET /v1/deployments/{deployment_id}` to watch the build complete.

Feature-gated: while the `enable_env_rollback` flag is OFF for the caller's tenant this route responds `404` as if it did not exist.



## OpenAPI

````yaml /openapi.yaml post /v1/environments/{id}/rollback
openapi: 3.0.3
info:
  contact:
    email: hello@agentmark.co
    url: https://docs.agentmark.co
  description: >-
    The AgentMark Gateway API lets you ingest traces, create scores, and
    retrieve prompt templates programmatically.


    Most developers should use the [AgentMark SDK](/introduction/overview) for
    integration.

    The REST API is for cases where you need direct HTTP access or are building
    a custom integration.


    Versioning: every endpoint is prefixed with `/v1/`. Breaking changes ship
    under a new version prefix (`/v2/`, etc.) with a 90-day-minimum deprecation
    window — see [API versioning & stability](/api-reference/versioning) for the
    full policy on what constitutes a breaking vs. additive change.
  title: AgentMark Gateway API
  version: '1.0'
servers:
  - description: Production (AgentMark Cloud)
    url: https://api.agentmark.co
  - description: Local dev server (`npx @agentmark-ai/cli dev`)
    url: http://localhost:9418
security:
  - AppId: []
    BearerAuth: []
tags:
  - description: Ingest, query, and export OpenTelemetry trace data.
    name: Traces
  - description: >-
      Coding-agent session ingest (outerlayer sync) and content-addressed
      session images.
    name: Agents
  - description: Query individual spans across traces.
    name: Spans
  - description: Create, retrieve, list, and delete score records for spans and traces.
    name: Scoring
  - description: Structured-filter search across observability resources.
    name: Search
  - description: Retrieve the effective synced project configuration.
    name: Config
  - description: List and retrieve datasets.
    name: Datasets
  - description: Query server feature availability.
    name: Capabilities
  - description: Per-model LLM pricing data. Public, unauthenticated.
    name: Pricing
  - description: >-
      Create, list, and revoke tenant API keys. Plaintext returned exactly once
      at creation.
    name: API Keys
  - description: >-
      List and retrieve score configuration definitions from the synced project
      config.
    name: Score Configs
  - description: >-
      Trigger and inspect managed deployments. POST returns 202; deployments run
      asynchronously and progress is observed via GET.
    name: Deployments
  - description: >-
      Per-app named environments (e.g. `dev`, `prod`). CRUD for env lifecycle;
      promote/rollback routes land alongside in this group as feature 054 lands
      the saga.
    name: Environments
  - description: >-
      App CRUD — the top-level tenant entity every other resource hangs off.
      Lets a headless agent provision an app without the dashboard.
    name: Apps
  - description: Service health checks.
    name: Health
paths:
  /v1/environments/{id}/rollback:
    post:
      tags:
        - Environments
      summary: Roll back an environment
      description: >-
        Rolls this environment back to a prior pinned version (FR-018..FR-023).
        `target_version` must name a successful forward-promote deployment row
        on this env — rollback re-runs the deployment at that row's
        `commit_sha`. Rollback is a promote at an older commit: it writes a
        fresh env-keyed snapshot, commits the env pointer, and dispatches the
        build. Returns 202 with the created `deployment` row; poll `GET
        /v1/deployments/{deployment_id}` to watch the build complete.


        Feature-gated: while the `enable_env_rollback` flag is OFF for the
        caller's tenant this route responds `404` as if it did not exist.
      operationId: rollback-environment
      parameters:
        - in: path
          name: id
          required: true
          schema:
            format: uuid
            type: string
      requestBody:
        content:
          application/json:
            schema:
              properties:
                note:
                  maxLength: 2000
                  type: string
                target_version:
                  exclusiveMinimum: true
                  minimum: 0
                  type: integer
              required:
                - target_version
              type: object
      responses:
        '202':
          content:
            application/json:
              schema:
                properties:
                  data:
                    properties:
                      commit_sha:
                        type: string
                      deployment_id:
                        format: uuid
                        type: string
                      deployment_status:
                        enum:
                          - pending
                          - snapshotting
                          - deploying
                          - success
                          - failed
                        type: string
                      env_version:
                        exclusiveMinimum: true
                        minimum: 0
                        type: integer
                    required:
                      - deployment_id
                      - deployment_status
                      - env_version
                      - commit_sha
                    type: object
                required:
                  - data
                type: object
          description: >-
            Rollback ran — the snapshot was written, the env pointer was
            committed, and the build was dispatched.
        '400':
          content:
            application/json:
              schema:
                properties:
                  error:
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                    type: object
                required:
                  - error
                type: object
          description: >-
            Target version is not a valid prior forward-promote success, app has
            no git connection, or invalid request body.
        '401':
          content:
            application/json:
              schema:
                properties:
                  error:
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                    type: object
                required:
                  - error
                type: object
          description: Missing or invalid API key.
        '403':
          content:
            application/json:
              schema:
                properties:
                  error:
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                    type: object
                required:
                  - error
                type: object
          description: Caller lacks 'environment.promote' permission.
        '404':
          content:
            application/json:
              schema:
                properties:
                  error:
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                    type: object
                required:
                  - error
                type: object
          description: Environment or target version not found.
        '500':
          content:
            application/json:
              schema:
                properties:
                  error:
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                    type: object
                required:
                  - error
                type: object
          description: Unexpected failure running the rollback.
components:
  securitySchemes:
    AppId:
      description: >-
        Application ID for tenant scoping. X-Outerlayer-App-Id is accepted as an
        equivalent header.
      in: header
      name: X-Agentmark-App-Id
      type: apiKey
    BearerAuth:
      description: API key (sk_agentmark_*)
      scheme: bearer
      type: http

````