API DocsIntroduction
Getting Started

Developer API

Build on top of your own document sets. Upload and index documents, then ask natural-language questions and get answers grounded in those documents — with citations back to the source files and pages.

This reference covers the Document API (bearer-token, JSON) and the embeddable chatbot (an account-scoped cb_ key), which lives on the web app host.

Conventions

  • API request and response bodies are JSON (Content-Type: application/json), except the streaming chat response, which is Server-Sent Events.
  • A docset (docSetName) is a named collection of indexed documents.
  • Timestamps are ISO 8601 strings.
Try requests in the browser

Every endpoint has a Try it console. Open Authorize in the top bar to set your API token or chatbot cb_ key, then edit the body and send. Each request is routed to the right host automatically and proxied through the docs server, so there’s no CORS setup. /health and /version need no credentials.

Getting Started

Authentication

There are two credential types. Most API endpoints use a bearer API token; the embeddable chatbot uses an account-scoped cb_ key.

API token (Document API)

HTTP header
Authorization: Bearer YOUR_API_TOKEN

The NestJS Document API authenticates every request with a bearer token. Requests without a valid token are rejected with 401 Unauthorized. The /health and /version endpoints are public.

Chatbot key (cb_…)

HTTP header
Authorization: Bearer cb_1234567890abcdef…

The chatbot and support-email endpoints use an account-scoped key that starts with cb_, generated from the account’s chatbot settings. It is safe to embed in a public website widget: a key may be locked to an allowed Origin/Referer, the endpoints require a Pro or Business plan, and they are rate-limited (50/hour on Pro, 100/hour on Business).

Keep credentials secret

Treat the API token like a password — keep it server-side, never in client code. Only the cb_ chatbot key is designed to be exposed in a browser widget.

Getting Started

Errors

Errors are returned as JSON with an HTTP status code that reflects the problem.

Error shape (API)

application/json
{
  "message": "Add an authorization header to the request: \"bearer <token>\"",
  "errorCode": "UNAUTHENTICATED"
}

message is human-readable; errorCode is a stable, machine-readable code you can branch on. Some validation errors include additional context fields.

Common status codes

StatusMeaning
400Bad Request — the input was malformed.
401Unauthorized — missing or invalid credentials.
404Not Found — the requested resource does not exist.
409Conflict — the request clashes with current state.
422Unprocessable Entity — well-formed but could not be acted on.
503Service Unavailable — a required capability is disabled.
General

Health check

GET/health

Liveness probe for the API service. No authentication required.

GET /health
curl https://docsapi.torqn.com/health
Try itGET https://docsapi.torqn.com/health
General

Version

GET/version

Returns the running application version. No authentication required.

GET /version
curl https://docsapi.torqn.com/version
Try itGET https://docsapi.torqn.com/version
Chat

Ask a question (RAG)

POST/ask

Run a retrieval-augmented question against one or more docsets and get an answer grounded in the retrieved passages, with citations.

Multi-turn conversations

Pass the conversation so far in pastMessages (oldest first) to keep context. The current question goes in question, not in pastMessages.

Streaming

Set "stream": true (or send Accept: text/event-stream) to receive a Server-Sent Events stream of JSON chunks carrying incremental answer text, so a chat UI can render tokens as they arrive.

Citations

The answer contains inline markers like [1] that map to entries in citations by index. Each citation carries fileName, pageNumber, and source metadata.

Body parameters
question
string
Required
The user’s question.
docSetNames
string[]
Required
Docsets to search.
pastMessages
Message[]
Optional
Prior turns, oldest first. A Message is { "role": "user" | "assistant", "content": string }.
config
object
Optional
Retrieval/generation tuning — e.g. retrievalLimit, minimumSimilarityScore, model.
promptContext
string
Optional
Extra system context prepended to the prompt.
stream
boolean
Optional
Stream the answer as Server-Sent Events.
POST /ask
curl -X POST https://docsapi.torqn.com/ask \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"question":"What is our refund policy?","docSetNames":["company-policies"]}'
Try itPOST https://docsapi.torqn.com/ask
Example response · 200
application/json
{
  "answer": "Refunds are available within 30 days of purchase [1].",
  "citations": [
    {
      "index": 1,
      "fileName": "refund-policy.pdf",
      "pageNumber": "2",
      "sourceType": "S3",
      "sourceMetadata": { "sourceId": "policies/refund-policy.pdf" }
    }
  ],
  "usage": { "inputTokens": 1234, "outputTokens": 88, "calls": 2, "perModel": [] }
}
Chat

