Logo
Search & Inference

FAQ Generator

Overview

The FAQ Generator endpoint is a knowledge agent that automatically generates frequently asked questions (FAQs) from documents using AI-powered question extraction and answer generation. You can specify focus areas and the number of questions to generate, and the system will create relevant Q&A pairs with source and relevance rankings.

Use this endpoint to:

  • Automatically generate FAQs from documents, manuals, and knowledge bases
  • Create Q&A pairs with specific focus areas (e.g., pricing, legal, technical)
  • Build comprehensive FAQ sections for websites and documentation
  • Extract key information as question-answer pairs
  • Generate training data for chatbots and support systems

Endpoint Details

Method: POST
Endpoint: /api/agent/faq_generator
Base URL: https://api.k-v.ai
Authentication: Access Key (Required)


Request Specification

Headers

HeaderTypeRequiredDescription
access-keystringYesYour unique access-key generated from the platform UI
Content-TypestringYesMust be application/json

Request Body

{
    "doc_process_ids": [
        "264dfa262b748d15ccbeaada89430c68"
    ],
    "focus_areas": ["fee"],
    "question_count": 2,
    "model_data": {
        "model_name": "gpt-5.1",
        "api_key": ""
    }
}

Body Fields

FieldTypeRequiredDescription
doc_process_idsarrayYesArray of document IDs to generate FAQs from (obtained from Upload or List Documents APIs)
focus_areasarrayNoList of focus areas to generate questions about (e.g., "pricing", "legal", "technical"). Leave empty for general FAQs
question_countintegerYesNumber of questions to generate (minimum: 1, maximum: 10)
model_dataobjectYesAI model configuration
model_data.model_namestringYesAI model to use for FAQ generation (see supported models below)
model_data.api_keystringNoYour own LLM API key (leave empty to use platform's default keys)

Supported AI Models

Model NameProvider
gpt-5.1OpenAI
gpt-5-miniOpenAI
claude-sonnet-4-5-20250929Anthropic
gemini/gemini-2.5-flash-liteGoogle
gemini/gemini-2.5-proGoogle
gemini/gemini-3-pro-previewGoogle
mistral/mistral-small-latestMistral AI
mistral/mistral-medium-latestMistral AI
llama3.1-70bMeta

Question Count Limits

  • Minimum: 1 question
  • Maximum: 10 questions per request

Using Your Own LLM API Keys

Platform Keys (Default):

{
    "model_data": {
        "model_name": "gpt-5.1",
        "api_key": ""
    }
}

Your Own Keys:

{
    "model_data": {
        "model_name": "gpt-5.1",
        "api_key": "sk-your-openai-api-key-here"
    }
}

Response Specification

Success Response (200 OK)

{
    "data": {
        "questions_answers": [
            {
                "question": "What is the prevailing party entitled to regarding attorneys' fees in any action relating to the Agreement?",
                "answer": "In any action relating to the Agreement, the prevailing party is entitled to collect reasonable attorneys' fees and costs from the non-prevailing party in addition to any other recovery.",
                "focus_area": "fee",
                "page_numbers": [
                    "1"
                ],
                "rank": 1,
                "source": "Settlement Agreement (1).pdf",
                "doc_hash": [
                    "264dfa262b748d15ccbeaada89430c68"
                ]
            },
            {
                "question": "Who is responsible for paying attorneys' fees and costs incurred before the execution of the Settlement Agreement?",
                "answer": "Each party is responsible for bearing its own attorneys' fees and costs arising from the actions of its own counsel incurred prior to the date of execution of the Agreement.",
                "focus_area": "fee",
                "page_numbers": [
                    "1"
                ],
                "rank": 2,
                "source": "Settlement Agreement (1).pdf",
                "doc_hash": [
                    "264dfa262b748d15ccbeaada89430c68"
                ]
            }
        ],
        "is_sufficient": true,
        "tokens": {
            "input": 1501,
            "output": 261,
            "total": 1762
        }
    },
    "message": "FAQs extracted successfully"
}

Response Fields

FieldTypeDescription
dataobjectResponse data object
data.questions_answersarrayArray of generated Q&A pairs
data.questions_answers[].questionstringGenerated question
data.questions_answers[].answerstringAI-generated answer based on document content
data.questions_answers[].focus_areastringFocus area this Q&A relates to (if specified in request)
data.questions_answers[].page_numbersarrayPage numbers where the answer information was found
data.questions_answers[].rankintegerRelevance ranking (1 = most relevant) based on cosine similarity and keyword matching
data.questions_answers[].sourcestringOriginal filename of the source document
data.questions_answers[].doc_hasharrayDocument process ID(s)
data.is_sufficientbooleantrue if the number of generated questions matches question_count, false if fewer questions were generated
data.tokensobjectToken usage for this request
data.tokens.inputintegerInput tokens consumed
data.tokens.outputintegerOutput tokens generated
data.tokens.totalintegerTotal tokens used
messagestringHuman-readable response message

Error Responses

401 Unauthorized

{
    "data": {},
    "message": "Invalid or missing access key"
}

Cause: Missing or invalid access-key header


422 Unprocessable Entity - Invalid Model Name

{
    "detail": [
        {
            "type": "literal_error",
            "loc": [
                "body",
                "model_data",
                "model_name"
            ],
            "msg": "Input should be 'gpt-5-chat-latest', 'gpt-5.1', 'gpt-5-mini', 'claude-sonnet-4-5-20250929', 'gemini/gemini-2.5-flash-lite', 'mistral/mistral-small-latest', 'mistral/mistral-medium-latest', 'gemini/gemini-2.5-pro', 'gemini/gemini-3-pro-preview' or 'llama3.1-70b'",
            "input": "",
            "ctx": {
                "expected": "'gpt-5-chat-latest', 'gpt-5.1', 'gpt-5-mini', 'claude-sonnet-4-5-20250929', 'gemini/gemini-2.5-flash-lite', 'mistral/mistral-small-latest', 'mistral/mistral-medium-latest', 'gemini/gemini-2.5-pro', 'gemini/gemini-3-pro-preview' or 'llama3.1-70b'"
            }
        }
    ]
}

Cause: Invalid or unsupported model_name in model_data. See supported models list above.


400 Bad Request - Invalid Document IDs

{
    "data": {},
    "message": "Invalid docs selected"
}

Causes: Missing or invalid doc_process_ids.


500 Internal Server Error - Invalid LLM API Key

{
    "data": {},
    "message": "litellm.AuthenticationError: AuthenticationError: OpenAIException - Incorrect API key provided: tyrdfuih**uhf7. You can find your API key at https://platform.openai.com/account/api-keys."
}

Cause: The api_key provided in model_data is invalid or expired. Verify your LLM provider API key.


500 Internal Server Error - General Error

{
    "data": {},
    "message": "Something went wrong"
}

Causes:

  • LLM service temporarily unavailable
  • Server-side processing error

422 Unprocessable Entity - Invalid Question Count

{
    "detail": [
        {
            "type": "json_invalid",
            "loc": [
                "body",
                121
            ],
            "msg": "JSON decode error",
            "input": {},
            "ctx": {
                "error": "Expecting value"
            }
        }
    ]
}

Causes:

  • Missing question_count field
  • Invalid question_count value (must be 1-10)
  • Malformed JSON request body

Code Snippets

cURL

curl --location 'https://api.k-v.ai/api/agent/faq_generator' \
--header 'access-key: YOUR_ACCESS_KEY' \
--header 'Content-Type: application/json' \
--data '{
    "doc_process_ids": [
        "264dfa262b748d15ccbeaada89430c68"
    ],
    "focus_areas": ["fee"],
    "question_count": 2,
    "model_data": {
        "model_name": "gpt-5.1",
        "api_key": ""
    }
}'

