Chat with Document
Chat with a document using conversational question-answering.#
/lmkit/v1/chat-with-documentLoads a document and enables multi-turn conversational Q&A powered by RAG.
Session lifecycle:
- First call: provide 'input' + 'input_format' to create a session. Returns a 'session_id'.
- Subsequent calls: provide 'session_id' + 'question' to chat. Conversation context is maintained.
- 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 ·
| Property | Type | Description |
|---|---|---|
session_id | string | The session identifier returned by a previous call. Omit on the first call to create a new session and load a document. |
input | string | 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'. | |
question | string | 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). |
model | string | 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_model | string | 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. |
stream | boolean | 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_tokens | object (int32) | The maximum number of tokens permitted for the response. Set to -1 to disable the limit. Defaults to -1 (unlimited). |
Responses
| Status | Type | Description |
|---|---|---|
| 200 | OK | |
| 202 | Accepted | |
| 400 | Bad Request | |
| 404 | Not Found | |
| 500 | application/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.#
/lmkit/v1/chat-with-document/{sessionId}/skip-thinkingSignals 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
| Name | In | Type | Description |
|---|---|---|---|
sessionIdrequired | path | string | The session identifier. |
Responses
| Status | Type | Description |
|---|---|---|
| 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.#
/lmkit/v1/chat-with-document/{sessionId}/clear-historyResets the chat history so you can start a fresh conversation without reloading the document.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
sessionIdrequired | path | string | The session identifier. |
Responses
| Status | Type | Description |
|---|---|---|
| 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.#
/lmkit/v1/chat-with-document/{sessionId}Removes the chat session, releases the loaded models, and frees memory.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
sessionIdrequired | path | string | The session identifier to delete. |
Responses
| Status | Type | Description |
|---|---|---|
| 200 | OK | |
| 404 | Not Found |
curl -X DELETE "$LMKIT_ONE_URL/lmkit/v1/chat-with-document/$SESSIONID" \
-H "Authorization: Bearer $LMKIT_API_KEY"