openapi: 3.1.0
info:
  title: PapaCall API
  version: 1.0.0
  summary: Create paid PapaCall links for third-party services.
  description: |
    PapaCall API creates call links from an API balance. Billing happens once, when a link is successfully created.
    Participant joins, participant count, and call duration do not create additional API charges.
    PapaCall Pro is required to create new API keys and to add API balance. Existing API keys remain usable if Pro later becomes inactive, until the API balance is insufficient.
  contact:
    email: contact@papacall.me
externalDocs:
  description: PapaCall API documentation
  url: https://papacall.com/api
servers:
  - url: https://api.papacall.me/v1
    description: Production
security:
  - bearerApiKey: []
  - apiKeyHeader: []
tags:
  - name: Calls
  - name: Account
paths:
  /calls:
    post:
      tags: [Calls]
      operationId: createCall
      summary: Create a PapaCall link
      description: |
        Creates one call link and deducts its calculated price from the shared API balance.
        Use `Idempotency-Key` to safely retry a request without creating or charging for a second link.
      parameters:
        - in: header
          name: Idempotency-Key
          required: false
          schema:
            type: string
            maxLength: 128
          description: Unique key for safe retries. Recommended for every create request.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateCallRequest'
            examples:
              videoTranslate:
                summary: Video + LiveTranslate
                value:
                  type: video
                  callMode: group
                  features:
                    liveTranslate: true
                  AfterCallPage: https://api.ppcall.me/api/after-call
              voiceMaskAtStart:
                summary: Audio + VoiceMask enabled at start
                value:
                  type: audio
                  callMode: 1x1
                  features:
                    voiceMask: true
                  voiceMaskEnabledAtStart: true
      responses:
        '201':
          description: Link created and charged.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateCallResponse'
        '200':
          description: Idempotent replay of an already successful request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateCallResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/InvalidApiKey'
        '402':
          description: API balance is insufficient for the requested configuration.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: API_INSUFFICIENT_BALANCE
                details:
                  balanceCents: 10
                  requiredCents: 28
        '429':
          $ref: '#/components/responses/RateLimited'
  /balance:
    get:
      tags: [Account]
      operationId: getBalance
      summary: Get API balance
      responses:
        '200':
          description: Current shared API balance.
          content:
            application/json:
              schema:
                type: object
                required: [ok, balanceCents, balanceUsd, currency]
                properties:
                  ok: { type: boolean, const: true }
                  balanceCents: { type: integer, minimum: 0, example: 10000 }
                  balanceUsd: { type: number, example: 100 }
                  currency: { type: string, const: USD }
        '401':
          $ref: '#/components/responses/InvalidApiKey'
        '429':
          $ref: '#/components/responses/RateLimited'
  /usage:
    get:
      tags: [Account]
      operationId: getKeyUsage
      summary: Get usage for the current API key
      responses:
        '200':
          description: Per-key usage counters.
          content:
            application/json:
              schema:
                type: object
                required: [ok, callCount, spentCents, spentUsd]
                properties:
                  ok: { type: boolean, const: true }
                  callCount: { type: integer, minimum: 0 }
                  spentCents: { type: integer, minimum: 0 }
                  spentUsd: { type: number, minimum: 0 }
                  lastUsedAt: { type: [string, 'null'], format: date-time }
                  createdAt: { type: [string, 'null'], format: date-time }
        '401':
          $ref: '#/components/responses/InvalidApiKey'
        '429':
          $ref: '#/components/responses/RateLimited'