Python

import requests
import json

url = "https://api.k-v.ai/api/agent/faq_generator"

payload = json.dumps({
    "doc_process_ids": [
        "264dfa262b748d15ccbeaada89430c68"
    ],
    "focus_areas": [
        "fee"
    ],
    "question_count": 2,
    "model_data": {
        "model_name": "gpt-5.1",
        "api_key": ""
    }
})

headers = {
    'access-key': 'YOUR_ACCESS_KEY',
    'Content-Type': 'application/json'
}

response = requests.post(url, headers=headers, data=payload)

print(response.text)

JavaScript (Node.js)

const axios = require('axios');

let data = JSON.stringify({
    "doc_process_ids": [
        "264dfa262b748d15ccbeaada89430c68"
    ],
    "focus_areas": [
        "fee"
    ],
    "question_count": 2,
    "model_data": {
        "model_name": "gpt-5.1",
        "api_key": ""
    }
});

let config = {
    method: 'post',
    maxBodyLength: Infinity,
    url: 'https://api.k-v.ai/api/agent/faq_generator',
    headers: { 
        'access-key': 'YOUR_ACCESS_KEY',
        'Content-Type': 'application/json'
    },
    data: data
};

axios.request(config)
.then((response) => {
    console.log(JSON.stringify(response.data, null, 2));
})
.catch((error) => {
    console.log(error);
});

Important Notes

  • Document Processing: Only generate FAQs from documents with status: "processed"
  • Question Limits: Maximum 10 questions per request
  • Focus Areas: More specific focus areas yield better, more targeted questions
  • Rankings: Lower rank numbers indicate higher relevance
  • Sufficiency: Check is_sufficient to know if all requested questions were generated

Next Steps

After generating FAQs:

  1. Review Quality: Verify generated Q&A accuracy against source documents
  2. Build Knowledge Base: Integrate FAQs into documentation or support systems
  3. Iterate: Refine focus areas and question counts based on results

Need Help? Contact support at support@k-v.ai

On this page