Evaluate keyword routing

GET/keyword-routing/evaluate

Evaluate which docsets a query would route to via keyword rules, without running a full RAG query.

GET /keyword-routing/evaluate
curl https://docsapi.torqn.com/keyword-routing/evaluate?question=refund%20policy \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/keyword-routing/evaluate?question=refund%20policy
Chatbot

Ask the chatbot

POST/api/v1/chatbot/ask_question

The embeddable chatbot endpoint on the web app. Runs a retrieval-augmented question against the account’s docset and returns an answer with citations — authenticated with the account-scoped cb_ key.

Uses the cb_ chatbot key

Authenticate with the cb_ key (not the API token). Requires a Pro or Business plan, and — when the key has an allowed origin set — the request Origin/Referer must match it. Rate limited to 50/hour (Pro) or 100/hour (Business).

Pass prior turns in past_messages (oldest first; only the last 10 are used). Set stream to true to receive a text/event-stream of Server-Sent Events instead of a single JSON body. The docset is resolved from the account the key belongs to.

Body parameters
question
string
Required
The user’s question.
past_messages
Message[]
Optional
Prior turns as { role, content } objects (role is "user" or "assistant"). Only the last 10 are used.
format
string
Optional
text (default) returns Markdown; html returns rendered HTML.
stream
boolean
Optional
When true, responds with a Server-Sent Events stream.
POST /api/v1/chatbot/ask_question
curl -X POST https://docsai.torqn.com/api/v1/chatbot/ask_question \
  -H "Authorization: Bearer $CHATBOT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"question":"What is the refund policy?","format":"text"}'
Try itPOST https://docsai.torqn.com/api/v1/chatbot/ask_question
Example response · 200
application/json
{
  "answer": "Refunds are available within 30 days of purchase [1].",
  "citations": [
    {
      "index": 1,
      "fileName": "refund-policy.pdf",
      "pageNumber": "2",
      "source": "https://files.example.com/refund-policy.pdf?signature=..."
    }
  ],
  "support_email": "[email protected]"
}
Chatbot

Send a support request

POST/api/v1/support_emails

Send a support message to the account’s configured support inbox — designed to back a “Contact support” action in a widget. Uses the cb_ chatbot key.

Body parameters
message
string
Required
The support message (maximum 2000 characters).
sender_email
string
Optional
Optional reply-to address for the requester.
POST /api/v1/support_emails
curl -X POST https://docsai.torqn.com/api/v1/support_emails \
  -H "Authorization: Bearer $CHATBOT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"message":"I can’t find the onboarding guide.","sender_email":"[email protected]"}'
Try itPOST https://docsai.torqn.com/api/v1/support_emails
Example response · 200
application/json
{
  "success": true,
  "message": "Your support request has been sent successfully. We'll get back to you soon!"
}
Summaries

Generate a conversation summary

POST/summary

Generate a short, descriptive title for a conversation — useful for naming chat threads in a sidebar.

Body parameters
pastMessages
Message[]
Required
The conversation to title, oldest first. A Message is { "role": "user" | "assistant", "content": string }.
POST /summary
curl -X POST https://docsapi.torqn.com/summary \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"pastMessages":[{"role":"user","content":"What is our refund policy?"},{"role":"assistant","content":"Refunds are available within 30 days."}]}'
Try itPOST https://docsapi.torqn.com/summary
Example response · 200
application/json
{ "title": "Refund policy window" }
Documents (API)

