openapi: 3.1.0
info:
  title: ScaliQ Public API
  version: '1.0.0'
  description: |
    ScaliQ Public API v1. Reference docs are the primary source for humans and agents.
    Import this file into Postman/Insomnia if you want a generated collection.
    Authenticate with header X-API-Key (sk_live_).
  contact:
    name: ScaliQ
    url: https://app.scaliq.ai/api-mcp
servers:
  - url: https://api.scaliq.ai/public/v1
    description: Production
security:
  - ApiKeyAuth: []
tags:
  - name: Credits
  - name: Setup
  - name: Accounts
  - name: Activity
  - name: Insights
  - name: Tags
  - name: Templates
  - name: Campaigns
  - name: Leads
  - name: Inbox
  - name: LinkedIn
paths:
  /credits:
    get:
      tags: [Credits]
      summary: Get credits
      operationId: getCredits
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Credits'
        default:
          $ref: '#/components/responses/Error'
  /setup:
    get:
      tags: [Setup]
      summary: Workspace readiness snapshot
      operationId: getSetupStatus
      description: |
        Account / template / campaign counts plus credits for MCP one-prompt onboarding.
        If accounts.hasConnectedAccount is false, the agent should send the user to /accounts and stop.
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SetupStatus'
        default:
          $ref: '#/components/responses/Error'
  /accounts:
    get:
      tags: [Accounts]
      summary: List LinkedIn accounts
      operationId: getAccounts
      parameters:
        - name: limit
          in: query
          schema: { type: integer, minimum: 1, maximum: 100, default: 50 }
        - name: cursor
          in: query
          schema: { type: string, nullable: true }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                required: [accounts, nextCursor]
                properties:
                  accounts:
                    type: array
                    items:
                      $ref: '#/components/schemas/Account'
                  nextCursor:
                    type: string
                    nullable: true
        default:
          $ref: '#/components/responses/Error'
  /accounts/connect-link:
    post:
      tags: [Accounts]
      summary: Mint LinkedIn connect URL
      operationId: postAccountConnectLink
      responses:
        '200':
          description: connectUrl + expiresAt
        default:
          $ref: '#/components/responses/Error'
  /accounts/{accountId}/disconnect-for-reconnect:
    post:
      tags: [Accounts]
      summary: Soft-disconnect for reconnect
      operationId: postAccountDisconnectForReconnect
      parameters:
        - name: accountId
          in: path
          required: true
          schema: { type: string }
      responses:
        '200':
          description: Account marked disconnected
        default:
          $ref: '#/components/responses/Error'
  /accounts/{accountId}/reconnect-link:
    post:
      tags: [Accounts]
      summary: Mint LinkedIn reconnect URL
      operationId: postAccountReconnectLink
      parameters:
        - name: accountId
          in: path
          required: true
          schema: { type: string }
      responses:
        '200':
          description: connectUrl + expiresAt
        default:
          $ref: '#/components/responses/Error'
  /accounts/{accountId}:
    delete:
      tags: [Accounts]
      summary: Delete LinkedIn account
      operationId: deleteAccount
      parameters:
        - name: accountId
          in: path
          required: true
          schema: { type: string }
      responses:
        '200':
          description: Deleted
        default:
          $ref: '#/components/responses/Error'
  /accounts/{accountId}/limits:
    patch:
      tags: [Accounts]
      summary: Update daily connection / message limits
      operationId: patchAccountLimits
      parameters:
        - name: accountId
          in: path
          required: true
          schema: { type: string }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                connectionRequestLimit:
                  type: integer
                  minimum: 0
                  maximum: 30
                messageLimit:
                  type: integer
                  minimum: 0
                  maximum: 30
      responses:
        '200':
          description: Updated account
        default:
          $ref: '#/components/responses/Error'
  /activity:
    get:
      tags: [Activity]
      summary: List recent activity events
      operationId: getActivity
      parameters:
        - name: type
          in: query
          schema:
            type: string
            enum:
              - connection_request_sent
              - connection_accepted
              - message_sent
              - reply_received
              - agent_replied
              - cta_sent
              - agent_handed_off
        - name: limit
          in: query
          schema: { type: integer, minimum: 1, maximum: 100, default: 50 }
        - name: cursor
          in: query
          schema: { type: string, nullable: true }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                required: [events, nextCursor]
                properties:
                  events:
                    type: array
                    items:
                      $ref: '#/components/schemas/ActivityEvent'
                  nextCursor:
                    type: string
                    nullable: true
        default:
          $ref: '#/components/responses/Error'
  /insights/overview:
    get:
      tags: [Insights]
      summary: Workspace insights overview (sampled)
      operationId: getInsightsOverview
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InsightsOverview'
        default:
          $ref: '#/components/responses/Error'
  /tags:
    get:
      tags: [Tags]
      summary: List reply tags
      operationId: getTags
      responses:
        '200':
          description: Built-ins then active customs
        default:
          $ref: '#/components/responses/Error'
    post:
      tags: [Tags]
      summary: Create custom reply tag
      operationId: postCreateTag
      parameters:
        - name: Idempotency-Key
          in: header
          required: false
          schema: { type: string, maxLength: 128 }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [label, description, color]
              additionalProperties: false
              properties:
                label: { type: string }
                description: { type: string, minLength: 20, maxLength: 280 }
                color:
                  type: string
                  enum: [gray, teal, pink, indigo, lime, orange]
      responses:
        '201':
          description: Created
        default:
          $ref: '#/components/responses/Error'
  /tags/{labelKey}:
    patch:
      tags: [Tags]
      summary: Update custom reply tag
      operationId: patchTag
      parameters:
        - name: labelKey
          in: path
          required: true
          schema: { type: string }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [description, color]
              additionalProperties: false
              properties:
                description: { type: string, minLength: 20, maxLength: 280 }
                color:
                  type: string
                  enum: [gray, teal, pink, indigo, lime, orange]
      responses:
        '200':
          description: Updated
        default:
          $ref: '#/components/responses/Error'
  /templates:
    get:
      tags: [Templates]
      summary: List agents / templates
      operationId: getTemplates
      parameters:
        - name: limit
          in: query
          schema: { type: integer, minimum: 1, maximum: 100, default: 50 }
        - name: cursor
          in: query
          schema: { type: string, nullable: true }
      responses:
        '200':
          description: OK
        default:
          $ref: '#/components/responses/Error'
    post:
      tags: [Templates]
      summary: Create manual agent / template
      operationId: postCreateTemplate
      parameters:
        - name: Idempotency-Key
          in: header
          required: false
          schema: { type: string, maxLength: 128 }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name, prompt, yourPitch, sendWhen, selectedAccounts]
              properties:
                name: { type: string }
                prompt: { type: string }
                yourPitch: { type: string }
                messageType: { type: string, enum: [static, ai] }
                sendWhen:
                  type: object
                  required: [timezone, days, timeRange]
                  properties:
                    timezone: { type: string }
                    days:
                      type: array
                      items:
                        type: string
                        enum: [monday, tuesday, wednesday, thursday, friday, saturday, sunday]
                    timeRange:
                      type: object
                      properties:
                        start: { type: string }
                        end: { type: string }
                selectedAccounts:
                  type: array
                  items: { type: string }
                  minItems: 1
                outboundSendMode: { type: string, enum: [auto, review] }
                skipExistingFirstDegree: { type: boolean }
                agentCanReply: { type: boolean }
                followUps: { type: array, maxItems: 10 }
                connectionInviteNoteEnabled: { type: boolean }
                connectionInviteNoteMode: { type: string, enum: [static, ai] }
                connectionInviteNote: { type: string }
      responses:
        '201':
          description: Created
        default:
          $ref: '#/components/responses/Error'
  /templates/{templateId}:
    get:
      tags: [Templates]
      summary: Get agent / template
      operationId: getTemplate
      parameters:
        - name: templateId
          in: path
          required: true
          schema: { type: string }
      responses:
        '200':
          description: OK
        default:
          $ref: '#/components/responses/Error'
    patch:
      tags: [Templates]
      summary: Update manual agent (echo-all)
      operationId: patchTemplate
      parameters:
        - name: templateId
          in: path
          required: true
          schema: { type: string }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - prompt
                - yourPitch
                - messageType
                - sendWhen
                - selectedAccounts
                - outboundSendMode
                - skipExistingFirstDegree
                - agentCanReply
                - followUps
                - connectionInviteNoteEnabled
                - connectionInviteNoteMode
                - connectionInviteNote
              properties:
                name: { type: string }
                prompt: { type: string }
                yourPitch: { type: string }
                messageType: { type: string, enum: [static, ai] }
                sendWhen:
                  type: object
                  required: [timezone, days, timeRange]
                  properties:
                    timezone: { type: string }
                    days:
                      type: array
                      items:
                        type: string
                        enum: [monday, tuesday, wednesday, thursday, friday, saturday, sunday]
                    timeRange:
                      type: object
                      properties:
                        start: { type: string }
                        end: { type: string }
                selectedAccounts:
                  type: array
                  items: { type: string }
                  minItems: 1
                outboundSendMode: { type: string, enum: [auto, review] }
                skipExistingFirstDegree: { type: boolean }
                agentCanReply: { type: boolean }
                followUps: { type: array, maxItems: 10 }
                connectionInviteNoteEnabled: { type: boolean }
                connectionInviteNoteMode:
                  oneOf:
                    - { type: string, enum: [static, ai] }
                    - { type: 'null' }
                connectionInviteNote: { type: string }
      responses:
        '200':
          description: Updated
        default:
          $ref: '#/components/responses/Error'
    delete:
      tags: [Templates]
      summary: Delete agent / template
      operationId: deleteTemplate
      parameters:
        - name: templateId
          in: path
          required: true
          schema: { type: string }
      responses:
        '200':
          description: Deleted
        default:
          $ref: '#/components/responses/Error'
  /campaigns:
    get:
      tags: [Campaigns]
      summary: List campaigns
      operationId: getCampaigns
      parameters:
        - name: status
          in: query
          schema: { type: string }
        - name: limit
          in: query
          schema: { type: integer, minimum: 1, maximum: 100, default: 50 }
        - name: cursor
          in: query
          schema: { type: string, nullable: true }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                required: [campaigns, nextCursor]
                properties:
                  campaigns:
                    type: array
                    items:
                      $ref: '#/components/schemas/Campaign'
                  nextCursor:
                    type: string
                    nullable: true
        default:
          $ref: '#/components/responses/Error'
    post:
      tags: [Campaigns]
      summary: Create empty manual campaign
      operationId: postCreateCampaign
      parameters:
        - name: Idempotency-Key
          in: header
          required: false
          schema: { type: string, maxLength: 128 }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name]
              additionalProperties: false
              properties:
                name: { type: string, maxLength: 80 }
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Campaign'
        default:
          $ref: '#/components/responses/Error'
  /campaigns/lookalike:
    post:
      tags: [Campaigns]
      summary: Create or extend Lookalike campaign
      operationId: postLookalikeCampaign
      parameters:
        - name: Idempotency-Key
          in: header
          required: false
          schema: { type: string, maxLength: 128 }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [seed]
              additionalProperties: false
              properties:
                seed:
                  type: string
                  description: LinkedIn profile URL or identifier (website/domain not accepted)
                numberOfLeads:
                  type: integer
                  minimum: 1
                  maximum: 10000
                  default: 50
                  description: >
                    Ocean default 50 / hard cap 10000. AgentEnrich deploy hard cap 25
                    (requests above the active provider cap return validation_error).
                campaignId:
                  type: string
                  description: Existing campaign id to extend
                jobTitleKeywords:
                  description: >
                    Ocean only — optional include job titles (partial match). String or string array
                    (max 15 phrases × 80 chars). Omit/empty for broad lookalike.
                    AgentEnrich rejects non-empty values with validation_error.
                  oneOf:
                    - type: string
                    - type: array
                      items: { type: string, minLength: 1, maxLength: 80 }
                      maxItems: 15
                countries:
                  type: array
                  maxItems: 25
                  items: { type: string, minLength: 2, maxLength: 2 }
                  description: >
                    Ocean only — person countries (ISO 3166-1 alpha-2, lowercase preferred).
                    Omit for worldwide. AgentEnrich rejects non-empty values with validation_error.
                leadDuplicateProtectionAcrossCampaigns:
                  type: boolean
                  default: true
      responses:
        '200':
          description: Queued
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LookalikeCampaignResponse'
        '202':
          description: Extend enqueue ambiguous — check campaign progress
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LookalikeCampaignResponse'
        default:
          $ref: '#/components/responses/Error'
  /campaigns/{campaignId}:
    get:
      tags: [Campaigns]
      summary: Get campaign
      operationId: getCampaign
      parameters:
        - $ref: '#/components/parameters/campaignId'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Campaign'
        default:
          $ref: '#/components/responses/Error'
    patch:
      tags: [Campaigns]
      summary: Rename campaign
      operationId: patchCampaign
      parameters:
        - $ref: '#/components/parameters/campaignId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name]
              additionalProperties: false
              properties:
                name: { type: string, maxLength: 80 }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Campaign'
        default:
          $ref: '#/components/responses/Error'
    delete:
      tags: [Campaigns]
      summary: Delete campaign
      operationId: deleteCampaign
      parameters:
        - $ref: '#/components/parameters/campaignId'
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                required: [id, deletedLeads, creditsRefunded]
                properties:
                  id: { type: string }
                  deletedLeads: { type: integer }
                  creditsRefunded: { type: integer, const: 0 }
        default:
          $ref: '#/components/responses/Error'
  /campaigns/{campaignId}/template:
    post:
      tags: [Campaigns]
      summary: Assign or clear agent on campaign
      operationId: postAssignTemplate
      parameters:
        - $ref: '#/components/parameters/campaignId'
        - name: Idempotency-Key
          in: header
          required: false
          schema: { type: string, maxLength: 128 }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [templateId]
              additionalProperties: false
              properties:
                templateId:
                  oneOf:
                    - type: string
                      minLength: 1
                    - type: 'null'
      responses:
        '200':
          description: Assigned or cleared
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Campaign'
        default:
          $ref: '#/components/responses/Error'
  /campaigns/{campaignId}/start:
    post:
      tags: [Campaigns]
      summary: Start or resume campaign
      operationId: startCampaign
      parameters:
        - $ref: '#/components/parameters/campaignId'
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
      responses:
        '200':
          description: started | resumed | noop
          content:
            application/json:
              schema:
                type: object
                required: [campaignId, action, status, campaign]
                properties:
                  campaignId: { type: string }
                  action:
                    type: string
                    enum: [started, resumed, noop]
                  status: { type: string }
                  campaign:
                    $ref: '#/components/schemas/Campaign'
        default:
          $ref: '#/components/responses/Error'
  /campaigns/{campaignId}/pause:
    post:
      tags: [Campaigns]
      summary: Pause campaign
      operationId: pauseCampaign
      parameters:
        - $ref: '#/components/parameters/campaignId'
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
      responses:
        '200':
          description: paused | noop
          content:
            application/json:
              schema:
                type: object
                required: [campaignId, action, status, campaign]
                properties:
                  campaignId: { type: string }
                  action:
                    type: string
                    enum: [paused, noop]
                  status: { type: string }
                  campaign:
                    $ref: '#/components/schemas/Campaign'
        default:
          $ref: '#/components/responses/Error'
  /campaigns/{campaignId}/leads:
    get:
      tags: [Leads]
      summary: List leads
      operationId: getLeads
      parameters:
        - $ref: '#/components/parameters/campaignId'
        - name: tag
          in: query
          schema:
            $ref: '#/components/schemas/LeadTag'
        - name: replied
          in: query
          schema: { type: boolean }
        - name: needsReply
          in: query
          schema: { type: boolean }
        - name: excluded
          in: query
          description: Filter to excluded leads. Only `true` is allowed.
          schema:
            type: boolean
            enum: [true]
        - name: sort
          in: query
          schema:
            type: string
            enum: [createdAt, lastInboundMessageAt, repliedAt, taggedAt]
            default: createdAt
        - name: limit
          in: query
          schema: { type: integer, minimum: 1, maximum: 100, default: 50 }
        - name: cursor
          in: query
          schema: { type: string, nullable: true }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                required: [leads, nextCursor]
                properties:
                  leads:
                    type: array
                    items:
                      $ref: '#/components/schemas/LeadListItem'
                  nextCursor:
                    type: string
                    nullable: true
        default:
          $ref: '#/components/responses/Error'
    post:
      tags: [Leads]
      summary: Add lead
      operationId: addLead
      parameters:
        - $ref: '#/components/parameters/campaignId'
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AddLeadBody'
      responses:
        '200':
          description: created | duplicate | excluded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AddLeadResponse'
        default:
          $ref: '#/components/responses/Error'
  /campaigns/{campaignId}/leads/batch:
    post:
      tags: [Leads]
      summary: Add leads (batch)
      operationId: addLeadsBatch
      parameters:
        - $ref: '#/components/parameters/campaignId'
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AddLeadsBatchBody'
      responses:
        '200':
          description: Per-item results (created | duplicate | excluded | validation_error | insufficient_credits | failed)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AddLeadsBatchResponse'
        default:
          $ref: '#/components/responses/Error'
  /campaigns/{campaignId}/leads/batch-update:
    post:
      tags: [Leads]
      summary: Update leads (batch tag/exclude/CRM fields)
      operationId: updateLeadsBatch
      parameters:
        - $ref: '#/components/parameters/campaignId'
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [updates]
              additionalProperties: false
              properties:
                updates:
                  type: array
                  minItems: 1
                  maxItems: 100
                  items:
                    $ref: '#/components/schemas/BatchUpdateLeadItem'
      responses:
        '200':
          description: Per-item results (updated | not_found | validation_error | failed)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UpdateLeadsBatchResponse'
        default:
          $ref: '#/components/responses/Error'
  /campaigns/{campaignId}/leads/batch-delete:
    post:
      tags: [Leads]
      summary: Delete leads (batch)
      operationId: deleteLeadsBatch
      parameters:
        - $ref: '#/components/parameters/campaignId'
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [leadIds]
              additionalProperties: false
              properties:
                leadIds:
                  type: array
                  minItems: 1
                  maxItems: 100
                  items: { type: string }
      responses:
        '200':
          description: Per-item results (deleted | not_found | validation_error | failed)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DeleteLeadsBatchResponse'
        '409':
          description: Campaign lead ingestion still in progress
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorBody'
        default:
          $ref: '#/components/responses/Error'
  /campaigns/{campaignId}/leads/{leadId}/preview:
    post:
      tags: [Leads]
      summary: Preview static invite note and first message
      operationId: postPreviewLead
      parameters:
        - $ref: '#/components/parameters/campaignId'
        - $ref: '#/components/parameters/leadId'
      responses:
        '200':
          description: Static dry-run (AI / Full Auto returns rendered null)
        default:
          $ref: '#/components/responses/Error'
  /campaigns/{campaignId}/leads/{leadId}:
    get:
      tags: [Leads]
      summary: Get lead
      operationId: getLead
      parameters:
        - $ref: '#/components/parameters/campaignId'
        - $ref: '#/components/parameters/leadId'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LeadDetail'
        default:
          $ref: '#/components/responses/Error'
    patch:
      tags: [Leads]
      summary: Update lead tag, excluded, or CRM/profile fields
      operationId: patchLead
      parameters:
        - $ref: '#/components/parameters/campaignId'
        - $ref: '#/components/parameters/leadId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PatchLeadBody'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PatchLeadResponse'
        default:
          $ref: '#/components/responses/Error'
    delete:
      tags: [Leads]
      summary: Delete one lead
      operationId: deleteLead
      parameters:
        - $ref: '#/components/parameters/campaignId'
        - $ref: '#/components/parameters/leadId'
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                required: [id, deleted, creditsRefunded]
                properties:
                  id: { type: string }
                  deleted: { type: boolean, const: true }
                  creditsRefunded: { type: integer, const: 0 }
                  reconciliationFailed: { type: boolean }
        default:
          $ref: '#/components/responses/Error'
  /inbox/messages:
    post:
      tags: [Inbox]
      summary: Send LinkedIn message
      operationId: sendMessage
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SendMessageBody'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok: { type: boolean }
                  chatId: { type: string }
                  messageId: { type: string }
        default:
          $ref: '#/components/responses/Error'
  /linkedin/profiles/lookup:
    post:
      tags: [LinkedIn]
      summary: Lookup profile by URL
      operationId: lookupProfile
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LookupBody'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProfileLookup'
        default:
          $ref: '#/components/responses/Error'
  /linkedin/search:
    post:
      tags: [LinkedIn]
      summary: Search LinkedIn people (one page)
      operationId: searchLinkedIn
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SearchBody'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                required: [results, cursor]
                properties:
                  results:
                    type: array
                    items:
                      $ref: '#/components/schemas/SearchResult'
                  cursor:
                    type: string
                    nullable: true
        default:
          $ref: '#/components/responses/Error'
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
  parameters:
    campaignId:
      name: campaignId
      in: path
      required: true
      schema: { type: string }
    leadId:
      name: leadId
      in: path
      required: true
      schema: { type: string }
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      schema: { type: string, maxLength: 128 }
  responses:
    Error:
      description: Error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBody'
  schemas:
    ErrorBody:
      type: object
      required: [error]
      properties:
        error:
          type: object
          required: [code, message, details]
          properties:
            code:
              type: string
              enum:
                - unauthorized
                - plan_required
                - validation_error
                - not_found
                - conflict
                - insufficient_credits
                - insufficient_lookalike_credits
                - lookalike_exhausted
                - alternate_seed_requires_new_campaign
                - lookalike_provider_mismatch
                - account_disconnected
                - sales_nav_required
                - rate_limited
                - linkedin_daily_quota
                - send_failed
                - upstream_unavailable
            message: { type: string }
            details:
              type: object
              additionalProperties: true
    Credits:
      type: object
      required: [credits, topUpCredits, lookalikeCredits, lookalikeTopUpCredits, planId]
      properties:
        credits: { type: number }
        topUpCredits: { type: number }
        lookalikeCredits: { type: number }
        lookalikeTopUpCredits: { type: number }
        planId: { type: string }
    SetupStatus:
      type: object
      required: [accounts, templates, campaigns, credits]
      properties:
        accounts:
          type: object
          required: [total, connected, hasConnectedAccount]
          properties:
            total: { type: integer }
            connected: { type: integer }
            hasConnectedAccount: { type: boolean }
        templates:
          type: object
          required: [total]
          properties:
            total: { type: integer }
        campaigns:
          type: object
          required: [total, byStatus]
          properties:
            total: { type: integer }
            byStatus:
              type: object
              required:
                - READY_TO_SEND
                - CAMPAIGN_IN_PROGRESS
                - CAMPAIGN_PAUSED
                - FAILED
                - DONE
                - COMPLETED
                - other
              properties:
                READY_TO_SEND: { type: integer }
                CAMPAIGN_IN_PROGRESS: { type: integer }
                CAMPAIGN_PAUSED: { type: integer }
                FAILED: { type: integer }
                DONE: { type: integer }
                COMPLETED: { type: integer }
                other: { type: integer }
        credits:
          $ref: '#/components/schemas/Credits'
    LookalikeCampaignResponse:
      type: object
      required:
        - campaignId
        - status
        - extended
        - extensionBatchId
        - requestedLeadTarget
        - lookalikeReserved
        - resume
        - message
      properties:
        campaignId: { type: string }
        status: { type: string }
        extended: { type: boolean }
        extensionBatchId: { type: string, nullable: true }
        requestedLeadTarget: { type: integer }
        lookalikeReserved: { type: integer }
        resume:
          type: string
          nullable: true
          enum: [fresh, continue]
        message: { type: string }
    AccountToday:
      type: object
      properties:
        connectionRequestsSent: { type: integer }
        connectionRequestsAccepted: { type: integer }
        connectionRequestLimit: { type: integer }
        messagesSent: { type: integer }
        messageLimit: { type: integer }
    Account:
      type: object
      properties:
        id: { type: string }
        name: { type: string }
        status:
          type: string
          enum: [connected, connecting, failed, disconnected]
        active: { type: boolean }
        hasSalesNavigator:
          type: boolean
          description: True only when a Sales Navigator contract id is stored. LinkedIn Premium alone is false.
        today:
          $ref: '#/components/schemas/AccountToday'
    CampaignStats:
      type: object
      properties:
        connectionRequestsSent: { type: integer }
        connectionRequestsAccepted: { type: integer }
        acceptanceRate: { type: number, nullable: true }
        messagesSent:
          type: integer
          description: Leads messaged (first outbound message per lead), not follow-ups.
        repliesReceived: { type: integer }
        replyRate:
          type: number
          nullable: true
          description: repliesReceived / messagesSent (leads messaged), one decimal; null when no leads messaged.
    Campaign:
      type: object
      properties:
        id: { type: string }
        name: { type: string }
        status: { type: string }
        totalLeads: { type: integer }
        assignedTemplateId: { type: string, nullable: true }
        stats:
          $ref: '#/components/schemas/CampaignStats'
    LeadTag:
      type: string
      maxLength: 40
      description: Built-in label (exact case) or a workspace custom reply tag. Side effects (exclude, stop outreach, Meetings) apply only to the six built-in labels.
    LeadStage:
      type: string
      description: >
        Pipeline stage for AI clients. Priority (first match wins): excluded, handed_off, failed,
        tagged, replied, messaged, connected, connection_sent, already_first_degree, then new.
        already_first_degree means the sending account already had a 1st-degree connection and the
        agent skipped the invitation at invite time (existingFirstDegreeSkipped).
      enum:
        - new
        - connection_sent
        - already_first_degree
        - connected
        - messaged
        - replied
        - tagged
        - excluded
        - failed
        - handed_off
    LeadListItem:
      type: object
      properties:
        id: { type: string }
        fullName: { type: string, nullable: true }
        firstName: { type: string, nullable: true }
        lastName: { type: string, nullable: true }
        linkedinUrl: { type: string, nullable: true }
        jobTitle: { type: string, nullable: true }
        location: { type: string, nullable: true }
        companyName: { type: string, nullable: true }
        companyLinkedin: { type: string, nullable: true }
        website: { type: string, nullable: true }
        email: { type: string, nullable: true }
        tag:
          oneOf:
            - $ref: '#/components/schemas/LeadTag'
            - type: 'null'
        excluded: { type: boolean }
        replied: { type: boolean }
        needsReply: { type: boolean }
        stage:
          $ref: '#/components/schemas/LeadStage'
        repliedAt: { type: string, format: date-time, nullable: true }
        lastInboundMessageAt: { type: string, format: date-time, nullable: true }
        taggedAt: { type: string, format: date-time, nullable: true }
    ActivityEvent:
      type: object
      properties:
        id: { type: string }
        type:
          type: string
          enum:
            - connection_request_sent
            - connection_accepted
            - message_sent
            - reply_received
            - agent_replied
            - cta_sent
            - agent_handed_off
        timestamp: { type: string, format: date-time }
        leadId: { type: string, nullable: true }
        leadName: { type: string, nullable: true }
        companyName: { type: string, nullable: true }
        campaignId: { type: string, nullable: true }
        messagePreview: { type: string, nullable: true }
        handOffReason: { type: string, nullable: true }
    InsightsOverview:
      type: object
      properties:
        highlights:
          type: object
          properties:
            lastActivityAt: { type: string, format: date-time, nullable: true }
            lastReplyAt: { type: string, format: date-time, nullable: true }
            lastReplyLeadName: { type: string, nullable: true }
            lastReplyCampaignId: { type: string, nullable: true }
        workspace:
          type: object
          properties:
            repliesReceived: { type: integer }
            connectionRequestsSent: { type: integer }
            connectionRequestsAccepted: { type: integer }
            messagesSent: { type: integer }
        topCampaignsByReplyRate:
          type: array
          items:
            $ref: '#/components/schemas/Campaign'
        topCampaignsByAcceptanceRate:
          type: array
          items:
            $ref: '#/components/schemas/Campaign'
        campaignsSampled: { type: integer }
        campaignsSampleCapped: { type: boolean }
    WorkExperience:
      type: object
      properties:
        company: { type: string, nullable: true }
        position: { type: string, nullable: true }
        location: { type: string, nullable: true }
        description: { type: string, nullable: true }
        start: { type: string, nullable: true }
        end: { type: string, nullable: true }
    LeadDetail:
      allOf:
        - $ref: '#/components/schemas/LeadListItem'
        - type: object
          properties:
            headline: { type: string, nullable: true }
            phone: { type: string, nullable: true }
            companySize: { type: string, nullable: true }
            companyCountry: { type: string, nullable: true }
            companyCity: { type: string, nullable: true }
            personalization: { type: string, nullable: true }
            custom: { type: string, nullable: true }
            custom1: { type: string, nullable: true }
            custom2: { type: string, nullable: true }
            custom3: { type: string, nullable: true }
            custom4: { type: string, nullable: true }
            custom5: { type: string, nullable: true }
            custom6: { type: string, nullable: true }
            custom7: { type: string, nullable: true }
            custom8: { type: string, nullable: true }
            custom9: { type: string, nullable: true }
            custom10: { type: string, nullable: true }
            workExperience:
              type: array
              items:
                $ref: '#/components/schemas/WorkExperience'
            connectionRequestAccepted: { type: boolean }
            messageSent: { type: boolean }
    AddLeadBody:
      type: object
      required: [linkedinUrl]
      additionalProperties: false
      properties:
        linkedinUrl: { type: string }
        fullName: { type: string, maxLength: 120 }
        firstName: { type: string, maxLength: 120 }
        lastName: { type: string, maxLength: 120 }
        jobTitle: { type: string, maxLength: 200 }
        companyName: { type: string, maxLength: 200 }
        email: { type: string, maxLength: 254 }
        location: { type: string, maxLength: 200 }
        headline: { type: string, maxLength: 500 }
        personalization: { type: string, maxLength: 2000 }
        custom: { type: string, maxLength: 2000 }
        custom1: { type: string, maxLength: 2000 }
        custom2: { type: string, maxLength: 2000 }
        custom3: { type: string, maxLength: 2000 }
        custom4: { type: string, maxLength: 2000 }
        custom5: { type: string, maxLength: 2000 }
        custom6: { type: string, maxLength: 2000 }
        custom7: { type: string, maxLength: 2000 }
        custom8: { type: string, maxLength: 2000 }
        custom9: { type: string, maxLength: 2000 }
        custom10: { type: string, maxLength: 2000 }
    AddLeadResponse:
      type: object
      required: [leadId, status, creditsCharged]
      properties:
        leadId: { type: string }
        status:
          type: string
          enum: [created, duplicate, excluded]
        creditsCharged: { type: integer, enum: [0, 1] }
    AddLeadsBatchBody:
      type: object
      required: [leads]
      additionalProperties: false
      properties:
        leads:
          type: array
          minItems: 1
          maxItems: 100
          items:
            $ref: '#/components/schemas/AddLeadBody'
    AddLeadsBatchResponse:
      type: object
      required: [results, summary, creditsCharged]
      properties:
        results:
          type: array
          items:
            type: object
            required: [index, status, creditsCharged]
            properties:
              index: { type: integer }
              linkedinUrl: { type: string, nullable: true }
              leadId: { type: string, nullable: true }
              status:
                type: string
                enum:
                  [
                    created,
                    duplicate,
                    excluded,
                    validation_error,
                    insufficient_credits,
                    failed,
                  ]
              creditsCharged: { type: integer, enum: [0, 1] }
              error:
                type: object
                properties:
                  code: { type: string }
                  message: { type: string }
        summary:
          type: object
          additionalProperties: { type: integer }
        creditsCharged: { type: integer, minimum: 0, maximum: 100 }
    UpdateLeadsBatchResponse:
      type: object
      required: [results, summary, creditsCharged]
      properties:
        results:
          type: array
          items:
            type: object
            required: [index, status]
            properties:
              index: { type: integer }
              leadId: { type: string, nullable: true }
              status:
                type: string
                enum: [updated, not_found, validation_error, failed]
              tag:
                oneOf:
                  - $ref: '#/components/schemas/LeadTag'
                  - type: 'null'
              excluded: { type: boolean }
              fields:
                type: object
                additionalProperties: { type: string }
                description: CRM/profile scalars written for this item (when requested)
              error:
                type: object
                properties:
                  code: { type: string }
                  message: { type: string }
        summary:
          type: object
          properties:
            total: { type: integer }
            updated: { type: integer }
            not_found: { type: integer }
            validation_error: { type: integer }
            failed: { type: integer }
        creditsCharged: { type: integer, enum: [0] }
    DeleteLeadsBatchResponse:
      type: object
      required: [results, summary, creditsCharged, reconciliationFailed]
      properties:
        results:
          type: array
          items:
            type: object
            required: [index, status]
            properties:
              index: { type: integer }
              leadId: { type: string, nullable: true }
              status:
                type: string
                enum: [deleted, not_found, validation_error, failed]
              error:
                type: object
                properties:
                  code: { type: string }
                  message: { type: string }
        summary:
          type: object
          properties:
            total: { type: integer }
            deleted: { type: integer }
            not_found: { type: integer }
            validation_error: { type: integer }
            failed: { type: integer }
        creditsCharged: { type: integer, enum: [0] }
        reconciliationFailed: { type: boolean }
    PatchLeadBody:
      type: object
      additionalProperties: false
      description: >
        Provide at least one of tag, excluded, or a CRM/profile field. Empty string or null clears a CRM field.
        LinkedIn URL is not writable. Same allowlist as the in-app lead editor.
        Sending firstName/lastName without fullName updates fullName server-side.
      properties:
        tag:
          oneOf:
            - $ref: '#/components/schemas/LeadTag'
            - type: 'null'
        excluded: { type: boolean }
        fullName: { type: string, maxLength: 400 }
        firstName: { type: string, maxLength: 200 }
        lastName: { type: string, maxLength: 200 }
        email: { type: string, maxLength: 320 }
        jobTitle: { type: string, maxLength: 400 }
        companyName: { type: string, maxLength: 400 }
        companyLinkedin: { type: string, maxLength: 500 }
        phone: { type: string, maxLength: 80 }
        website: { type: string, maxLength: 500 }
        companySize: { type: string, maxLength: 120 }
        companyCountry: { type: string, maxLength: 120 }
        companyCity: { type: string, maxLength: 120 }
        headline: { type: string, maxLength: 500 }
        location: { type: string, maxLength: 200 }
        personalization:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom1:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom2:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom3:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom4:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom5:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom6:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom7:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom8:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom9:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom10:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
    BatchUpdateLeadItem:
      type: object
      required: [leadId]
      additionalProperties: false
      description: Same fields as PatchLeadBody plus required leadId.
      properties:
        leadId: { type: string }
        tag:
          oneOf:
            - $ref: '#/components/schemas/LeadTag'
            - type: 'null'
        excluded: { type: boolean }
        fullName: { type: string, maxLength: 400 }
        firstName: { type: string, maxLength: 200 }
        lastName: { type: string, maxLength: 200 }
        email: { type: string, maxLength: 320 }
        jobTitle: { type: string, maxLength: 400 }
        companyName: { type: string, maxLength: 400 }
        companyLinkedin: { type: string, maxLength: 500 }
        phone: { type: string, maxLength: 80 }
        website: { type: string, maxLength: 500 }
        companySize: { type: string, maxLength: 120 }
        companyCountry: { type: string, maxLength: 120 }
        companyCity: { type: string, maxLength: 120 }
        headline: { type: string, maxLength: 500 }
        location: { type: string, maxLength: 200 }
        personalization:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom1:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom2:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom3:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom4:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom5:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom6:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom7:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom8:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom9:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
        custom10:
          oneOf:
            - { type: string, maxLength: 2000 }
            - { type: 'null' }
    PatchLeadResponse:
      type: object
      required: [id, tag, excluded]
      properties:
        id: { type: string }
        tag:
          oneOf:
            - $ref: '#/components/schemas/LeadTag'
            - type: 'null'
        excluded: { type: boolean }
        fields:
          type: object
          additionalProperties: { type: string }
          description: Present when CRM/profile fields were in the request (values after sanitize)
    SendMessageBody:
      type: object
      required: [campaignId, leadId, text]
      additionalProperties: false
      properties:
        campaignId: { type: string, maxLength: 128 }
        leadId: { type: string, maxLength: 128 }
        text: { type: string, maxLength: 8000 }
        accountId: { type: string, maxLength: 128 }
    LookupBody:
      type: object
      required: [accountId, linkedinUrl]
      additionalProperties: false
      properties:
        accountId: { type: string }
        linkedinUrl: { type: string }
        depth:
          type: string
          enum: [basic, full]
          default: basic
    ProfileLookup:
      type: object
      properties:
        fullName: { type: string, nullable: true }
        firstName: { type: string, nullable: true }
        lastName: { type: string, nullable: true }
        headline: { type: string, nullable: true }
        jobTitle: { type: string, nullable: true }
        companyName: { type: string, nullable: true }
        companyLinkedin: { type: string, nullable: true }
        website: { type: string, nullable: true }
        location: { type: string, nullable: true }
        linkedinUrl: { type: string, nullable: true }
        providerId: { type: string, nullable: true }
        profilePictureUrl: { type: string, nullable: true }
        about: { type: string, nullable: true }
        experience:
          type: array
          items:
            type: object
            additionalProperties: true
    SearchBody:
      type: object
      required: [accountId]
      additionalProperties: false
      properties:
        accountId: { type: string }
        type:
          type: string
          enum: [classic, sales_nav]
          default: classic
        query: { type: string, maxLength: 2000 }
        url: { type: string, maxLength: 2000 }
        limit: { type: integer }
        cursor: { type: string, maxLength: 4000 }
    SearchResult:
      type: object
      properties:
        fullName: { type: string, nullable: true }
        headline: { type: string, nullable: true }
        jobTitle: { type: string, nullable: true }
        companyName: { type: string, nullable: true }
        location: { type: string, nullable: true }
        linkedinUrl: { type: string, nullable: true }
        providerId: { type: string, nullable: true }
        profilePictureUrl: { type: string, nullable: true }
    WebhookEvent:
      type: object
      description: Outbound webhook payload (not a REST request)
      properties:
        id: { type: string }
        type:
          type: string
          enum:
            - reply.received
            - connection.accepted
            - lead.tagged
            - account.disconnected
        createdAt: { type: string, format: date-time }
        data:
          type: object
          properties:
            campaignId: { type: string, nullable: true }
            leadId: { type: string, nullable: true }
            accountId: { type: string, nullable: true }
            linkedinUrl: { type: string, nullable: true }
            fullName: { type: string, nullable: true }
            messageText: { type: string, nullable: true }
            tag: { type: string, nullable: true }
            messageId:
              type: string
              nullable: true
              description: Provider message id when known (dedupe / incremental sync)
            conversationId:
              type: string
              nullable: true
              description: ScaliQ conversation / thread id when known
            messageTimestamp:
              type: string
              format: date-time
              nullable: true
              description: When ScaliQ recorded the inbound message (ISO-8601); envelope createdAt is webhook delivery time
            direction:
              type: string
              nullable: true
              enum: [incoming, outgoing]
              description: Always incoming on reply.received; null on other events
