> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getaftercare.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create AI Followup Question

> Generates a contextual followup question based on a survey response



## OpenAPI

````yaml POST /api/v1/followups
openapi: 3.0.0
info:
  title: Followup Generation API
  version: 1.0.0
  description: API for generating followup questions based on survey responses
  contact:
    name: API Support
    email: justin@getaftercare.com
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
  - url: https://surveys.getaftercare.com
    description: Production server
  - url: https://staging.aftercareai.com
    description: Staging server
security:
  - ApiKeyAuth: []
tags:
  - name: Followups
    description: Operations related to followup question generation
  - name: Data Quality
    description: Operations related to response data quality evaluation
  - name: Coding
    description: Operations related to coding survey responses
paths:
  /api/v1/followups:
    post:
      tags:
        - Followups
      summary: Generate a followup question
      description: Generates a contextual followup question based on a survey response
      operationId: generateFollowup
      parameters:
        - $ref: '#/components/parameters/X-Request-Encoding'
        - $ref: '#/components/parameters/X-Response-Encoding'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FollowupGenerationRequest'
            example:
              surveyName: Customer Satisfaction
              surveyDescription: Tracking customer satisfaction and loyalty for the XYZ Company
              question: How likely are you to recommend our service?
              questionContext: >-
                I want to understand specifically why a customer is convinced to
                recommend our service. If they are not recommending our service,
                I want to know why.
              answer: Very likely, the customer service is excellent
              surveyIdentifiers:
                surveyIdentifier: CSAT-2024-Q1
                questionIdentifier: NPS-1
              guidanceBehavior: Verbose
      responses:
        '200':
          description: Successfully generated followup question
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FollowupGenerationResponse'
              example:
                followupQuestion: >-
                  What specific aspects of our customer service impressed you
                  the most?
                responseEvaluation:
                  completeness: 75
                  relevance: 90
                threadId: 7a54b8da-f65d-4946-9c9a-f202e0cc29c8
                responseIdentifier: '12345'
        '400':
          description: Bad request - invalid input parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                code: INVALID_REQUEST
                message: Invalid request parameters
                details:
                  question: Question is required
        '403':
          description: Forbidden - Missing or invalid API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                code: INVALID_API_KEY
                message: Invalid or missing API key
        '404':
          description: Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                code: NOT_FOUND
                message: Requested resource not found
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                code: INTERNAL_ERROR
                message: An unexpected error occurred
        '504':
          description: Gateway timeout
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                code: GATEWAY_TIMEOUT
                message: The request timed out
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            const response = await api.followups.generate({
              surveyName: 'Customer Satisfaction',
              question: 'How likely are you to recommend our service?',
              answer: 'Very likely, the customer service is excellent',
              surveyIdentifiers: {
                surveyIdentifier: 'CSAT-2024-Q1',
                questionIdentifier: 'NPS-1'
              }
            });
        - lang: Python
          source: |-
            response = api.followups.generate(
                survey_name='Customer Satisfaction',
                question='How likely are you to recommend our service?',
                answer='Very likely, the customer service is excellent',
                surveyIdentifiers={
                    'survey_identifier': 'CSAT-2024-Q1',
                    'question_identifier': 'NPS-1'
                }
            )
