{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/roark/json-schema/roark-call-cost-schema.json",
  "title": "CallCost",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/roark-call-api-openapi.yml#/components/schemas/CallCost",
  "type": "object",
  "properties": {
    "callId": {
      "type": "string",
      "format": "uuid"
    },
    "currency": {
      "type": "string",
      "const": "usd"
    },
    "totalUsdMicros": {
      "type": "integer",
      "description": "Total billable spend for this call, in micro-dollars."
    },
    "totalUsd": {
      "type": "number"
    },
    "breakdown": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/CostBreakdownItem"
      },
      "description": "Spend by cost type. Sums to totalUsdMicros."
    },
    "items": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/CallCostLine"
      },
      "description": "Every billable cost line attributed to the call."
    }
  },
  "required": [
    "callId",
    "currency",
    "totalUsdMicros",
    "totalUsd",
    "breakdown",
    "items"
  ],
  "$defs": {
    "CallCostLine": {
      "type": "object",
      "properties": {
        "eventId": {
          "type": "string",
          "description": "Stable id of the cost event. Use it to deduplicate."
        },
        "source": {
          "type": "string",
          "enum": [
            "SIM_PLATFORM_FEE",
            "SIM_TTS",
            "SIM_STT",
            "SIM_LLM",
            "SIM_TELEPHONY",
            "METRIC",
            "TRANSCRIPTION",
            "INTERNAL_LLM",
            "INTERNAL_STT",
            "PHONE_NUMBER"
          ]
        },
        "surface": {
          "type": "string",
          "enum": [
            "SIMULATION",
            "POST_CALL"
          ]
        },
        "amountUsdMicros": {
          "type": "integer"
        },
        "amountUsd": {
          "type": "number"
        },
        "quantity": {
          "type": "number",
          "minimum": 0
        },
        "quantityUnit": {
          "type": "string",
          "enum": [
            "MINUTES",
            "INPUT_TOKENS",
            "OUTPUT_TOKENS",
            "CHARACTERS",
            "AUDIO_SECONDS",
            "UNITS"
          ]
        },
        "provider": {
          "type": [
            "string",
            "null"
          ]
        },
        "model": {
          "type": [
            "string",
            "null"
          ]
        },
        "simulationJobId": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid"
        },
        "metricDefinitionId": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid",
          "description": "The metric a METRIC line was charged for."
        },
        "metricCollectionJobId": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid",
          "description": "The grading pass a METRIC line paid for. A call graded twice carries one line per pass."
        },
        "occurredAt": {
          "type": "string",
          "description": "When the cost was incurred, ISO 8601."
        }
      },
      "required": [
        "eventId",
        "source",
        "surface",
        "amountUsdMicros",
        "amountUsd",
        "quantity",
        "quantityUnit",
        "provider",
        "model",
        "simulationJobId",
        "metricDefinitionId",
        "metricCollectionJobId",
        "occurredAt"
      ]
    },
    "CostBreakdownItem": {
      "type": "object",
      "properties": {
        "source": {
          "type": "string",
          "enum": [
            "SIM_PLATFORM_FEE",
            "SIM_TTS",
            "SIM_STT",
            "SIM_LLM",
            "SIM_TELEPHONY",
            "METRIC",
            "TRANSCRIPTION",
            "INTERNAL_LLM",
            "INTERNAL_STT",
            "PHONE_NUMBER"
          ],
          "description": "The cost source, e.g. SIM_PLATFORM_FEE, SIM_LLM, METRIC."
        },
        "surface": {
          "type": "string",
          "enum": [
            "SIMULATION",
            "POST_CALL"
          ],
          "description": "SIMULATION or POST_CALL."
        },
        "amountUsdMicros": {
          "type": "integer",
          "description": "Billable spend for this type, in micro-dollars."
        },
        "amountUsd": {
          "type": "number",
          "description": "The same figure in US dollars."
        },
        "quantity": {
          "type": "number",
          "minimum": 0,
          "description": "Units billed (see the line items for the unit)."
        }
      },
      "required": [
        "source",
        "surface",
        "amountUsdMicros",
        "amountUsd",
        "quantity"
      ]
    }
  }
}