API overview
Start the search service and connect local or LAN applications.
How it works
On Linux (Ubuntu 24.04 or Debian 12, x86_64 or ARM64), the standalone CLI can run the HTTP API without the desktop app or a graphical environment. The API shares the knowledge base, index and decision-model configuration with desktop and CLI. Local and LAN access is allowed by default.
The API provides search, folder browsing and service status. Search returns source passages without generating answers or summaries. See the API reference for parameters, responses and errors.
To connect through an MCP client, see the MCP guide.
Start the service
The API service can run on macOS, Windows or Linux, serving local and LAN applications.
If the desktop app is installed, open Settings → Remote services, click Create key, then turn on API and MCP. You can start and stop the API independently.
Remote services automatically refreshes service status and automatic-startup registration status. On Windows, these checks run in the background without opening a command window.
To start it through the standalone CLI, install Node.js/npm, then run the commands below. Command examples on this page use macOS/Linux shell syntax. Replace directories with absolute paths on the computer running the service. On Windows, run the same sag commands in PowerShell with Windows absolute paths.
npm install -g @zleap-ai/sag
sag config
sag add "/data/documents"
sag api key create --name "Application A"
sag api startsag config configures the decision model used by deep search. sag api key create creates credentials for applications calling the HTTP API. These keys are managed separately. Fast search needs no model configuration.
New API keys are stored locally and can be copied again from the desktop key list. Keys created in earlier versions still work; create a new key to copy it from Settings. Each key can be revoked individually and can use full-library or selected-folder access. Existing keys retain full-library access after upgrading, including folders added later; existing credentials and MCP configurations need no changes.
Run a search
Replace the address with the server's address and the key with the value saved at creation. The default port is 24681; use the actual address printed by the CLI or shown in Settings → Remote services.
export SAG_API_URL='http://192.168.1.10:24681'
export SAG_API_KEY='<API_KEY>'
curl --fail-with-body --max-time 65 \
-H "Authorization: Bearer $SAG_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"query":"How is the project deployed?","mode":"deep","limit":10}' \
"$SAG_API_URL/v1/search"| Mode | Purpose | Whole-request deadline |
|---|---|---|
deep, default | Retrieve relevant evidence for a complete question; requires a decision model | 60 seconds |
fast | Find keywords in the local index; no model required | 30 seconds |
Calls wait synchronously for results. Deadlines include queueing and execution. A slightly longer client timeout allows for network transfer. Deep-search failures return an explicit error and retain the requested mode.
Select directories
Call GET /v1/folders to list the current key’s permitted entry folders. Full-library keys still list all imported roots; restricted keys list only granted directories, with a granted subfolder itself serving as an entry folder. Supplying path lists that directory’s immediate subfolders within the granted scope, one level at a time.
curl --fail-with-body \
-H "Authorization: Bearer $SAG_API_KEY" \
"$SAG_API_URL/v1/folders"
curl --fail-with-body --get \
-H "Authorization: Bearer $SAG_API_KEY" \
--data-urlencode 'path=/data/documents' \
"$SAG_API_URL/v1/folders"Use the returned absolute paths in the search request's paths array to select one or more roots or subdirectories. Omitting paths, or supplying an empty array, searches all folders allowed by the current key. Full-library keys continue to search the entire knowledge base. Paths refer to the server. Identically named folders are distinguished by their absolute paths.
{
"query": "How is the project deployed?",
"mode": "deep",
"paths": ["/data/project-notes", "/data/technical-docs/deployment"],
"limit": 10
}Manage the service and keys
| Command | Purpose |
|---|---|
sag api start | Start the API and save its enabled state |
sag api start --host HOST --port PORT | Start with a specified IP address and port |
sag api status --json | Print status and addresses as JSON without exposing keys or starting the backend |
sag api stop | Close the API and cancel API searches while retaining the shared backend |
sag api status | Show runtime status and local and LAN addresses for the API and MCP |
sag api mcp config | Export a configuration with the address and key; see the MCP guide for options |
sag api key create --name NAME | Create a named key and show its full value |
sag api key list | List key names, IDs and partial identifiers |
sag api key revoke KEY_ID | Revoke a key and cancel its searches |
sag api autostart enable | Enable the platform's automatic startup mechanism |
sag api autostart disable | Disable automatic startup |
sag api autostart status | Inspect automatic-startup registration |
With no valid key, the API keeps listening and HTTP requests return 401 Unauthorized. Revoking the last key does not stop the API. Management happens through the local CLI or desktop settings, with no management endpoints over HTTP.
Background operation and desktop settings
Closing the terminal leaves the service running. Settings → Remote services shows local and LAN API and MCP addresses only while the API is running. Copy an API address or the corresponding MCP configuration there. A green status dot indicates that the service is running. API documentation, next to the page title, opens the reference page. Expand Request example at the bottom of the API and MCP card to view and copy a sample request.
Connection configuration is always visible below API and MCP. Choose This device only or This device and local network (the default). The web service and API share these settings; stop both before changing them. After saving and starting the service, This device only shows the local address. This device and local network also shows available LAN addresses. Service, key and automatic-startup actions take effect immediately.
Opening desktop restores the saved API enabled state. An API stopped manually remains off when desktop next opens. Automatic startup is in a separate section below Connection configuration and is off by default. When enabled, Linux can run after reboot without login; macOS and Windows start after the user logs in.
API searches share the existing 20 expensive-task slots with desktop and CLI, waiting when full. Indexed content remains searchable while indexing continues. Browser cross-origin access is off by default; normal local and LAN application calls are unaffected.
Continue to the API reference for the complete endpoint contract.
Limit folders by project
In Settings → Remote services → Create key, enter the project name and select Entire knowledge base or Selected folders. Select one or more imported roots or subfolders; shared folders may belong to multiple keys. Use Edit scope in the key list to change an existing key. Saving takes effect immediately and cancels that key’s running and queued requests without affecting other keys.

You can also use the CLI with absolute server directory paths:
sag api key create --name "Project A" --path "/data/project-a" --path "/data/shared"
sag api key set-scope KEY_ID --path "/data/project-a"
sag api key set-scope KEY_ID --all
sag api key list --json
sag api mcp config --key-id KEY_IDOmitting --path when creating a key preserves the original full-library behavior; --all selects it explicitly. Scope changes require --path or --all. The same scope applies to HTTP API and MCP. Restricted keys cannot request parent folders or other projects. Removed folders or changed canonical paths return scope_unavailable; select folders again locally. Access never falls back to the entire knowledge base.
These grants do not change desktop, local management CLI or separate web-access-code permissions. A web access code is not a project key.
Grants apply to the selected directory locations; later content updates remain accessible. Restricted searches use the indexed files allowed when the request resolves its scope; new files are included on the next search.