components:
  parameters:
    X-Request-Encoding:
      in: header
      name: X-Request-Encoding
      schema:
        type: string
        enum:
          - unicode
          - html
        default: unicode
      required: false
      description: >-
        Specifies the encoding format of the request data. Use `html` if you are
        sending data that HTML entity encodes non-ASCII characters.
    X-Response-Encoding:
      in: header
      name: X-Response-Encoding
      schema:
        type: string
        enum:
          - unicode
          - html
        default: unicode
      required: false
      description: >-
        Specifies the preferred encoding format for the response data. Use
        `html` if you are expecting to receive data that HTML entity encodes
        non-ASCII characters.
  schemas:
    FollowupGenerationRequest:
      type: object
      required:
        - question
        - answer
      properties:
        surveyName:
          type: string
          description: The name of the survey as it will appear in the Aftercare platform
          example: Customer Satisfaction
        surveyDescription:
          type: string
          description: >-
            A description of the survey purpose and background.


            It will be used to give the AI more context around specific aspects
            of the survey (e.g. brand/product names, movie names, etc.)
          example: >-
            Quarterly survey tracking customer satisfaction and loyalty for the
            XYZ Company
        question:
          type: string
          description: The question that was asked to the respondent
          example: How likely are you to recommend our service?
        questionContext:
          type: string
          description: >-
            A description of what you are trying to learn from the respondent
            for this question.


            This will be used to give the AI guidance on what followup questions
            to ask.
          example: >-
            I want to understand specifically why a customer is convinced to
            recommend our service. If they are not recommending our service, I
            want to know why.
        answer:
          type: string
          description: The answer to the question provided by the respondent
          example: Very likely, the customer service is excellent
        surveyIdentifiers:
          type: object
          description: >-
            Optional identifiers to tie responses to a specific survey and
            question.

            If provided, Aftercare will use these to generate analytics over
            your survey responses.


            If included, both survey and question identifiers are required.


            See the [Aftercare Data Model](/aftercareDataModel) to learn more.
          required:
            - surveyIdentifier
            - questionIdentifier
          properties:
            surveyIdentifier:
              type: string
              description: >-
                Optional unique identifier for the survey.


                Aftercare will use this to build a data model to associate
                questions and answers with the survey.
              example: CSAT-2024-Q1
            questionIdentifier:
              type: string
              description: >-
                Optional unique identifier for the question.


                Aftercare will use this to build a data model to track questions
                across a survey
              example: Q1
        responseLanguage:
          type: string
          description: >-
            Optional language to use for the followup question generation.


            If not provided, Aftercare will default to the language it
            determines best matches the response.


            Set response language to `match_response_language` to automatically
            set the language of the generated follow up question to the language
            of the respondent's answer.
          example: French
        threadId:
          type: string
          description: >-
            A unique identifier for the follow-up response thread.


            If provided, Aftercare will follow-up questions and answers in a
            thread with the original question and answer.


            If not provided, Aftercare will automatically generate a new thread
            id you can use in a subsequent follow-up.
          example: 7a54b8da-f65d-4946-9c9a-f202e0cc29c8
        responseIdentifier:
          type: string
          description: >-
            Optional unique identifier for a respondent's entire response to a
            survey.


            Aftercare will use this to build a data model tie together questions
            and answer pairs for a single response.
          example: '12345'
        guidanceBehavior:
          $ref: '#/components/schemas/FollowupGenerationGuidanceBehavior'
    FollowupGenerationResponse:
      type: object
      required:
        - followupQuestion
        - responseEvaluation
      properties:
        followupQuestion:
          type: string
          description: The generated followup question
          example: >-
            What specific aspects of our customer service impressed you the
            most?
        responseEvaluation:
          $ref: '#/components/schemas/ResponseEvaluation'
        threadId:
          type: string
          description: The unique identifier for the follow-up thread
          example: 7a54b8da-f65d-4946-9c9a-f202e0cc29c8
        responseIdentifier:
          type: string
          description: Optional identifier for the survey response
          example: '12345'
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: Error code
          example: INVALID_REQUEST
        message:
          type: string
          description: Error message
          example: Invalid request parameters
        details:
          type: object
          description: Additional error details
          example:
            question: Question is required
    FollowupGenerationGuidanceBehavior:
      type: string
      description: >-
        Different ways Aftercare AI will generate follow-up questions based on
        incomplete or irrelevant user input.


        * `Succinct` - The AI will not generate a follow-up question if the
        response is irrelevant or complete. This occurs when the relevance score
        is below 25 or the completeness score is above 70. This is the default
        behavior.

        * `Redirection` - The AI will return a follow-up question that redirects
        the user to answering the top-level question if it is irrelevant and
        incomplete.

        A follow-up question will be generated as long as the completeness score
        is below 70.

        * `Verbose` - The AI will always return a follow-up question regardless
        of the relevance or completeness of the response.
      enum:
        - Succinct
        - Redirection
        - Verbose
      default: Succinct
    ResponseEvaluation:
      type: object
      required:
        - completeness
        - relevance
      properties:
        completeness:
          type: number
          description: >-
            A number between 0 and 100 that represents how completely the
            response answered the topic question.

            The higher the score, the more complete the response.
          minimum: 0
          maximum: 100
        relevance:
          type: number
          description: >-
            A number between 0 and 100 that represents the relevance of the
            response to the topic question.

            The higher the score, the more relevant the response.
          minimum: 0
          maximum: 100
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-Aftercare-Key
      description: API key for authentication

````