SAG Wiki Docs

API reference

Parameters, responses and errors for search, folders and service status.

Follow Start the API service to enable the service and configure a key.

Authentication

The default base address is http://SERVER_IP:24681; use the actual service configuration. All endpoints use JSON and require:

Authorization: Bearer <API_KEY>

Each key can access the entire knowledge base or only its selected folders and their subfolders. Existing keys retain full-library access after upgrading; existing credentials and MCP configurations keep working without reconfiguration. Missing, invalid or revoked keys return 401, including when no key has been created. The API continues running when the valid-key count reaches zero.

POST/v1/search
Bearer Token · JSON

Request body

querystringRequired
Search text. Must contain 1–2000 characters.
modestringDefault: deep
Either deep (deep retrieval) or fast (full-text search).
pathsstring[]
Absolute server directory paths. Accepts multiple directories; omitted or empty searches all folders allowed by the current key. Full-library keys continue to search the entire knowledge base.
excludestring[]
Glob patterns for both fast and deep search, such as archive/**. Patterns match paths relative to each search directory. Patterns without a slash match file names.
limitintegerDefault: 10
Maximum source passages returned. Range: 1–100.

fast reuses local full-text search without a model. deep reuses the decision model and existing retrieval settings. Incomplete configuration or model failures return explicit errors while preserving the requested mode.

One or more directories form a single search scope, including their permitted subdirectories. Duplicate scopes are removed and results ranked together. Any invalid path or path outside the current key’s scope fails the entire request, including mixed allowed and denied paths. Requested paths can narrow access but cannot expand it. The API does not import new directories automatically.

Directories can use a symbolic-link path or its actual path; both resolve to the same search scope. If an indexed root later becomes a symbolic link, whole-library search can still use its existing index. Excluded directories and subdirectory links pointing outside the knowledge base remain inaccessible.

Request and response

curl http://127.0.0.1:24681/v1/search \
  -H "Authorization: Bearer <API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{"query":"How is the project deployed?","mode":"deep","limit":10}'

Response fields

FieldMeaning
request_idRequest identifier
modeRetrieval mode actually used
elapsed_msServer duration, including queueing
resultsSource passages grouped by file path and heading. Groups follow the first matching candidate’s position in the retrieval order. Within a group, overlapping or adjacent ranges are merged in source order.
pathAbsolute server file path
headingPassage heading
start_line, end_lineSource line range; converted documents retain the searchable text's location semantics
contentSource passage text
truncatedTrue when a response-size boundary reduces results; selecting the top limit results is not truncation

No matches returns 200 with an empty array. Already indexed content can be searched while indexing continues, with no indexing-in-progress marker in search responses. The endpoint returns up to limit source passages. For deep search, the per-round candidate setting also caps the number of candidates used to assemble the response. The endpoint provides no pagination, generated answers or summaries.

Folders

GET/v1/folders
Bearer Token · JSON

With no path, full-library keys list all knowledge-base roots; restricted keys list only their granted folders, including subfolders, without exposing parents or siblings. Supplying path lists only that directory's immediate subfolders. Names are display labels; absolute paths distinguish identically named folders. No aliases are used.

Query parameters

pathstring
Absolute server directory path. Omit to list the current key’s granted entry folders; supply to list immediate subfolders. URL-encode the value.

Request and response

curl http://127.0.0.1:24681/v1/folders \
  -H "Authorization: Bearer <API_KEY>"

All roots are listed together; subfolders are browsed one level at a time. No matches returns an empty array. Only permitted directories are returned, without file contents. URL-encode the path, including spaces, non-ASCII text and Windows path characters.

Service status

GET/v1/status
Bearer Token · JSON
curl http://127.0.0.1:24681/v1/status \
  -H "Authorization: Bearer <API_KEY>"

decision_configured reports whether the server has saved usable decision-model configuration.

Returns the actual version, API runtime state, decision-model configuration availability and root indexing states. It never returns secrets or internal connection tokens. When the API is off, inspect status through local sag api status or desktop settings.

Decision-model fields, configuration names and error codes consistently use decision.

For restricted keys, roots contains only granted directories. Each indexed_files count covers that granted directory, without disclosing its parent’s count.

Deadlines and concurrency

Fast requests have a 30-second deadline and deep requests a 60-second deadline, including queueing and execution. API searches share the existing 20 expensive-task slots with desktop and CLI. Full capacity causes waiting without resetting the deadline.

A timeout, caller disconnect, revoked key, changed key scope or stopped API cancels the corresponding API search. Other keys, desktop requests, ordinary CLI commands and indexing tasks continue. Reaching the concurrency limit alone does not immediately return 429.

The JSON request body is limited to 32 KiB and must arrive within 30 seconds. Search JSON responses are limited to 512 KiB; oversized responses omit complete passages and set truncated to true, without cutting passage text.

Error responses

{
  "request_id": "example-request",
  "error": {"code": "unauthorized", "message": "Unauthorized"}
}
HTTP statusError codeCondition
400invalid_requestInvalid parameters, JSON, types or ranges
400invalid_pathPath is not an absolute directory path or has the wrong type
401unauthorizedMissing, invalid or revoked API key
403path_not_allowedPath is outside the knowledge base or the current key’s scope
403scope_unavailableA granted folder was removed, became unavailable or changed its canonical path (for example, a retargeted symlink); reset the scope locally
404directory_not_foundDirectory is missing or removed
404not_foundEndpoint does not exist
405method_not_allowedHTTP method is unsupported
408invalid_requestRequest body reception timed out
409decision_not_configuredDeep search requires decision-model configuration
413request_too_largeRequest exceeds the input-size boundary
502decision_request_failedDecision-model request failed
503api_stoppedStopping the API cancelled the request; returned if the connection remains writable
504search_timeoutWhole search request timed out
500internal_errorSource changed during retrieval or another internal failure

An upstream model authentication failure is distinct from an unauthorized calling API key. Failures return explicit errors rather than empty results. See the API overview for installation and service management.

To connect through an MCP client, see the MCP guide.

HTTP MCP search (fast/deep) and /v1/search accept exclude: {"query":"authentication flow","paths":["F:/project"],"exclude":[".git/**","archive/","*.zip"]}. Patterns are relative to each search root. Excluding all files returns no results, never an unrestricted search. Converted documents use the original filename and extension; within a converted-output directory, relative subdirectories are preserved, for example nested/report.csv rather than nested/report.csv.md.

With exclusions, each search uses the files allowed when filtering runs; newly added files are included on the next search.

Folder grants apply before retrieval and decision scoring, with the same restrictions for fast/deep and MCP. Converted PDF/Office documents inherit access from their original source directories; do not grant the conversion storage directory. An unavailable grant returns an error and never falls back to full-library search.

On this page