# Flush external state (/brain/docs/api/generated/flush)

Uploads local event history and the latest completed checkpoint to external storage and returns the resulting checkpoint reference. Requires a management token and configured persistence.

## POST /sessions/{id}/flush

Bearer authentication is required.

```json
{
  "openapi": "3.1.0",
  "info": {
    "description": "HTTP API for the Brain agent session server.",
    "title": "Brain",
    "version": "current"
  },
  "servers": [
    {
      "description": "Local development",
      "url": "http://127.0.0.1:8080"
    }
  ],
  "paths": {
    "/sessions/{id}/flush": {
      "post": {
        "description": "Uploads local event history and the latest completed checkpoint to external storage and returns the resulting checkpoint reference. Requires a management token and configured persistence.",
        "operationId": "flush",
        "parameters": [
          {
            "description": "Opaque session ID.",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "pattern": "^[a-fA-F0-9]{32}$",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SyncStatus"
                }
              }
            },
            "description": "Flush external state"
          },
          "default": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            },
            "description": "Error. 400 invalid_request; 401 missing/invalid Bearer token; 403 forbidden; 404 not_found; 409 conflict or cursor_unavailable; 413 body limit; 422 unsupported; 429 overloaded (Retry-After: 1); 500 brain_error. X-Request-ID is present on every response."
          }
        },
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Flush external state"
      }
    }
  },
  "components": {
    "schemas": {
      "SyncStatus": {
        "additionalProperties": false,
        "properties": {
          "checkpoint": {
            "type": "string"
          },
          "error": {
            "type": "string"
          },
          "history_bytes": {
            "type": "integer"
          },
          "native_checkpoint": {
            "type": "string"
          },
          "pending": {
            "type": "boolean"
          },
          "resume_offset": {
            "type": "integer"
          },
          "time": {
            "format": "date-time",
            "type": "string"
          }
        },
        "required": [
          "history_bytes",
          "resume_offset",
          "pending"
        ],
        "type": "object"
      },
      "ErrorResponse": {
        "additionalProperties": false,
        "properties": {
          "error": {
            "$ref": "#/components/schemas/ErrorDetail"
          },
          "request_id": {
            "type": "string"
          }
        },
        "required": [
          "error",
          "request_id"
        ],
        "type": "object"
      },
      "ErrorDetail": {
        "additionalProperties": false,
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "code",
          "message"
        ],
        "type": "object"
      }
    },
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "type": "http"
      }
    }
  }
}
```

[Complete OpenAPI document](/brain/openapi.json)