SidetalkGuides
Sidetalk website ↗Open dashboard

Training Data Answer Generation API

Purpose

Retrieves an answer from saved training question-and-answer data, calls the AI once to format it, and returns the result. Depending on stream, responses are regular JSON or an SSE stream.

URL

Plain Text
https://api.sidetalk.ai/v1/knowledge/completions

HTTP method

Plain Text
POST

Request body

ParameterTypeRequiredDescription
questionStringConditionalUsed to find an exact match to the saved question when knowledgeId is absent.
knowledgeIdStringConditionalThe ID identifying a training data entry. Pass data[].knowledgeId from the query API response unchanged.
streamBooleanNofalse (default) returns regular JSON; true returns an SSE stream.
sessionIdStringNoThe session ID for chat logs.
Provide either knowledgeId or question. If both are provided, knowledgeId takes priority.

Example request

Request by knowledgeId

Bash
curl -X POST "https://api.sidetalk.ai/v1/knowledge/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${API_KEY}" \
  -d '{
    "knowledgeId": "456",
    "stream": false
  }'

Request with an existing session

Bash
curl -X POST "https://api.sidetalk.ai/v1/knowledge/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${API_KEY}" \
  -d '{
    "knowledgeId": "456",
    "sessionId": "943f15db-3984-4f21-ad64-f0115839c3a6",
    "stream": false
  }'

Success response (200 OK)

JSON
{
  "success": true,
  "knowledgeId": "456",
  "sessionId": "943f15db-3984-4f21-ad64-f0115839c3a6",
  "message": {
    "content": "배송은 결제 후 2~3일 이내에 진행됩니다."
  },
  "recommended_questions": [
    {
      "knowledgeId": "3356",
      "question": "배송 조회는 어떻게 하나요?",
      "type": "chat_data"
    }
  ],
  "meta": {
    "chat_log_uuid": "uuid",
    "knowledgeId": "456",
    "sessionId": "943f15db-3984-4f21-ad64-f0115839c3a6",
    "latency_ms": 850,
    "used_credit": 1,
    "tokens": {
      "input_tokens": 100,
      "output_tokens": 30,
      "total_tokens": 130,
      "token_cost": 0
    }
  }
}

Error response

Status codeDescription
400Invalid JSON format or required identifying information.
402Insufficient API credits.
403API key authentication failed.
404No training answer matches the criteria.
500A server error occurred during answer generation.
JSON
{
  "success": false,
  "error": "Answer not found"
}
Note: this API retrieves the specified training data answer and applies AI formatting once.

Stream request (stream: true)

With stream: true, responses use the same SSE format as the conversational API. A metadata event is followed by data chunks with choices[].delta.content, then a finish_reason: "stop" chunk and [DONE]. knowledgeId is included in metadata and all data chunks.
Bash
curl -N -X POST "https://api.sidetalk.ai/v1/knowledge/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${API_KEY}" \
  -d '{
    "knowledgeId": "456",
    "stream": true,
    "sessionId": "api-session-1"
  }'
An example response follows.
JSON
event: metadata
data: {"knowledgeId":"456","sessionId":"api-session-1","chat_log_uuid":"uuid"}

data: {"id":"chatcmpl-uuid","object":"chat.completion.chunk","created":1731042399,"knowledgeId":"456","choices":[{"index":0,"delta":{"content":"배송은 "},"finish_reason":null}]}

data: {"id":"chatcmpl-uuid","object":"chat.completion.chunk","created":1731042399,"knowledgeId":"456","choices":[{"index":0,"delta":{"content":"결제 후 2~3일 이내에 진행됩니다."},"finish_reason":null}]}

data: {"id":"chatcmpl-uuid","object":"chat.completion.chunk","created":1731042399,"knowledgeId":"456","choices":[{"index":0,"delta":{},"finish_reason":null}],"sidetalk_event":{"type":"recommendedQuestions","data":{"items":[{"knowledgeId":"3356","question":"배송 조회는 어떻게 하나요?","type":"chat_data"}]}}}

data: {"id":"chatcmpl-uuid","object":"chat.completion.chunk","created":1731042399,"knowledgeId":"456","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"meta":{"chat_log_uuid":"uuid","knowledgeId":"456","sessionId":"api-session-1","latency_ms":850,"used_credit":1,"tokens":{"input_tokens":100,"output_tokens":30,"total_tokens":130,"token_cost":0}}}

data: [DONE]
Regular JSON responses include recommended_questions. If there are no directly linked suggestions, up to three similarity-based suggestions may be returned.
Suggested question identifiers are also knowledgeId; type indicates the suggested data type.
In streams, the following event is added in the same data format as answer chunks.
JSON
data: {"id":"chatcmpl-uuid","object":"chat.completion.chunk","created":1731042399,"knowledgeId":"456","choices":[{"index":0,"delta":{},"finish_reason":null}],"sidetalk_event":{"type":"recommendedQuestions","data":{"items":[{"knowledgeId":"3356","question":"배송 조회는 어떻게 하나요?","type":"chat_data"}]}}}

data: {"id":"chatcmpl-uuid","object":"chat.completion.chunk","created":1731042399,"knowledgeId":"456","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]
With question alone and no knowledgeId, the API finds an exact match to a saved training question. If no suggestions are available after retrieving the answer, similarity-based suggestions may be looked up automatically.