List documents

GET/documents

List the documents in a docset. Returns id, fileName, docSetName, source, indexingStatus, and timestamps.

GET /documents
curl https://docsapi.torqn.com/documents?docSetName=company-policies \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/documents?docSetName=company-policies
Documents (API)

Recent documents

GET/documents/recent

List recently indexed documents. limit is optional (1–100, default 20).

GET /documents/recent
curl https://docsapi.torqn.com/documents/recent?limit=10 \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/documents/recent?limit=10
Documents (API)

List docsets

GET/documents/docsets

List every docset with its source types and document counts.

GET /documents/docsets
curl https://docsapi.torqn.com/documents/docsets \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/documents/docsets
Documents (API)

Docset metadata

GET/documents/metadata/{docSetName}

Return aggregate metadata for a single docset.

GET /documents/metadata/{docSetName}
curl https://docsapi.torqn.com/documents/metadata/company-policies \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/documents/metadata/company-policies
Documents (API)

Indexing summary

GET/documents/indexing-summary

Summary of indexing status across docsets.

GET /documents/indexing-summary
curl https://docsapi.torqn.com/documents/indexing-summary \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/documents/indexing-summary
Documents (API)

Get document

GET/documents/{id}

Fetch a single document by id, or 404 if the id is unknown.

GET /documents/{id}
curl https://docsapi.torqn.com/documents/123 \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/documents/123
Indexing

Start indexing

POST/index

Index a docset from a source — S3 (default), SharePoint, or Google Drive. Runs asynchronously by default and returns a job id.

Body parameters
docSetName
string
Required
The docset to index into.
sourceType
enum
Optional
S3 (default), SHAREPOINT, or GOOGLEDRIVE.
credentials
object
Optional
Source credentials; shape depends on sourceType. Omit for S3 when the API has bucket access.
indexOptions
object
Optional
{ targetIndexTypes?, forceReindex? }.
async
boolean
Optional
Queue the job (true, default) or block until done (false).
accountName
string
Optional
Optional account/tenant label.
summaryModel
string
Optional
LLM used for document summarization.
POST /index
curl -X POST https://docsapi.torqn.com/index \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"docSetName":"company-policies","sourceType":"S3"}'
Try itPOST https://docsapi.torqn.com/index
Example response · 200
application/json
{ "message": "Indexing queued", "docSetName": "company-policies", "jobId": "..." }
Indexing

Check a source

POST/index/check-source

Validate connectivity and report how many supported files a source has, without indexing anything.

POST /index/check-source
curl -X POST https://docsapi.torqn.com/index/check-source \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"docSetName":"company-policies","sourceType":"S3"}'
Try itPOST https://docsapi.torqn.com/index/check-source
Example response · 200
application/json
{ "sourceFileCount": 12, "existingDocumentCount": 0, "message": "Found 12 supported files." }
Indexing

Store SharePoint credentials

POST/index/credentials/sharepoint

Store the SharePoint credentials used to index a docset. The exact shape depends on your tenant’s app registration.

POST /index/credentials/sharepoint
curl -X POST https://docsapi.torqn.com/index/credentials/sharepoint \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"docSetName":"company-policies","tenantId":"...","clientId":"...","clientSecret":"..."}'
Try itPOST https://docsapi.torqn.com/index/credentials/sharepoint
Indexing

Indexing progress

GET/index/progress/{docSetName}

Return document status counts and an isIndexing flag for a docset.

GET /index/progress/{docSetName}
curl https://docsapi.torqn.com/index/progress/company-policies \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/index/progress/company-policies
Example response · 200
application/json
{
  "pendingCount": 3,
  "indexingCount": 1,
  "completedCount": 8,
  "errorCount": 0,
  "isIndexing": true
}
Indexing

Cancel indexing

POST/index/cancel/{docSetName}

Cancel an in-progress indexing run for a docset.

POST /index/cancel/{docSetName}
curl -X POST https://docsapi.torqn.com/index/cancel/company-policies \
  -H "Authorization: Bearer $API_TOKEN"