components:
  securitySchemes:
    bearerApiKey:
      type: http
      scheme: bearer
      bearerFormat: PapaCall API key
      description: 'Authorization: Bearer pc_live_...'
    apiKeyHeader:
      type: apiKey
      in: header
      name: X-API-Key
      description: Alternative to Bearer authorization.
  responses:
    BadRequest:
      description: Invalid request parameters.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    InvalidApiKey:
      description: API key is invalid or has been revoked.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            invalid:
              value: { error: API_KEY_INVALID }
            revoked:
              value: { error: API_KEY_REVOKED }
    ProRequired:
      description: PapaCall Pro is required for account-level API management actions such as creating keys or adding funds.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error: API_PRO_REQUIRED
            details:
              requiredPlan: Pro
    RateLimited:
      description: Too many requests for this API key.
      headers:
        Retry-After:
          schema: { type: integer }
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  schemas:
    CreateCallRequest:
      type: object
      additionalProperties: false
      required: [type]
      properties:
        type:
          type: string
          enum: [audio, video]
          description: Audio is $0.04. Video is $0.06 and allows camera video.
        callMode:
          type: string
          enum: [1x1, group]
          default: group
          description: Creates either a private 1-to-1 room (capacity 2) or a group room (capacity 10).
        AfterCallPage:
          type: [string, 'null']
          format: uri
          maxLength: 2048
          description: Optional absolute http(s) URL opened after an API call ends. If omitted, PapaCall opens its built-in responsive after-call page.
        features:
          type: object
          additionalProperties: false
          properties:
            voiceMask:
              type: boolean
              default: false
              description: Adds VoiceMask (+$0.03).
            faceLight:
              type: boolean
              default: false
              description: Adds FaceLight (+$0.01).
            liveTranslate:
              type: boolean
              default: false
              description: Adds LiveTranslate (+$0.22).
            meetingReport:
              type: boolean
              default: false
              description: Adds Meeting Report (+$0.10).
            chat:
              type: boolean
              default: false
              description: Adds one-time in-call chat (+$0.04).
        voiceMaskEnabledAtStart:
          type: boolean
          default: false
          description: Starts with VoiceMask enabled. Requires features.voiceMask=true.
    CallFeatures:
      type: object
      required: [voiceMask, faceLight, liveTranslate, meetingReport, chat]
      properties:
        voiceMask: { type: boolean }
        faceLight: { type: boolean }
        liveTranslate: { type: boolean }
        meetingReport: { type: boolean }
        chat: { type: boolean }
    Call:
      type: object
      required: [id, roomCode, url, type, callMode, status, priceCents, priceUsd, createdAt, joinBy, expiresAt, features, voiceMaskEnabledAtStart, AfterCallPage]
      properties:
        id: { type: string, format: uuid }
        roomCode: { type: string }
        url: { type: string, format: uri }
        type: { type: string, enum: [audio, video] }
        callMode: { type: string, enum: [1x1, group] }
        status: { type: string, enum: [active, expired, completed] }
        priceCents: { type: integer, minimum: 0 }
        priceUsd: { type: number, minimum: 0 }
        createdAt: { type: string, format: date-time }
        joinBy:
          type: [string, 'null']
          format: date-time
          description: First participant must join by this time; otherwise the link expires.
        expiresAt:
          type: string
          format: date-time
          description: Absolute maximum lifetime for the call link.
        firstJoinedAt: { type: [string, 'null'], format: date-time }
        features:
          $ref: '#/components/schemas/CallFeatures'
        voiceMaskEnabledAtStart: { type: boolean }
        AfterCallPage:
          type: [string, 'null']
          format: uri
          description: Custom after-call URL supplied when the call was created, or null when the built-in PapaCall after-call page is used.
    Balance:
      type: object
      required: [balanceCents, balanceUsd, currency]
      properties:
        balanceCents: { type: integer, minimum: 0 }
        balanceUsd: { type: number, minimum: 0 }
        currency: { type: string, const: USD }
    CreateCallResponse:
      type: object
      required: [ok, idempotentReplay, call]
      properties:
        ok: { type: boolean, const: true }
        idempotentReplay: { type: boolean }
        call:
          $ref: '#/components/schemas/Call'
        balance:
          anyOf:
            - $ref: '#/components/schemas/Balance'
            - type: 'null'
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error: { type: string }
        details:
          type: object
          additionalProperties: true
x-papacall-pricing:
  currency: USD
  billingUnit: successful_link_creation
  base:
    audio: 0.04
    video: 0.06
  addOns:
    voiceMask: 0.03
    faceLight: 0.01
    liveTranslate: 0.22
    meetingReport: 0.10
    chat: 0.04
x-papacall-lifecycle:
  beforeFirstJoinMinutes: 15
  emptyAfterJoinMinutes: 10
  maximumCallHours: 12
