LM-Kit OneDocs2026.8.10lm-kit.com
AI Assistants

Chat with Document

Chat with a document using conversational question-answering.#

POST/lmkit/v1/chat-with-document

Loads a document and enables multi-turn conversational Q&A powered by RAG.

Session lifecycle:

  1. First call: provide 'input' + 'input_format' to create a session. Returns a 'session_id'.
  2. Subsequent calls: provide 'session_id' + 'question' to chat. Conversation context is maintained.
  3. DELETE /lmkit/v1/chat-with-document/ to release resources.

Response modes:

stream: false (default): returns a single ChatWithDocumentResponse JSON object.

stream: true: returns a text/event-stream of SSE events. Each event is data: {json}\n\n containing a ChatWithDocumentStreamChunk object with these fields:

Field Type Description
session_id string The session identifier
delta string Incremental text token (empty in the final chunk)
thinking bool true if the delta is internal reasoning (chain-of-thought), false for the user-visible answer
done bool true on the final chunk
response string? Complete answer text (final chunk only, excludes thinking)
source_references array? Retrieved document passages (final chunk only)

The stream ends with data: [DONE]\n\n.

If document loading exceeds the configured timeout, returns 202 Accepted with a job_id. Poll GET /lmkit/v1/jobs/ for status and results.

Request body

application/json ·

PropertyTypeDescription
session_idstring

The session identifier returned by a previous call. Omit on the first call to create a new session and load a document.

inputstring

The input document to load. Required when session_id is not provided. When input_format is 'Base64EncodedFile', provide a base64-encoded file payload. When 'FileIdentifier', provide the file ID previously returned by the /lmkit/v1/files/upload endpoint.

input_format

How the input is provided. Accepted values: 'Base64EncodedFile' or 'FileIdentifier'. Defaults to 'Base64EncodedFile'.

questionstring

The user question to ask about the loaded document. Required when session_id is provided. Optional on the first call (if provided, the question is submitted immediately after loading the document).

modelstring

The identifier of the chat model to use for response generation. If not provided, the server's default chat model is used. Only used when creating a new session.

embedding_modelstring

The identifier of the embedding model to use for passage retrieval. If not provided, the server's default text embeddings model is used. Only used when creating a new session.

streamboolean

When true, the response is streamed as server-sent events (SSE). Each event contains a JSON object with a 'delta' field for incremental text. Defaults to false.

max_completion_tokensobject (int32)

The maximum number of tokens permitted for the response. Set to -1 to disable the limit. Defaults to -1 (unlimited).

Responses

StatusTypeDescription
200

OK

202

Accepted

400

Bad Request

404

Not Found

500application/json

Internal Server Error

curl -X POST "$LMKIT_ONE_URL/lmkit/v1/chat-with-document" \
  -H "Authorization: Bearer $LMKIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "session_id": "string",
  "input": "",
  "input_format": "Base64EncodedFile",
  "question": ""
}'

Skip the model's thinking phase and start generating the answer.#

POST/lmkit/v1/chat-with-document/{sessionId}/skip-thinking

Signals the model to immediately end its internal reasoning (chain-of-thought) and begin producing the user-visible answer. Has no effect if the model is not currently thinking.

Parameters

NameInTypeDescription
sessionIdrequiredpathstring

The session identifier.

Responses

StatusTypeDescription
200

OK

404

Not Found

curl -X POST "$LMKIT_ONE_URL/lmkit/v1/chat-with-document/$SESSIONID/skip-thinking" \
  -H "Authorization: Bearer $LMKIT_API_KEY"

Clear the conversation history while keeping the loaded document.#

POST/lmkit/v1/chat-with-document/{sessionId}/clear-history

Resets the chat history so you can start a fresh conversation without reloading the document.

Parameters

NameInTypeDescription
sessionIdrequiredpathstring

The session identifier.

Responses

StatusTypeDescription
200

OK

404

Not Found

curl -X POST "$LMKIT_ONE_URL/lmkit/v1/chat-with-document/$SESSIONID/clear-history" \
  -H "Authorization: Bearer $LMKIT_API_KEY"

Delete a chat session and release its resources.#

DELETE/lmkit/v1/chat-with-document/{sessionId}

Removes the chat session, releases the loaded models, and frees memory.

Parameters

NameInTypeDescription
sessionIdrequiredpathstring

The session identifier to delete.

Responses

StatusTypeDescription
200

OK

404

Not Found

curl -X DELETE "$LMKIT_ONE_URL/lmkit/v1/chat-with-document/$SESSIONID" \
  -H "Authorization: Bearer $LMKIT_API_KEY"