Try itPOST https://docsapi.torqn.com/index/cancel/company-policies
Indexing

Retry a document

POST/index/retry/{documentId}

Retry indexing a single failed document.

POST /index/retry/{documentId}
curl -X POST https://docsapi.torqn.com/index/retry/DOCUMENT_ID \
  -H "Authorization: Bearer $API_TOKEN"
Try itPOST https://docsapi.torqn.com/index/retry/DOCUMENT_ID
Indexing

Reindex all

POST/index/reindex-all

Trigger a reindex of every document. Long-running.

POST /index/reindex-all
curl -X POST https://docsapi.torqn.com/index/reindex-all \
  -H "Authorization: Bearer $API_TOKEN"
Try itPOST https://docsapi.torqn.com/index/reindex-all
Indexing

Delete docsets

DELETE/index/docsets

Delete one or more docsets and their indexed documents.

DELETE /index/docsets
curl -X DELETE https://docsapi.torqn.com/index/docsets \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"docSetNames":["company-policies"]}'
Try itDELETE https://docsapi.torqn.com/index/docsets
Indexing — Operations

Get consumer mode

GET/index/consumer

Return the current queue consumer mode.

GET /index/consumer
curl https://docsapi.torqn.com/index/consumer \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/index/consumer
Indexing — Operations

Set consumer mode

POST/index/consumer

Set the queue consumer mode (e.g. pause or resume consumption).

POST /index/consumer
curl -X POST https://docsapi.torqn.com/index/consumer \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"mode":"paused"}'
Try itPOST https://docsapi.torqn.com/index/consumer
Indexing — Operations

Active sessions

GET/index/sessions

List active indexing sessions.

GET /index/sessions
curl https://docsapi.torqn.com/index/sessions \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/index/sessions
Indexing — Operations

Session detail

GET/index/sessions/{docSetName}

Return the indexing session detail for a docset.

GET /index/sessions/{docSetName}
curl https://docsapi.torqn.com/index/sessions/company-policies \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/index/sessions/company-policies
Indexing — Operations

Recovery log

GET/index/recovery-log

Return the indexing recovery log.

GET /index/recovery-log
curl https://docsapi.torqn.com/index/recovery-log \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/index/recovery-log
Indexing — Operations

Abort log

GET/index/abort-log

Return the indexing abort log.

GET /index/abort-log
curl https://docsapi.torqn.com/index/abort-log \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/index/abort-log
Indexing — Operations

Watchdog status

GET/index/watchdog

Return the indexing watchdog status.

GET /index/watchdog
curl https://docsapi.torqn.com/index/watchdog \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/index/watchdog
Indexing — Operations

Queue status

GET/index/queues

Return queue status.

GET /index/queues
curl https://docsapi.torqn.com/index/queues \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/index/queues
Indexing — Operations

Queue stats

GET/index/queue-stats

Return queue statistics.

GET /index/queue-stats
curl https://docsapi.torqn.com/index/queue-stats \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/index/queue-stats
Indexing — Operations

Stuck documents

GET/index/stuck-documents

List documents that appear stuck mid-indexing.

GET /index/stuck-documents
curl https://docsapi.torqn.com/index/stuck-documents \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/index/stuck-documents
Indexing — Operations

Document errors

GET/index/document-errors

List documents that errored during indexing.

GET /index/document-errors
curl https://docsapi.torqn.com/index/document-errors \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/index/document-errors
Indexing — Operations

Runtime config

GET/index/config

Return the indexer’s runtime configuration.

GET /index/config
curl https://docsapi.torqn.com/index/config \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/index/config
Indexing — Operations

Document timeline

GET/index/document-timeline/{id}

Return the indexing timeline for a single document.

GET /index/document-timeline/{id}
curl https://docsapi.torqn.com/index/document-timeline/123 \
  -H "Authorization: Bearer $API_TOKEN"
Try itGET https://docsapi.torqn.com/index/document-timeline/123