openapi: 3.0.3
info:
  title: Dhvanee public API
  version: "1"
  description: |
    Workspace API for contacts, one outbound call, campaigns, agents, knowledge documents, automations,
    copilot, account balances, and owned phone numbers.
    Send `Authorization: Bearer dhvanee_live_…` or `X-API-Key`.
    Each key allows 60 requests per minute and each workspace allows 300 requests per minute shared across keys.
    Over a limit the response is 429 with `Retry-After` and `detail.code` of `rate_limit_key`, `rate_limit_workspace`, `rate_limit_client`, or `rate_limit_auth_fail`.
    If the rate-limit store is unavailable the response is 503 with `Retry-After: 1`.
    `POST /v1/calls`, `POST /v1/campaigns/{id}/start`, `POST /v1/automations`, and `POST /v1/automations/{id}/runs` require `Idempotency-Key`.
    When voice minutes, concurrency, outbound entitlement, knowledge storage, automation executions, or copilot credits are exhausted the response is 402.
    Connecting a CRM or storing OAuth credentials stays in the dashboard; this API does not accept connection secrets.
    This API does not buy numbers, search a shop, top up a wallet, or run checkout.

    ## Webhooks

    Create subscriptions in the dashboard under Settings → Developer Access (session auth), not with a data API key.
    Contact events: `created`, `field_change`, `merged`, `imported`, `sync`, `note`, `consent`, `task`.
    Call events: `call_started`, `call_ended`, `call_analyzed`. The payload `call_id` is the same id returned by `POST /v1/calls`.
    Deliveries are HTTPS POSTs with headers `X-Dhvanee-Event`, `X-Dhvanee-Delivery`, `X-Dhvanee-Timestamp`,
    and `X-Dhvanee-Signature` (`sha256=` + HMAC-SHA256 of `timestamp + "." + body` using the signing secret shown once at create).
    Reject deliveries when `abs(now_unix - X-Dhvanee-Timestamp) > 300` seconds, verify the signature on the raw body, and dedupe on `X-Dhvanee-Delivery`.
    Example body for `call_ended`:

    ```json
    {
      "id": "9f3c0d2e-…",
      "type": "call_ended",
      "tenant_id": "…",
      "call_id": "…",
      "created_at": "2026-11-04T12:00:00+00:00",
      "data": { "call": { "id": "…", "status": "completed", "to": "+91…", "from": "+91…", "duration": 42, "transcript": null, "agent": "…" } }
    }
    ```
servers:
  - url: https://api.stage.dhvanee.com
    description: Alpha (staging)
  - url: https://api.dhvanee.com
    description: Production (coming soon)
