{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/clearstreet8e71/json-schema/clearstreet8e71-base-response-schema.json",
  "title": "BaseResponse",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/clearstreet8e71-api-version-api-openapi.yml#/components/schemas/BaseResponse",
  "type": "object",
  "required": [
    "metadata"
  ],
  "properties": {
    "error": {
      "oneOf": [
        {
          "oneOf": [
            {
              "type": "null"
            },
            {
              "$ref": "#/$defs/ApiError",
              "description": "Structured error details when the request is unsuccessful."
            }
          ]
        }
      ]
    },
    "metadata": {
      "$ref": "#/$defs/ResponseMetadata",
      "description": "Response metadata, including the request ID and optional pagination info."
    }
  },
  "$defs": {
    "ApiError": {
      "type": "object",
      "description": "A direct mapping of tonic::Status, for use in HTTP responses.",
      "required": [
        "code",
        "message"
      ],
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32",
          "description": "The error code is used to identify the nature of the error. It corresponds\nto an HTTP status code.",
          "minimum": 0
        },
        "details": {
          "$ref": "#/$defs/ErrorDetails",
          "description": "Additional error details, if any. This can include structured information\nsuch as field violations or error metadata."
        },
        "message": {
          "type": "string",
          "description": "A human-readable message providing more details about the error."
        }
      }
    },
    "ErrorDetails": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true
      }
    },
    "ResponseMetadata": {
      "type": "object",
      "description": "Metadata for the response. This will always contain a request ID which can be used to identify\nthe request to Clear Street for tracing, and optionally may include pagination data.",
      "required": [
        "request_id"
      ],
      "properties": {
        "next_page_token": {
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "string",
              "format": "byte",
              "description": "Base64URL-encoded pagination token"
            }
          ],
          "description": "A token that can be used to retrieve the next page of results, if any.\nThe token contains opaque pagination state.\nFiltering and sorting parameters must be provided with each request."
        },
        "page_number": {
          "type": [
            "integer",
            "null"
          ],
          "format": "int32",
          "description": "Pagination. Included if this was a GET (list) response",
          "minimum": 0
        },
        "previous_page_token": {
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "string",
              "format": "byte",
              "description": "Base64URL-encoded pagination token"
            }
          ],
          "description": "A token that can be used to retrieve the previous page of results, if any.\nThe token contains opaque pagination state.\nFiltering and sorting parameters must be provided with each request."
        },
        "request_id": {
          "type": "string",
          "description": "A unique ID for this request, generated upon ingestion of the request."
        },
        "total_items": {
          "type": [
            "integer",
            "null"
          ],
          "format": "int64",
          "description": "Total number of items available (not just in this page).",
          "minimum": 0
        },
        "total_pages": {
          "type": [
            "integer",
            "null"
          ],
          "format": "int32",
          "description": "Total number of pages available.",
          "minimum": 0
        }
      }
    }
  }
}