{
  "openapi": "3.1.0",
  "info": {
    "title": "Trellus Call Data API",
    "version": "0.4.0",
    "description": "Read stored call activity, transcripts, recordings, and reporting totals. Each operation uses the authenticated user’s existing read scope. The detail schemas cover the common integration fields. See https://www.trellus.ai/developers/api#sync-call-records for an example client."
  },
  "servers": [
    {
      "url": "https://rpt-2.trellus.ai",
      "description": "Call list, one-call detail, and aggregate reporting. Operations on other hosts declare their own server."
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/visible": {
      "get": {
        "operationId": "listVisibleResources",
        "servers": [
          {
            "url": "https://ext.trellus.ai"
          }
        ],
        "security": [
          {
            "apiKeyHeader": []
          }
        ],
        "summary": "List the teams, users, groups, and memberships this key can read.",
        "responses": {
          "200": {
            "description": "Readable directory; team is present only with whole-team read access."
          },
          "default": {
            "$ref": "#/components/responses/RequestError"
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "team_id",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/bootstrap": {
      "get": {
        "operationId": "getReportingOptions",
        "servers": [
          {
            "url": "https://ext.trellus.ai"
          }
        ],
        "security": [
          {
            "apiKeyHeader": []
          }
        ],
        "summary": "Discover the key owner's account context and exact option values.",
        "responses": {
          "200": {
            "description": "Account configuration and filter vocabulary."
          },
          "default": {
            "$ref": "#/components/responses/RequestError"
          }
        }
      }
    },
    "/session-list-v6": {
      "post": {
        "operationId": "listCalls",
        "summary": "Return the newest matching session rows.",
        "responses": {
          "200": {
            "description": "JSON arrays in select order; started_at is Unix seconds.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Rows"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/RequestError"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SessionListRequest"
              }
            }
          }
        },
        "description": "Use UTC Unix microseconds for the inclusive start and exclusive end. Rows contain cells in select order and are returned newest first by started_at, in Unix seconds. Include session_id to match details and audio. The default limit is 50 and the maximum is 1,000. Split capped windows and deduplicate by session_id."
      }
    },
    "/metric-details-v7": {
      "post": {
        "operationId": "getCallMetrics",
        "summary": "Return aggregate count/sum rows, optionally grouped.",
        "responses": {
          "200": {
            "description": "JSON arrays in selects order; a group value is prepended when grouped.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Rows"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/RequestError"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MetricRequest"
              }
            }
          }
        }
      }
    },
    "/session": {
      "get": {
        "operationId": "getCall",
        "summary": "Return one session selected by the x-session-id header.",
        "responses": {
          "200": {
            "description": "Protobuf by default; x-proto-as-json true returns camelCase proto JSON without wordData.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CallDetail"
                }
              },
              "applicaton/json": {
                "schema": {
                  "$ref": "#/components/schemas/CallDetail"
                }
              },
              "application/protobuf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "description": "Inactive user, not found, not permissioned, or not on db; inspect the response body."
          },
          "default": {
            "$ref": "#/components/responses/RequestError"
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "x-session-id",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "x-proto-as-json",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "description": "Read one stored session using its session_id from listCalls or the browser SDK session.created event. Send x-proto-as-json: true to select camelCase protobuf JSON. That body may arrive with the legacy applicaton/json media type. Unset fields can be omitted. JSON excludes wordData."
      }
    },
    "/get-audio-links": {
      "get": {
        "operationId": "getCallAudioLinks",
        "servers": [
          {
            "url": "https://api.trellus.ai"
          }
        ],
        "security": [
          {
            "apiKeyHeader": []
          }
        ],
        "summary": "Return temporary audio URLs for one readable call.",
        "responses": {
          "200": {
            "description": "Object containing session, audio metadata, and audio_links; audio arrays align by index and may be empty.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CallAudioLinks"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/RequestError"
          },
          "400": {
            "description": "The selected session is within audio retention and its conversation type is not a call."
          },
          "401": {
            "description": "The session could not be read with this API key."
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "session_id",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "description": "Generate short-lived URLs using the session_id selected from the call list. The same key is sent in api_key on this host. Audio URLs expire after one hour and audio arrays may be empty. Generate or refresh links when needed. Audio and session detail share the default limit of one request per second per user. Audio errors can have an empty body and omit Retry-After."
      }
    }
  },
  "components": {
    "responses": {
      "RequestError": {
        "description": "Read the HTTP status and response text; on 429 honor Retry-After seconds.",
        "headers": {
          "Retry-After": {
            "description": "Delay in seconds on rate-limited responses.",
            "schema": {
              "type": "integer"
            }
          }
        },
        "content": {
          "text/plain": {
            "schema": {
              "type": "string"
            }
          }
        }
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      },
      "apiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "api_key"
      }
    },
    "schemas": {
      "Rows": {
        "type": "array",
        "items": {
          "type": "array",
          "items": {}
        }
      },
      "Filter": {
        "type": "object",
        "required": [
          "column_name",
          "operator",
          "value_safe"
        ],
        "properties": {
          "column_name": {
            "type": "string"
          },
          "operator": {
            "enum": [
              "EQ",
              "NEQ",
              "GT",
              "GE",
              "LT",
              "LE",
              "REGEX",
              "IN",
              "NIN"
            ]
          },
          "value_safe": {},
          "reducer": {
            "enum": [
              "ANY",
              "ALL"
            ]
          }
        }
      },
      "SessionListRequest": {
        "type": "object",
        "required": [
          "start",
          "select"
        ],
        "properties": {
          "start": {
            "type": "integer",
            "description": "Unix microseconds, inclusive."
          },
          "end": {
            "type": "integer",
            "description": "Unix microseconds, exclusive; defaults to now."
          },
          "team_id": {
            "type": "string"
          },
          "cnf": {
            "type": "array",
            "description": "Outer arrays are AND; inner arrays are OR.",
            "items": {
              "type": "array",
              "items": {
                "$ref": "#/components/schemas/Filter"
              }
            }
          },
          "select": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000,
            "default": 50
          }
        }
      },
      "MetricRequest": {
        "type": "object",
        "required": [
          "start",
          "selects"
        ],
        "properties": {
          "start": {
            "type": "integer",
            "description": "Unix microseconds, inclusive."
          },
          "end": {
            "type": "integer",
            "description": "Unix microseconds, exclusive; defaults to now."
          },
          "team_id": {
            "type": "string"
          },
          "cnf": {
            "type": "array",
            "description": "Filters applied to every aggregate.",
            "items": {
              "type": "array",
              "items": {
                "$ref": "#/components/schemas/Filter"
              }
            }
          },
          "selects": {
            "type": "array",
            "description": "Count with cnf or sum with column_name; both may be supplied.",
            "items": {
              "anyOf": [
                {
                  "type": "object",
                  "required": [
                    "cnf"
                  ],
                  "properties": {
                    "cnf": {
                      "type": "array"
                    }
                  }
                },
                {
                  "type": "object",
                  "required": [
                    "column_name"
                  ],
                  "properties": {
                    "column_name": {
                      "type": "string"
                    },
                    "cnf": {
                      "type": "array"
                    }
                  }
                }
              ]
            }
          },
          "group_by": {
            "type": "object",
            "properties": {
              "column_name": {
                "type": "string"
              },
              "step_size_safe": {
                "description": "Bin width in the grouped column units; required for float/time grouping."
              },
              "step_start_safe": {
                "description": "Bin origin. Required when step_size_safe is supplied."
              },
              "step_modulus_safe": {
                "description": "Optional repeating period in the grouped column units."
              }
            },
            "required": [
              "column_name"
            ],
            "description": "Use exact grouping for strings, booleans, bytes and enums. Do not supply step parameters for these types. Floating-point and started_at grouping require step_size_safe and step_start_safe. Integer grouping can use exact values or steps. step_size_safe is the bin width; step_start_safe is its origin; optional step_modulus_safe is a repeat period. Values use the grouped column’s units: started_at uses seconds. For stepped groups, the key is floor(((value - origin) modulo period, when supplied) / width). It is a bin index, not a date. Compatibility exception: the current metric-details-v7 endpoint scales a started_at group key by 1,000,000. Divide by 1,000,000 to recover the bin index before converting it to a time range."
          }
        }
      },
      "CallDetail": {
        "type": "object",
        "description": "Common fields from SessionData in protobuf JSON. Other fields may be present. Default-valued fields may be omitted.",
        "properties": {
          "sessionId": {
            "type": "string"
          },
          "startedAt": {
            "type": "integer",
            "description": "Unix seconds."
          },
          "duration": {
            "type": "number",
            "description": "Seconds."
          },
          "endReason": {
            "type": "string",
            "description": "Protobuf enum name."
          },
          "customerData": {
            "type": "object"
          },
          "dialMetric": {
            "type": "object",
            "properties": {
              "isInbound": {
                "type": "boolean"
              }
            }
          },
          "userLog": {
            "type": "object",
            "properties": {
              "disposition": {
                "type": "string"
              },
              "notes": {
                "type": "string"
              },
              "sentiment": {
                "type": "string"
              },
              "purpose": {
                "type": "string"
              }
            }
          },
          "turnData": {
            "$ref": "#/components/schemas/TranscriptTurns"
          }
        }
      },
      "TranscriptTurns": {
        "type": "object",
        "description": "Arrays align by turn index. Offset arrays are relative to the call in seconds.",
        "properties": {
          "texts": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "isCustomers": {
            "type": "array",
            "items": {
              "type": "boolean"
            }
          },
          "starts": {
            "type": "array",
            "items": {
              "type": "number"
            }
          },
          "ends": {
            "type": "array",
            "items": {
              "type": "number"
            }
          }
        }
      },
      "CallAudioLinks": {
        "type": "object",
        "required": [
          "session",
          "audio",
          "audio_links"
        ],
        "properties": {
          "session": {
            "type": "object",
            "description": "Session metadata."
          },
          "audio": {
            "type": "array",
            "description": "Recording metadata, one object for each corresponding link.",
            "items": {
              "type": "object"
            }
          },
          "audio_links": {
            "type": "array",
            "description": "Temporary recording URLs, aligned with audio by index.",
            "items": {
              "type": "string",
              "format": "uri"
            }
          }
        }
      }
    }
  },
  "externalDocs": {
    "description": "Public Trellus Call Data API documentation",
    "url": "https://www.trellus.ai/developers/api"
  }
}