paths:
  /v1/contacts:
    get:
      operationId: listContacts
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: query
          name: limit
          schema: {type: integer, minimum: 1, maximum: 200, default: 50}
        - in: query
          name: offset
          schema: {type: integer, minimum: 0, default: 0}
      responses:
        "200":
          description: Contacts in this key's workspace
          content:
            application/json:
              schema: {$ref: "#/components/schemas/ContactPage"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing contacts:read"}
        "422": {description: "`limit` or `offset` is not a whole number"}
        "429": {$ref: "#/components/responses/RateLimited"}
    post:
      operationId: createContact
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: "#/components/schemas/ContactWrite"}
      responses:
        "201":
          description: Created contact
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Contact"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing contacts:write"}
        "409": {description: "That phone number is already a contact"}
        "422": {description: "Phone and email are both missing"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/contacts/{id}:
    get:
      operationId: getContact
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "200":
          description: One contact
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Contact"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing contacts:read"}
        "404": {description: "No contact with that id in this workspace"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
    patch:
      operationId: updateContact
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: "#/components/schemas/ContactWrite"}
      responses:
        "200":
          description: Updated contact
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Contact"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing contacts:write"}
        "404": {description: "No contact with that id in this workspace"}
        "409": {description: "That phone number is already a contact"}
        "422": {description: "The update would leave the contact with no phone and no email"}
        "429": {$ref: "#/components/responses/RateLimited"}
    delete:
      operationId: deleteContact
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "204": {description: "Contact deleted"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing contacts:write"}
        "404": {description: "No contact with that id in this workspace"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/calls:
    get:
      operationId: listCalls
      description: "Newest first. Lists only the calls placed through `POST /v1/calls`; calls made by a campaign, an automation or the dashboard are not listed. `limit` 1-200 (default 50), `offset` 0 or more; out of range answers 422."
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: query
          name: limit
          schema: {type: integer, minimum: 1, maximum: 200, default: 50}
        - in: query
          name: offset
          schema: {type: integer, minimum: 0, default: 0}
      responses:
        "200":
          description: "Calls this workspace placed with `POST /v1/calls`"
          content:
            application/json:
              schema: {$ref: "#/components/schemas/CallPage"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing calls:read"}
        "422": {description: "`limit must be 1-200 and offset non-negative`"}
        "429": {$ref: "#/components/responses/RateLimited"}
    post:
      operationId: createCall
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - $ref: "#/components/parameters/IdempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: "#/components/schemas/CallCreate"}
      responses:
        "201":
          description: The call that was placed. A repeat with the same key and body returns this same call.
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Call"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "402":
          description: "Plan does not allow it and nothing is started. `detail.code` is `minutes_limit_reached`, `wallet_empty`, `concurrent_limit_reached`, `outbound_disabled` or `workspace_inactive`."
          content:
            application/json:
              schema: {$ref: "#/components/schemas/PlanLimit"}
        "403": {description: "Key is missing calls:write"}
        "409": {description: "`Idempotency-Key was already used with a different request`"}
        "422": {description: "`Idempotency-Key is required`, `Idempotency-Key must be 1-128 printable ASCII characters`, `Unknown workspace agent`, `Publish the agent before placing a call`, `Use a phone number this workspace already owns`, `Give a valid phone number`, or a missing or malformed field (`agent_id`, `to` or `from` absent, an id that is not a UUID, `to` shorter than 3 or longer than 40 characters)"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/calls/{id}:
    get:
      operationId: getCall
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "200":
          description: One call
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Call"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing calls:read"}
        "404": {description: "`Call not found`: no call with that id among the calls this workspace placed with `POST /v1/calls`"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/calls/{id}/stop:
    post:
      operationId: stopCall
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "200":
          description: The call, with status stopped when it was still live
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Call"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing calls:write"}
        "404": {description: "`Call not found`: no call with that id among the calls this workspace placed with `POST /v1/calls`"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/campaigns:
    get:
      operationId: listCampaigns
      description: "Newest first, at most 100, no paging. Single calls placed with `POST /v1/calls` and the hidden campaigns of automations are not listed."
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      responses:
        "200":
          description: Campaigns in this key's workspace
          content:
            application/json:
              schema: {$ref: "#/components/schemas/CampaignPage"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing campaigns:read"}
        "429": {$ref: "#/components/responses/RateLimited"}
    post:
      operationId: createCampaign
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: "#/components/schemas/CampaignCreate"}
      responses:
        "201":
          description: Draft campaign
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Campaign"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing campaigns:write"}
        "422": {description: "`Unknown workspace agent`, `Unknown phone number for this workspace` (for `from`), `Give at least one valid phone number`, or a missing or malformed field (empty `name`, `to` empty or over 1000 entries, an id that is not a UUID)"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/campaigns/{id}:
    get:
      operationId: getCampaign
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "200":
          description: One campaign
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Campaign"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing campaigns:read"}
        "404": {description: "No campaign with that id in this workspace"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/campaigns/{id}/start:
    post:
      operationId: startCampaign
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
        - $ref: "#/components/parameters/IdempotencyKey"
      responses:
        "200":
          description: Campaign is running. A repeat with the same key does not dial again.
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Campaign"}
        "400": {description: "`Add recipients before starting`, or the dialer refused: `This campaign has no agent selected`, `Publish this agent before placing calls. Phone calls run the last published version.`, or the workspace has no phone number. The campaign stays as it was."}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "402":
          description: "Plan does not allow it and nothing is started. `detail.code` is `minutes_limit_reached`, `wallet_empty`, `concurrent_limit_reached`, `outbound_disabled` or `workspace_inactive`."
          content:
            application/json:
              schema: {$ref: "#/components/schemas/PlanLimit"}
        "403": {description: "Key is missing campaigns:write"}
        "404": {description: "`Campaign not found`"}
        "409": {description: "`Idempotency-Key was already used with a different request`"}
        "422": {description: "`Idempotency-Key is required` or `Idempotency-Key must be 1-128 printable ASCII characters`, or an id that is not a UUID"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/campaigns/{id}/pause:
    post:
      operationId: pauseCampaign
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "200":
          description: Campaign is paused
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Campaign"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing campaigns:write"}
        "404": {description: "No campaign with that id in this workspace"}
        "409": {description: "`Only a running or scheduled campaign can be paused`"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/campaigns/{id}/resume:
    post:
      operationId: resumeCampaign
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "200":
          description: Campaign is running again
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Campaign"}
        "400": {description: "The dialer refused, as for start (for example `This campaign has no agent selected`)"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "402":
          description: "Plan does not allow it and nothing is started. `detail.code` is `minutes_limit_reached`, `wallet_empty`, `concurrent_limit_reached`, `outbound_disabled` or `workspace_inactive`."
          content:
            application/json:
              schema: {$ref: "#/components/schemas/PlanLimit"}
        "403": {description: "Key is missing campaigns:write"}
        "404": {description: "No campaign with that id in this workspace"}
        "409": {description: "`Start the campaign instead of resuming it` (a draft) or `A cancelled campaign cannot be resumed`"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/campaigns/{id}/cancel:
    post:
      operationId: cancelCampaign
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "200":
          description: Campaign is cancelled
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Campaign"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing campaigns:write"}
        "404": {description: "No campaign with that id in this workspace"}
        "409": {description: "`A completed campaign cannot be cancelled`"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/agents:
    get:
      operationId: listAgents
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      responses:
        "200":
          description: Agents in this key's workspace
          content:
            application/json:
              schema: {$ref: "#/components/schemas/AgentPage"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing agents:read"}
        "429": {$ref: "#/components/responses/RateLimited"}
    post:
      operationId: createAgent
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: "#/components/schemas/AgentCreate"}
      responses:
        "201":
          description: Created agent. It is not published until publish is called.
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Agent"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing agents:write"}
        "422": {description: "A malformed body, for example a `name` longer than 128 characters"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/agents/{id}:
    get:
      operationId: getAgent
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "200":
          description: One agent
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Agent"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing agents:read"}
        "404": {description: "`Agent not found`"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
    patch:
      operationId: updateAgent
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: "#/components/schemas/AgentUpdate"}
      responses:
        "200":
          description: Updated agent
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Agent"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing agents:write"}
        "404": {description: "`Agent not found`"}
        "422": {description: "An empty `name`, a `name` longer than 128 characters, or an id that is not a UUID"}
        "429": {$ref: "#/components/responses/RateLimited"}
    delete:
      operationId: deleteAgent
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "204": {description: "Agent deleted"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing agents:write"}
        "404": {description: "`Agent not found`"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/agents/{id}/workflow:
    get:
      operationId: getAgentWorkflow
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "200":
          description: The canvas saved for this agent
          content:
            application/json:
              schema: {$ref: "#/components/schemas/AgentWorkflow"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing agents:read"}
        "404": {description: "`Agent not found`"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
    put:
      operationId: putAgentWorkflow
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: "#/components/schemas/AgentWorkflowWrite"}
      responses:
        "200":
          description: Saved canvas. Saving does not publish the agent.
          content:
            application/json:
              schema: {$ref: "#/components/schemas/AgentWorkflow"}
        "400": {description: "The canvas is not a valid workflow (`Workflow graph.nodes must be a non-empty object`, `Workflow must include start_node`, `Workflow must include at least one end node`, `Edge ... references unknown nodes`)"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing agents:write"}
        "404": {description: "`Agent not found`"}
        "422": {description: "`graph` is missing, or an id that is not a UUID"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/agents/{id}/publish:
    post:
      operationId: publishAgent
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "200":
          description: Agent is published. Live calls keep using this published version.
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Agent"}
        "400": {description: "The agent cannot be published yet. A conversational-flow agent publishes its saved canvas; `No workflow to publish — save the Agent canvas first` when none is saved"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing agents:write"}
        "404": {description: "`Agent not found`"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/agents/{id}/versions:
    get:
      operationId: listAgentVersions
      description: "Published versions, newest first. Each item holds the version number, when it went live and what was published."
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "200":
          description: Published versions, newest first
          content:
            application/json:
              schema: {$ref: "#/components/schemas/AgentVersionPage"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing agents:read"}
        "404": {description: "`Agent not found`"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/agents/{id}/versions/{version}:
    get:
      operationId: getAgentVersion
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
        - in: path
          name: version
          required: true
          schema: {type: integer, minimum: 1}
      responses:
        "200":
          description: One published version
          content:
            application/json:
              schema: {$ref: "#/components/schemas/AgentVersion"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing agents:read"}
        "404": {description: "No such version, for example `Workflow version 1 not found`, or no agent with that id"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/knowledge/documents:
    get:
      operationId: listKnowledgeDocuments
      description: "Most recently updated first. `limit` defaults to 50 and is clamped into 1-50, not rejected; a `limit` that is not a whole number answers 422. There is no paging."
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: query
          name: limit
          description: Clamped into 1-50, not rejected
          schema: {type: integer, minimum: 1, maximum: 50, default: 50}
      responses:
        "200":
          description: Knowledge documents in this key's workspace
          content:
            application/json:
              schema: {$ref: "#/components/schemas/KnowledgeDocumentPage"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing knowledge:read"}
        "422": {description: "`limit` is not a whole number"}
        "429": {$ref: "#/components/responses/RateLimited"}
    post:
      operationId: uploadKnowledgeDocument
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required: [file]
              properties:
                file: {type: string, format: binary}
                title: {type: string}
                language: {type: string, default: en}
      responses:
        "201":
          description: Uploaded document. Indexing may still be pending.
          content:
            application/json:
              schema: {$ref: "#/components/schemas/KnowledgeDocument"}
        "400": {description: "`File is empty`, `File is larger than 5 MB`, `Unsupported file type. Use .md, .txt, or .pdf`, `Could not extract text from this PDF`, or `Could not read this PDF. It may be damaged or password-protected.`"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "402":
          description: "The plan's knowledge storage would be exceeded. `detail.code` is `kb_storage_limit_reached`"
          content:
            application/json:
              schema: {$ref: "#/components/schemas/PlanLimit"}
        "403": {description: "Key is missing knowledge:write"}
        "422": {description: "`file` is missing"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/knowledge/documents/{id}:
    delete:
      operationId: deleteKnowledgeDocument
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "204": {description: "Document deleted"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing knowledge:write"}
        "404": {description: "`Document not found`"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/agents/{id}/knowledge:
    get:
      operationId: getAgentKnowledge
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "200":
          description: "Documents attached to this agent, in the order they were attached. `source_path`, `created_at` and `updated_at` are null here; use the document list for them."
          content:
            application/json:
              schema: {$ref: "#/components/schemas/KnowledgeDocumentPage"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing knowledge:read"}
        "404": {description: "`Agent not found`"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
    put:
      operationId: putAgentKnowledge
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: "#/components/schemas/AgentKnowledgeWrite"}
      responses:
        "200":
          description: "Attached document set replaced, in the order sent. An empty list detaches all documents. `source_path`, `created_at` and `updated_at` are null here."
          content:
            application/json:
              schema: {$ref: "#/components/schemas/KnowledgeDocumentPage"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing knowledge:write"}
        "404": {description: "`Agent not found`, or `One or more knowledge documents were not found in this workspace`. The agent's current set is left unchanged"}
        "422": {description: "`document_ids` is missing, or an id is not a UUID"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/automations:
    get:
      operationId: listAutomations
      description: Newest first, archived excluded. There is no paging, search, status filter or sort. A `limit` outside 1-100 is clamped, not rejected.
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: query
          name: limit
          schema: {type: integer, minimum: 1, maximum: 100, default: 50}
      responses:
        "200":
          description: Automations in this key's workspace
          content:
            application/json:
              schema: {$ref: "#/components/schemas/AutomationPage"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing automations:read"}
        "422": {description: "`limit` is not a whole number"}
        "429": {$ref: "#/components/responses/RateLimited"}
    post:
      operationId: createAutomation
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - $ref: "#/components/parameters/IdempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: "#/components/schemas/AutomationCreate"}
      responses:
        "201":
          description: Created automation draft
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Automation"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing automations:write"}
        "409": {description: "`Idempotency-Key was already used with a different request`. The same key and body within 24 hours replays the original response"}
        "422": {description: "Invalid name (1-200 characters) or graph (`Graph is not valid. path: reason`, over 50 nodes, 100 edges or 256 KiB, unknown connection), or `Idempotency-Key is required` / `Idempotency-Key must be 1-128 printable ASCII characters`"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/automations/{id}:
    get:
      operationId: getAutomation
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "200":
          description: One automation
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Automation"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing automations:read"}
        "404": {description: "`Automation not found`"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
    patch:
      operationId: updateAutomation
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: "#/components/schemas/AutomationUpdate"}
      responses:
        "200":
          description: Updated automation draft
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Automation"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing automations:write"}
        "404": {description: "`Automation not found`"}
        "409": {description: "`Archived workflows cannot be edited`, or `Workflow was modified by another request`"}
        "422": {description: "Invalid name or graph, or none of `name` and `graph` sent (`At least one field must be provided`)"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/automations/{id}/activate:
    post:
      operationId: activateAutomation
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "200":
          description: Draft published and automation enabled
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Automation"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing automations:write"}
        "404": {description: "`Automation not found`"}
        "409": {description: "`Archived workflows cannot be published`, or `Workflow draft revision is stale`"}
        "422": {description: "The graph cannot be published; the message names the first problem found (for example `Add a supported trigger.`)"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/automations/{id}/runs:
    post:
      operationId: runAutomation
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
        - $ref: "#/components/parameters/IdempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: "#/components/schemas/AutomationRunCreate"}
      responses:
        "202":
          description: Run accepted. A repeated Idempotency-Key returns the same run.
          content:
            application/json:
              schema: {$ref: "#/components/schemas/AutomationRun"}
        "400": {description: "`Idempotency-Key must be 1-128 printable ASCII characters`"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "402":
          description: "No automation executions left. `detail.code` is `automation_executions_limit_reached`, `wallet_empty` or `workspace_inactive`"
          content:
            application/json:
              schema: {$ref: "#/components/schemas/PlanLimit"}
        "403": {description: "Key is missing automations:write"}
        "404": {description: "`Automation not found`"}
        "409": {description: "`Only an active automation with a Manual trigger can be run on demand` (also when `trigger_node_id` is not a Manual trigger of the published graph), or `Idempotency-Key was already used with a different payload`"}
        "422": {description: "`This automation has more than one Manual trigger: send trigger_node_id with the node id of the one to run`, `Payload must be valid JSON`, `Payload exceeds 64 KiB`, or a missing body, a `payload` that is not an object, or an id that is not a UUID"}
        "428": {description: "`Idempotency-Key is required`"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/automations/runs/{id}:
    get:
      operationId: getAutomationRun
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "200":
          description: One automation run
          content:
            application/json:
              schema: {$ref: "#/components/schemas/AutomationRun"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing automations:read"}
        "404": {description: "`Run not found`"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/account:
    get:
      operationId: getAccount
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      responses:
        "200":
          description: Plan name and remaining balances for this key's workspace. No card data.
          content:
            application/json:
              schema: {$ref: "#/components/schemas/Account"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing account:read"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/copilot:
    post:
      operationId: createCopilotTurn
      description: "Sends the first message of a new chat and returns the chat after one turn. Unknown body keys are rejected. The public turn ignores `subject`, `snapshot`, `selection`, `attachment_ids` and `call_ids`; `domain: platform` is accepted but platform questions are not answered through the API."
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: "#/components/schemas/CopilotCreate"}
      responses:
        "201":
          description: Copilot session after the first turn. Same shape the dashboard uses.
          content:
            application/json:
              schema: {$ref: "#/components/schemas/CopilotSession"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "402":
          description: "Copilot credits are used up. `detail.code` is `copilot_credits_exhausted` or `wallet_empty`"
          content:
            application/json:
              schema: {$ref: "#/components/schemas/PlanLimit"}
        "403": {description: "Key is missing copilot:use"}
        "404": {description: "`Agent not found`: `agent_id` is not an agent of this workspace"}
        "409": {description: "`Building agents is not available right now.` (`agent_id` or `domain: agent` while building agents is switched off)"}
        "422": {description: "`text` missing, shorter than 2 or longer than 2000 characters (20,000 for agent chats), an unknown key (`Extra inputs are not permitted`), or an invalid combination of `agent_id`, `domain`, `subject`, `snapshot` or `selection`"}
        "429": {$ref: "#/components/responses/RateLimited"}
        "503": {description: "The AI model could not be reached or is not set up. `detail.code` is `assistant_unavailable`"}
  /v1/phone-numbers:
    get:
      operationId: listPhoneNumbers
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      responses:
        "200":
          description: Numbers this workspace already owns
          content:
            application/json:
              schema: {$ref: "#/components/schemas/PhoneNumberPage"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing numbers:read"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/phone-numbers/import:
    post:
      operationId: importPhoneNumber
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: "#/components/schemas/PhoneNumberImport"}
      responses:
        "201":
          description: "Imported a number the customer already owns on their carrier. `bind_message` may carry a note from the carrier set-up."
          content:
            application/json:
              schema: {$ref: "#/components/schemas/PhoneNumber"}
        "400": {description: "`Enter the number in international format, starting with + and the country code.`, `Exotel numbers must be from IN (+91).`, or the carrier refused the set-up (its reason is the message). Nothing is saved"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing numbers:write"}
        "404": {description: "`Agent not found` (unknown `workspace_agent_id`)"}
        "409": {description: "`Phone number already mapped to a workspace`"}
        "422": {description: "A missing or invalid field, for example `Twilio Account SID must look like AC followed by 32 hex characters`, `Missing required field(s): auth_token`, `Subdomain must be an Exotel API host such as api.in.exotel.com`, or a `provider` that is not `twilio` or `exotel`"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/phone-numbers/{id}/attach:
    post:
      operationId: attachPhoneNumber
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: "#/components/schemas/PhoneNumberAttach"}
      responses:
        "200":
          description: "Number pointed at the agent. `bind_message` may carry a note."
          content:
            application/json:
              schema: {$ref: "#/components/schemas/PhoneNumber"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing numbers:write"}
        "404": {description: "`Phone number not found` or `Agent not found`"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
  /v1/phone-numbers/{id}/detach:
    post:
      operationId: detachPhoneNumber
      security:
        - bearerAuth: []
        - apiKeyAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema: {type: string, format: uuid}
      responses:
        "200":
          description: "Number no longer pointed at an agent. `bind_message` may carry a note."
          content:
            application/json:
              schema: {$ref: "#/components/schemas/PhoneNumber"}
        "401": {$ref: "#/components/responses/Unauthorized"}
        "403": {description: "Key is missing numbers:write"}
        "404": {description: "`Phone number not found`"}
        "422": {$ref: "#/components/responses/ValidationError"}
        "429": {$ref: "#/components/responses/RateLimited"}
components:
  responses:
    Unauthorized:
      description: "No key (`Valid API key is required`), or an unknown or revoked key (`API key is invalid or revoked`)"
    RateLimited:
      description: "Too many requests. `detail.code` is `rate_limit_key`, `rate_limit_workspace`, `rate_limit_client` or `rate_limit_auth_fail`. Wait `Retry-After` seconds."
      headers:
        Retry-After:
          description: Seconds to wait before retrying
          schema: {type: integer}
      content:
        application/json:
          schema: {$ref: "#/components/schemas/RateLimitError"}
    ValidationError:
      description: "A malformed body, query or path value, such as an id that is not a UUID. `detail` is a list of field errors."
  parameters:
    IdempotencyKey:
      in: header
      name: Idempotency-Key
      required: true
      description: 1-128 printable ASCII characters, no spaces. A random UUID is a good key. Remembered for 24 hours.
      schema: {type: string, minLength: 1, maxLength: 128, pattern: "^[!-~]{1,128}$"}
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
    apiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
  schemas:
    RateLimitError:
      type: object
      properties:
        detail:
          type: object
          properties:
            code: {type: string, enum: [rate_limit_key, rate_limit_workspace, rate_limit_client, rate_limit_auth_fail]}
            message: {type: string, example: Too many requests}
    PlanLimit:
      type: object
      properties:
        detail:
          type: object
          properties:
            code:
              type: string
              enum: [minutes_limit_reached, wallet_empty, concurrent_limit_reached, outbound_disabled, workspace_inactive, kb_storage_limit_reached, automation_executions_limit_reached, copilot_credits_exhausted]
    Contact:
      type: object
      required: [id]
      properties:
        id: {type: string, format: uuid}
        phone: {type: string, nullable: true}
        first_name: {type: string, nullable: true}
        last_name: {type: string, nullable: true}
        email: {type: string, nullable: true}
        company: {type: string, nullable: true}
        job_title: {type: string, nullable: true}
    ContactWrite:
      type: object
      properties:
        phone: {type: string, nullable: true}
        first_name: {type: string, nullable: true}
        last_name: {type: string, nullable: true}
        email: {type: string, nullable: true}
        company: {type: string, nullable: true}
        job_title: {type: string, nullable: true}
        language: {type: string, nullable: true}
    ContactPage:
      type: object
      required: [items, limit, offset]
      properties:
        items:
          type: array
          items: {$ref: "#/components/schemas/Contact"}
        limit: {type: integer}
        offset: {type: integer}
    Call:
      type: object
      required: [id, agent, to, from, status, duration, transcript]
      properties:
        id: {type: string, format: uuid}
        agent: {type: string, format: uuid, nullable: true}
        to: {type: string}
        from: {type: string, nullable: true}
        status: {type: string, enum: [queued, in_progress, completed, stopped, no_answer, busy, failed, skipped, cancelled]}
        duration: {type: integer, nullable: true}
        transcript: {type: string, nullable: true}
    CallCreate:
      type: object
      required: [agent_id, to, from]
      properties:
        agent_id: {type: string, format: uuid}
        to: {type: string, minLength: 3, maxLength: 40, description: "Written like a phone number; turned into international format using the workspace country"}
        from: {type: string, format: uuid, description: Id of a number this workspace already owns}
    CallPage:
      type: object
      required: [items, limit, offset]
      properties:
        items:
          type: array
          items: {$ref: "#/components/schemas/Call"}
        limit: {type: integer}
        offset: {type: integer}
    Campaign:
      type: object
      required: [id, name, status, agent, from, recipients]
      properties:
        id: {type: string, format: uuid}
        name: {type: string}
        status: {type: string, enum: [draft, scheduled, running, paused, completed, cancelled]}
        agent: {type: string, format: uuid, nullable: true}
        from: {type: string, nullable: true, description: The workspace number the calls are made from. Null when none was chosen}
        recipients: {type: integer}
    CampaignCreate:
      type: object
      required: [name, agent_id, to]
      properties:
        name: {type: string, minLength: 1, maxLength: 200}
        agent_id: {type: string, format: uuid}
        to:
          type: array
          minItems: 1
          maxItems: 1000
          items: {type: string}
          description: Invalid numbers are left out without an error and duplicates are kept once; check `recipients` in the answer
        from: {type: string, format: uuid, description: Id of a number this workspace already owns. Optional}
    CampaignPage:
      type: object
      required: [items]
      properties:
        items:
          type: array
          items: {$ref: "#/components/schemas/Campaign"}
    Agent:
      type: object
      required: [id, name, language, published, workflow]
      properties:
        id: {type: string, format: uuid}
        name: {type: string}
        language: {type: string, nullable: true}
        published: {type: boolean}
        workflow:
          type: object
          nullable: true
          description: The canvas the product stores. Absent until one is saved.
    AgentCreate:
      type: object
      properties:
        name: {type: string, maxLength: 128}
    AgentUpdate:
      type: object
      required: [name]
      properties:
        name: {type: string, minLength: 1, maxLength: 128}
    AgentPage:
      type: object
      required: [items]
      properties:
        items:
          type: array
          items: {$ref: "#/components/schemas/Agent"}
    AgentWorkflow:
      type: object
      required: [workflow]
      properties:
        workflow:
          type: object
          nullable: true
    AgentWorkflowWrite:
      type: object
      required: [graph]
      properties:
        graph:
          type: object
          description: The same canvas document the dashboard saves.
    AgentVersion:
      type: object
      required: [version, published_at, workflow]
      properties:
        version: {type: integer}
        published_at: {type: string, format: date-time}
        workflow: {type: object}
    AgentVersionPage:
      type: object
      required: [items]
      properties:
        items:
          type: array
          items: {$ref: "#/components/schemas/AgentVersion"}
    KnowledgeDocument:
      type: object
      required: [id, title, language, slug]
      properties:
        id: {type: string, format: uuid}
        title: {type: string}
        language: {type: string}
        slug: {type: string}
        source_path: {type: string, nullable: true}
        created_at: {type: string, format: date-time, nullable: true}
        updated_at: {type: string, format: date-time, nullable: true}
    KnowledgeDocumentPage:
      type: object
      required: [items]
      properties:
        items:
          type: array
          items: {$ref: "#/components/schemas/KnowledgeDocument"}
    AgentKnowledgeWrite:
      type: object
      required: [document_ids]
      properties:
        document_ids:
          type: array
          items: {type: string, format: uuid}
          description: Full set of document ids to attach. Empty list detaches all.
    Automation:
      type: object
      required: [id, name, state, revision, draft_revision, graph]
      properties:
        id: {type: string, format: uuid}
        name: {type: string}
        state: {type: string, enum: [draft, active, paused, archived]}
        revision: {type: integer}
        draft_revision: {type: integer}
        active_version_id: {type: string, format: uuid, nullable: true}
        graph: {type: object}
        created_at: {type: string, format: date-time, nullable: true}
        updated_at: {type: string, format: date-time, nullable: true}
    AutomationCreate:
      type: object
      required: [name, graph]
      properties:
        name: {type: string, minLength: 1, maxLength: 200}
        graph:
          type: object
          description: >-
            Draft graph with `schema_version: 2` (at most 50 nodes, 100 edges, 256 KiB). Nodes have `id`, `type` and `config`;
            edges have `from`, `to` and `port`. Unknown keys are rejected. Publishing is stricter than saving a draft.
    AutomationUpdate:
      type: object
      minProperties: 1
      description: Send at least one of `name` and `graph` (422 `At least one field must be provided`). A `graph` replaces the whole draft.
      properties:
        name: {type: string, minLength: 1, maxLength: 200}
        graph: {type: object}
    AutomationPage:
      type: object
      required: [items]
      properties:
        items:
          type: array
          items: {$ref: "#/components/schemas/Automation"}
    AutomationRun:
      type: object
      required: [id, workflow_id, state, is_test]
      properties:
        id: {type: string, format: uuid}
        workflow_id: {type: string, format: uuid}
        version_id: {type: string, format: uuid, nullable: true}
        state:
          type: string
          enum: [waiting_event, queued, running, waiting_response, succeeded, failed, ambiguous, cancelled, skipped]
          description: Final states are succeeded, failed, ambiguous, cancelled and skipped.
        is_test: {type: boolean}
        created_at: {type: string, format: date-time, nullable: true}
        started_at: {type: string, format: date-time, nullable: true}
        finished_at: {type: string, format: date-time, nullable: true}
    AutomationRunCreate:
      type: object
      properties:
        payload:
          type: object
          description: Input passed to a Manual trigger, up to 64 KiB of JSON.
        trigger_node_id:
          type: string
          minLength: 1
          maxLength: 64
          description: Id of the Manual trigger to start. Needed only when the published graph has more than one Manual trigger.
    AccountMeter:
      type: object
      required: [limit, used, remaining]
      properties:
        limit: {type: number, nullable: true}
        used: {type: number}
        remaining: {type: number, nullable: true}
    Account:
      type: object
      required: [plan, plan_code, voice_minutes, concurrency, automation_executions, knowledge_storage_mb, copilot_credits, wallet]
      properties:
        plan: {type: string}
        plan_code: {type: string}
        voice_minutes: {$ref: "#/components/schemas/AccountMeter"}
        concurrency:
          type: object
          required: [in_use, cap]
          properties:
            in_use: {type: integer}
            cap: {type: integer, nullable: true}
        automation_executions: {$ref: "#/components/schemas/AccountMeter"}
        knowledge_storage_mb: {$ref: "#/components/schemas/AccountMeter"}
        copilot_credits:
          type: object
          required: [limit, used, remaining, extra_allowed]
          properties:
            limit: {type: number, nullable: true}
            used: {type: number}
            remaining: {type: number, nullable: true}
            extra_allowed: {type: boolean}
        wallet:
          type: object
          required: [balance, available, currency, required]
          properties:
            balance: {type: number}
            available: {type: number}
            currency: {type: string}
            required: {type: boolean}
        cycle_start: {type: string, format: date-time}
        cycle_end: {type: string, format: date-time}
    CopilotCreate:
      type: object
      required: [text]
      additionalProperties: false
      properties:
        text: {type: string, minLength: 2, maxLength: 20000, description: "2-2000 characters, up to 20,000 when the chat is about an agent (`agent_id` or `domain: agent`)"}
        domain: {type: string, enum: [agent, platform], nullable: true, description: "`agent` starts an agent-flow chat. `platform` is accepted but platform questions are not answered through the API"}
        agent_id: {type: string, format: uuid, nullable: true}
        area: {type: string, enum: [automations, agents, other], nullable: true}
        subject: {type: object, nullable: true, description: Checked but ignored by the public turn}
        snapshot: {type: object, nullable: true, description: Checked but ignored by the public turn}
        selection: {type: object, nullable: true, description: Checked but ignored by the public turn}
        attachment_ids:
          type: array
          items: {type: string, format: uuid}
          nullable: true
          description: Checked but ignored by the public turn
        call_ids:
          type: array
          items: {type: string, format: uuid}
          nullable: true
          description: Checked but ignored by the public turn
    CopilotUsage:
      type: object
      nullable: true
      description: Null on the user message. On the reply, what the turn used.
      properties:
        calls: {type: integer}
        input_tokens: {type: integer}
        cached_input_tokens: {type: integer}
        output_tokens: {type: integer}
        credits: {type: number, description: Copilot credits this turn used}
    CopilotSession:
      type: object
      required: [id, title, status, messages]
      properties:
        id: {type: string, format: uuid}
        title: {type: string, description: The start of the message, up to 80 characters}
        status: {type: string, enum: [active, opened, archived]}
        domain: {type: string, enum: [automation, agent], nullable: true, description: Null while the copilot does not know yet}
        subject: {type: object, nullable: true, description: Null through this API}
        applied_revision_seq: {type: integer, nullable: true}
        workflow_id: {type: string, format: uuid, nullable: true, description: Null through this API}
        created_at: {type: string, format: date-time, nullable: true}
        updated_at: {type: string, format: date-time, nullable: true}
        messages:
          type: array
          description: The user message first, then the copilot reply (usually one message)
          items:
            type: object
            required: [seq, role, kind, content]
            properties:
              seq: {type: integer, description: Position in the chat, from 1}
              role: {type: string, enum: [user, assistant]}
              kind: {type: string, description: "`request` for the user message; for the reply `questions`, `draft`, `brief`, `general`, `needs_detail`, `out_of_scope` or `error`"}
              content: {type: object}
              created_at: {type: string, format: date-time, nullable: true}
              usage: {$ref: "#/components/schemas/CopilotUsage"}
    PhoneNumber:
      type: object
      required: [id, phone_number, provider, byo, bound, agent_id]
      properties:
        id: {type: string, format: uuid}
        phone_number: {type: string}
        label: {type: string, nullable: true}
        provider: {type: string, enum: [twilio, exotel]}
        byo: {type: boolean}
        bound: {type: boolean}
        agent_id: {type: string, format: uuid, nullable: true}
        created_at: {type: string, format: date-time, nullable: true}
        bind_message: {type: string, nullable: true, description: A note from the carrier set-up. Only in the import, attach and detach responses}
    PhoneNumberPage:
      type: object
      required: [items]
      properties:
        items:
          type: array
          items: {$ref: "#/components/schemas/PhoneNumber"}
    PhoneNumberAttach:
      type: object
      required: [agent_id]
      properties:
        agent_id: {type: string, format: uuid}
    PhoneNumberImport:
      type: object
      required: [provider, phone_number, account_sid]
      properties:
        provider: {type: string, enum: [twilio, exotel]}
        phone_number: {type: string}
        label: {type: string, nullable: true}
        workspace_agent_id: {type: string, format: uuid, nullable: true}
        account_sid: {type: string}
        auth_token: {type: string, nullable: true}
        api_key: {type: string, nullable: true}
        api_token: {type: string, nullable: true}
        subdomain: {type: string, nullable: true}
        app_id: {type: string, nullable: true}
    WebhookEvent:
      type: object
      description: |
        Body posted to a workspace webhook URL. Subscribe via the dashboard Developer Access page.
        Verify `X-Dhvanee-Signature` as `sha256=` + HMAC-SHA256 hex of `X-Dhvanee-Timestamp + "." + raw_body`.
      required: [id, type, tenant_id, created_at, data]
      properties:
        id: {type: string, format: uuid}
        type:
          type: string
          enum: [created, field_change, merged, imported, sync, note, consent, task, call_started, call_ended, call_analyzed]
        tenant_id: {type: string, format: uuid}
        contact_id: {type: string, format: uuid, nullable: true, description: Present on contact events}
        call_id:
          type: string
          format: uuid
          nullable: true
          description: Present on call events; same id as GET /v1/calls/{id}
        created_at: {type: string, format: date-time}
        data: {type: object}
