{
  "openapi": "3.1.0",
  "info": {
    "title": "Frecall Call API",
    "version": "1.0.0",
    "summary": "Secure access to call history and private recordings.",
    "description": "Read tenant-scoped Frecall call history, customer conversations, timing data, outcomes, ratings, and short-lived recording links. Version 1 remains backward compatible.",
    "contact": {
      "name": "Frecall support",
      "email": "support@frecall.com",
      "url": "https://frecall.com/contact/"
    }
  },
  "servers": [
    {
      "url": "https://api.frecall.com",
      "description": "Production"
    }
  ],
  "tags": [
    {
      "name": "Discovery",
      "description": "Public API metadata."
    },
    {
      "name": "Calls",
      "description": "Tenant-scoped call history."
    },
    {
      "name": "Customers",
      "description": "Call history for a specific customer."
    }
  ],
  "paths": {
    "/v1": {
      "get": {
        "tags": ["Discovery"],
        "operationId": "discoverApi",
        "summary": "Discover the API",
        "description": "Returns the current API version, status, documentation URL, and protected endpoints. Authentication is not required.",
        "security": [],
        "responses": {
          "200": {
            "description": "API metadata.",
            "headers": {
              "X-Frecall-API-Version": {
                "$ref": "#/components/headers/ApiVersion"
              },
              "X-Request-ID": {
                "$ref": "#/components/headers/RequestId"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DiscoveryResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/calls": {
      "get": {
        "tags": ["Calls"],
        "operationId": "listCalls",
        "summary": "List calls",
        "description": "Returns the authenticated account's calls in reverse chronological order.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/CallList"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/v1/customers/{customerId}/calls": {
      "get": {
        "tags": ["Customers"],
        "operationId": "listCustomerCalls",
        "summary": "List a customer's calls",
        "description": "Returns only calls associated with the supplied customer identifier and owned by the authenticated account.",
        "parameters": [
          {
            "name": "customerId",
            "in": "path",
            "required": true,
            "description": "The exact caller/customer identifier stored by Frecall.",
            "schema": {
              "type": "string",
              "minLength": 1
            },
            "example": "customer_8271"
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/CallList"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/v1/calls/{callId}": {
      "get": {
        "tags": ["Calls"],
        "operationId": "getCall",
        "summary": "Get call detail",
        "description": "Returns one owned call. Set includeRecording=true to request a private listening URL. Signed URLs expire after 30 minutes.",
        "parameters": [
          {
            "name": "callId",
            "in": "path",
            "required": true,
            "description": "Frecall call-log identifier.",
            "schema": {
              "type": "string",
              "minLength": 1
            },
            "example": "call_01JX7F2QK9"
          },
          {
            "name": "includeRecording",
            "in": "query",
            "required": false,
            "description": "When true, include a 30-minute signed listening URL. The API key must have recordings:read scope.",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Call detail.",
            "headers": {
              "X-Frecall-API-Version": {
                "$ref": "#/components/headers/ApiVersion"
              },
              "X-Request-ID": {
                "$ref": "#/components/headers/RequestId"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/RateLimit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/RateRemaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/RateReset"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data"],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CallDetail"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerApiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "fc_live_…",
        "description": "Create and rotate API keys in Frecall Manager. Keys are shown once."
      }
    },
    "parameters": {
      "Limit": {
        "name": "limit",
        "in": "query",
        "required": false,
        "description": "Number of calls to return.",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 50,
          "default": 20
        }
      },
      "Cursor": {
        "name": "cursor",
        "in": "query",
        "required": false,
        "description": "Opaque nextCursor from the previous response. Do not decode or modify it.",
        "schema": {
          "type": "string"
        }
      }
    },
    "headers": {
      "ApiVersion": {
        "description": "Resolved Frecall API major version.",
        "schema": {
          "type": "string",
          "example": "1"
        }
      },
      "RequestId": {
        "description": "Unique request identifier for support and diagnostics.",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "RateLimit": {
        "description": "Maximum requests permitted per minute for this key.",
        "schema": {
          "type": "integer",
          "example": 120
        }
      },
      "RateRemaining": {
        "description": "Requests remaining in the current rate window.",
        "schema": {
          "type": "integer",
          "example": 119
        }
      },
      "RateReset": {
        "description": "Unix timestamp when the current rate window resets.",
        "schema": {
          "type": "integer",
          "example": 1784798160
        }
      }
    },
    "responses": {
      "CallList": {
        "description": "A page of calls.",
        "headers": {
          "X-Frecall-API-Version": {
            "$ref": "#/components/headers/ApiVersion"
          },
          "X-Request-ID": {
            "$ref": "#/components/headers/RequestId"
          },
          "X-RateLimit-Limit": {
            "$ref": "#/components/headers/RateLimit"
          },
          "X-RateLimit-Remaining": {
            "$ref": "#/components/headers/RateRemaining"
          },
          "X-RateLimit-Reset": {
            "$ref": "#/components/headers/RateReset"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/CallListResponse"
            }
          }
        }
      },
      "BadRequest": {
        "description": "Invalid query input.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "error": {
                "code": "invalid_cursor",
                "message": "The cursor is invalid."
              }
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing, invalid, or expired API key.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "Forbidden": {
        "description": "The key lacks the required scope or source-IP permission.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "NotFound": {
        "description": "The call does not exist or is not owned by the authenticated account.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "RateLimited": {
        "description": "The API key exceeded 120 requests per minute.",
        "headers": {
          "X-RateLimit-Limit": {
            "$ref": "#/components/headers/RateLimit"
          },
          "X-RateLimit-Remaining": {
            "$ref": "#/components/headers/RateRemaining"
          },
          "X-RateLimit-Reset": {
            "$ref": "#/components/headers/RateReset"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "InternalError": {
        "description": "The request could not be completed.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    },
    "schemas": {
      "DiscoveryResponse": {
        "type": "object",
        "required": ["data"],
        "properties": {
          "data": {
            "type": "object",
            "required": ["name", "version", "status", "documentation", "endpoints"],
            "properties": {
              "name": {
                "type": "string",
                "example": "Frecall Call API"
              },
              "version": {
                "type": "string",
                "example": "v1"
              },
              "status": {
                "type": "string",
                "example": "available"
              },
              "documentation": {
                "type": "string",
                "format": "uri",
                "example": "https://api.frecall.com/docs/"
              },
              "endpoints": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "CallListResponse": {
        "type": "object",
        "required": ["data", "paging"],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CallSummary"
            }
          },
          "paging": {
            "$ref": "#/components/schemas/Paging"
          }
        }
      },
      "CallSummary": {
        "type": "object",
        "description": "Lean six-field public representation of a call.",
        "required": [
          "id",
          "customerId",
          "agent",
          "timing",
          "result",
          "recordingAvailable"
        ],
        "properties": {
          "id": {
            "type": "string",
            "example": "call_01JX7F2QK9"
          },
          "customerId": {
            "type": "string",
            "example": "customer_8271"
          },
          "agent": {
            "$ref": "#/components/schemas/Agent"
          },
          "timing": {
            "$ref": "#/components/schemas/Timing"
          },
          "result": {
            "$ref": "#/components/schemas/CallResult"
          },
          "recordingAvailable": {
            "type": "boolean",
            "example": true
          }
        }
      },
      "CallDetail": {
        "type": "object",
        "description": "Lean six-field detail representation of a call.",
        "required": ["id", "customerId", "agent", "timing", "result", "recording"],
        "properties": {
          "id": {
            "type": "string",
            "example": "call_01JX7F2QK9"
          },
          "customerId": {
            "type": "string",
            "example": "customer_8271"
          },
          "agent": {
            "$ref": "#/components/schemas/Agent"
          },
          "timing": {
            "$ref": "#/components/schemas/Timing"
          },
          "result": {
            "$ref": "#/components/schemas/CallDetailResult"
          },
          "recording": {
            "$ref": "#/components/schemas/Recording"
          }
        }
      },
      "Agent": {
        "type": "object",
        "required": ["id", "name"],
        "properties": {
          "id": {
            "type": "string",
            "example": "agent_104"
          },
          "name": {
            "type": "string",
            "example": "Tobi"
          }
        }
      },
      "Timing": {
        "type": "object",
        "required": [
          "ringAt",
          "assignedAt",
          "answeredAt",
          "endedAt",
          "queueToAssignmentSeconds",
          "waitSeconds",
          "durationSeconds"
        ],
        "properties": {
          "ringAt": {
            "type": ["string", "null"],
            "format": "date-time"
          },
          "assignedAt": {
            "type": ["string", "null"],
            "format": "date-time"
          },
          "answeredAt": {
            "type": ["string", "null"],
            "format": "date-time"
          },
          "endedAt": {
            "type": ["string", "null"],
            "format": "date-time"
          },
          "queueToAssignmentSeconds": {
            "type": ["number", "null"],
            "minimum": 0
          },
          "waitSeconds": {
            "type": ["number", "null"],
            "minimum": 0
          },
          "durationSeconds": {
            "type": ["number", "null"],
            "minimum": 0
          }
        }
      },
      "CallResult": {
        "type": "object",
        "required": ["outcome", "rating", "connectionIssues", "billingStatus"],
        "properties": {
          "outcome": {
            "type": "string",
            "enum": ["queued", "active", "completed", "unanswered"],
            "example": "completed"
          },
          "rating": {
            "type": ["number", "null"],
            "minimum": 1,
            "maximum": 5
          },
          "connectionIssues": {
            "type": "integer",
            "minimum": 0
          },
          "billingStatus": {
            "type": ["string", "null"]
          }
        }
      },
      "CallDetailResult": {
        "allOf": [
          {
            "$ref": "#/components/schemas/CallResult"
          },
          {
            "type": "object",
            "properties": {
              "comment": {
                "type": "string"
              }
            }
          }
        ]
      },
      "Recording": {
        "type": "object",
        "required": [
          "available",
          "startedAt",
          "endedAt",
          "durationSeconds",
          "sizeBytes"
        ],
        "properties": {
          "available": {
            "type": "boolean"
          },
          "startedAt": {
            "type": ["string", "null"],
            "format": "date-time"
          },
          "endedAt": {
            "type": ["string", "null"],
            "format": "date-time"
          },
          "durationSeconds": {
            "type": ["number", "null"],
            "minimum": 0
          },
          "sizeBytes": {
            "type": ["number", "null"],
            "minimum": 0
          },
          "contentType": {
            "type": "string",
            "example": "audio/mpeg"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Private signed listening URL returned only when includeRecording=true and the key has recordings:read scope."
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time",
            "description": "The signed URL expiry, normally 30 minutes after the request."
          }
        }
      },
      "Paging": {
        "type": "object",
        "required": ["nextCursor", "hasMore"],
        "properties": {
          "nextCursor": {
            "type": ["string", "null"],
            "description": "Opaque cursor for the next page."
          },
          "hasMore": {
            "type": "boolean"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "bearerApiKey": []
    }
  ]
}
