API Reference

Quick Start

The Saachi API is a REST API served at https://saachi.ai. This page, /api-docs, is the API reference.

Every example below uses an API key. Create one from Account → API Keys in the dashboard (or via the keys endpoint).

1. Create a collection

curl -X POST https://saachi.ai/collections \
  -H "Authorization: Bearer <api_key>" \
  -H "Content-Type: application/json" \
  -d '{"name": "My Knowledge Base"}'
# → {"id": "...", "name": "My Knowledge Base", ...}

2. Upload files

curl -X POST https://saachi.ai/collections/<collection_id>/ingest \
  -H "Authorization: Bearer <api_key>" \
  -F "files=@/path/to/document.pdf"

3. Ask a question

curl -X POST https://saachi.ai/collections/<collection_id>/query/sync \
  -H "Authorization: Bearer <api_key>" \
  -H "Content-Type: application/json" \
  -d '{"question": "What does the contract say about renewal?"}'
# → {"answer": "...", "sources": [...], "sources_used": [0], ...}

Authentication

All requests authenticate with an API key in the Authorization header:

Authorization: Bearer <api_key>

Keys are issued per account and shown only once at creation — save the value immediately.

Key types

TypeCan doTypical use
adminFull read + write on allowed collectionsBackend services, ingest pipelines
queryRead-only queries and listingsPublic widgets, integrations
embedPowers the iframe embed widget only (/embed/<collection_id>?key=…)Embedding a collection's Q&A on your own site

Key scope

ScopeReach
accountEvery collection on the account
collectionOnly the collection IDs you picked when creating the key

Manage keys programmatically under Account → Keys.

Collections

A collection is an isolated knowledge base. Files, folders, and vector embeddings are scoped per collection.

GET /collections

List all collections the key can access.

POST /collections

Create a collection. Body: {"name": "My KB"}. Returns the new collection with its id.

GET /api/collections/<id>

Fetch a single collection's metadata (name, timestamps, file counts).

PATCH /collections/<id>

Rename a collection. Body: {"name": "New name"}.

DELETE /collections/<id>

Delete a collection and all of its folders, files, and embeddings. Irreversible.

Folders

Folders group files inside a collection. A file is active in queries only if its folder is enabled (or the file has no folder).

GET /collections/<id>/folders

List folders with their enabled flag and file_count.

POST /collections/<id>/folders

Create a folder. Body: {"name": "Contracts"}.

PATCH /collections/<id>/folders/<folder_id>

Toggle a folder on or off. Body: {"enabled": false}. Disabling a folder excludes all its files from retrieval without changing individual file flags.

DELETE /collections/<id>/folders/<folder_id>

Delete a folder. Files inside are moved back to the collection root.

Files

GET /collections/<id>/files

List files. Each record includes id, filename, file_type, enabled, downloadable, chunk_count, folder_id, source (upload / google_drive / circleback / user_input), ingested_at, document_date (null unless set), and an optional profile summary.

PATCH /collections/<id>/files/<file_id>

Update a file. Any subset of fields:

{
  "enabled": false,          // toggle in/out of retrieval
  "filename": "renamed.pdf", // rename the record
  "folder_id": "folder-abc", // move to folder (null = collection root)
  "document_date": "2024-03-15", // date used by query date filters
                             // (null = clear, fall back to ingested_at)
  "downloadable": false      // block visitors on share links / embeds from
                             // downloading this file, even when the surface's
                             // own allow-download setting is on
}

DELETE /collections/<id>/files/<file_id>

Delete a file, its chunks, and its embeddings.

GET /collections/<id>/files/<file_id>/content

Return the extracted plain-text of the file (the text actually used for retrieval).

GET /collections/<id>/files/<file_id>/download

Download the original uploaded file.

Notes written in Saachi

Notes are Markdown files created directly in Saachi (no upload). They go through the normal ingest pipeline and are the only files whose content can be edited afterwards.

POST /collections/<id>/files/manual

{
  "title": "Meeting follow-ups",   // becomes the filename
  "content": "## Action items…",   // Markdown body
  "folder_id": "folder-abc"        // optional
}

GET /collections/<id>/files/<file_id>/manual

Return the note's Markdown content. 403 unless the file's source is user_input.

PUT /collections/<id>/files/<file_id>/manual

Replace the note's content and re-ingest it. Body: {"content": "…"}. Same 403 rule as above.

Ingestion

POST /collections/<id>/ingest

Upload one or more files. Returns immediately with queued job IDs — parsing, chunking, and embedding happen asynchronously.

Supported formats:

  • Text: .txt .md .pdf .docx .pptx .csv .xlsx .html
  • .pptx decks are parsed slide-by-slide, speaker notes included. Google Docs, Sheets, and Slides import via the Google Drive integration.
  • Audio / video (transcribed with Whisper): .mp3 .wav .m4a .ogg .flac .mp4 .webm

Optional form field folder_id places the files into a specific folder.

Optional form field document_date (YYYY-MM-DD) sets the date the query date_from/date_to filters see for these files, instead of the upload time. Use it when backfilling older documents. It applies to every file in the request, so send one file per request when the dates differ. Re-uploading a file without it keeps the date it already has.

Filenames may be up to 255 bytes in UTF-8 (about 85 Japanese characters). Send non-ASCII names as raw UTF-8 in filename=; percent-encoded names are stored as-is, and filename*= is ignored, per RFC 7578. A longer name returns 400 and queues nothing.

curl -X POST https://saachi.ai/collections/<id>/ingest \
  -H "Authorization: Bearer <api_key>" \
  -F "files=@report.pdf" \
  -F "files=@notes.md" \
  -F "folder_id=folder-abc" \
  -F "document_date=2024-03-15"   # optional, for backfills
# → [{"job_id": "...", "filename": "report.pdf", "status": "pending"}, ...]

GET /collections/<id>/ingest/jobs

Returns ingest jobs that are still in progress (pending, processing, or failed). Completed jobs drop off this list once the file shows up in /files.

# → [{"id": "...", "filename": "report.pdf", "status": "processing"}, ...]

DELETE /collections/<id>/ingest/jobs/<job_id>

Clear a failed or cancelled job and its staged file from the list. Needs write access to the collection. Returns 404 for jobs in any other state.

Querying

Four query endpoints share the same request body. Pick by response shape and retrieval strategy.

Request body

FieldTypeDefaultDescription
questionstringrequiredThe question to ask (up to 4,000 characters)
modelstringserver defaultModel ID (see Models)
n_resultsint12Chunks to retrieve before answering (1–20)
date_fromstring (date)noneOnly retrieve from files dated on/after this date (YYYY-MM-DD)
date_tostring (date)noneOnly retrieve from files dated on/before this date (YYYY-MM-DD)
conversation_historyarraynonePrior turns for multi-turn conversations: [{"role": "user"|"assistant", "content": "…"}]. Up to 40 messages of 8,000 characters each; only the last 20 are used. Any other role is rejected with 422.
conversation_turnintnone1-based turn number, used for usage accounting on conversations

A file's date is its document_date if one was set at upload (or later via PATCH), otherwise ingested_at (upload time to Saachi).

Query syntax

Two inline operators tune retrieval inside the question string itself:

  • |phrase| — positive pin: boosts chunks containing this exact phrase.
  • !term! — negative exclude: removes every chunk containing this term before retrieval runs. Example: "best healing item !potion!"

POST /collections/<id>/query/sync

Single JSON response. Best for scripts and integrations.

curl -X POST https://saachi.ai/collections/<id>/query/sync \
  -H "Authorization: Bearer <api_key>" \
  -H "Content-Type: application/json" \
  -d '{"question": "What is the refund policy?"}'
{
  "answer": "Refunds are accepted within 30 days of purchase.",
  "sources": [
    {"filename": "policy.md", "score": 0.91, "chunk": "...", "chunk_index": 0, "file_id": "..."}
  ],
  "sources_used": [0],
  "model": "openai/gpt-oss-20b",
  "prompt_tokens": 1240,
  "completion_tokens": 52
}

sources_used is a 0-indexed list of which sources the model cited. null means no citation footer was found.

POST /collections/<id>/query

Streaming response (Server-Sent Events). Best for UIs showing tokens as they arrive.

data: {"sources": [{"filename": "policy.md", "score": 0.91, "chunk": "..."}]}
data: {"token": "Refunds"}
data: {"token": " are"}
...
data: {"sources_used": [0]}
data: {"done": true}

POST /collections/<id>/query/deep

Deep Research: the server splits the question into sub-questions, retrieves for each, and synthesises a longer answer. Costs roughly 3× a standard query. Streams SSE events including per-step progress.

POST /collections/<id>/query/multilingual

Translates the question, retrieves in the source and English, and merges the results before answering. Streams SSE. The model field is ignored — multilingual runs on a server-pinned model.

Automatic cross-language answers

Create the API key with "allow_multilingual": true and /query and /query/sync decide per question: a question in a different language than the collection's documents (or any question on a collection with both English and Japanese documents) goes through the multilingual pipeline; a same-language question is answered normally at the normal cost. The documents' language is detected automatically, or set it yourself with PATCH /api/collections/<id>/language and {"language": "auto" | "en" | "ja" | "mixed"} (GET shows the setting and what was detected). A cross-language /query/sync response adds "cross_language": true and translated_query. Cross-language questions use the multilingual model, about 3–5× the credits of a standard query.

Sharing

Generate a public share link for a collection. Anyone with the link can ask questions; they cannot add, modify, or delete content.

GET /collections/<id>/share

Return the active share config, or null if none exists.

POST /collections/<id>/share

Create or update a share link. All fields optional:

{
  "model": "fast",               // tier name; null = server default
  "deep_research": false,        // let visitors run Deep Research
  "allow_download": false,       // let visitors download source files
                                 // (files marked downloadable:false stay blocked)
  "conversation": false,         // multi-turn chat with memory of earlier questions
  "sql_dive": false,             // SQL analysis over ingested CSV/Excel tables
  "monthly_spend_limit_usd": 0   // monthly credit cap for the link (0 = default)
}

DELETE /collections/<id>/share

Revoke the share link immediately.

Team

Invite teammates into your account. Each member gets their own login and can be granted their own API keys.

GET /account/members

List active members and pending invites.

POST /account/members/invite

Send an invite email. Body: {"email": "new@teammate.com"}.

DELETE /account/members/<user_id>

Remove a member from the account.

DELETE /account/invites/<invite_id>

Cancel a pending invite.

Account

GET /account/me

Return the principal tied to the current key (user id, email, account id, role).

GET /account/usage

Spend and query counts for the current billing month.

curl https://saachi.ai/account/usage \
  -H "Authorization: Bearer <api_key>"
# → {"used": 0.42, "limit": 10.0, "remaining": 9.58, "currency_label": "$",
#    "plan": "pro", "query_count_this_month": 38, ...}

Manage API keys

Creating, editing and revoking keys requires a team admin's signed-in session token (from /auth/login). API keys of any type get 403 on these three endpoints, so a leaked key can never mint another.

GET /account/keys

List existing keys (prefix, name, type, scope, limits, last-used timestamp). Raw key values are never returned again after creation.

POST /account/keys

curl -X POST https://saachi.ai/account/keys \
  -H "Authorization: Bearer <team_admin_session_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Production",
    "key_type": "admin",
    "scope": "account",
    "monthly_spend_limit_usd": 5.00,
    "default_model": "fast"
  }'
# → {"id": "...", "key": "sk-...", "monthly_spend_limit_usd": 5.0, ...}

For a collection-scoped key, send "scope": "collection" and "collection_ids": ["...","..."]. default_model takes a tier name (see Models).

Keys of type embed additionally accept feature flags controlling what the widget offers its visitors: allow_deep_research, allow_download, allow_conversation, allow_sql_dive (all default false). Any key type accepts allow_multilingual (default false) for automatic cross-language answers. Whether questions asked with a non-embed key are recorded is set per collection, on its Insights page (Recording settings → API keys), where an account admin ticks the keys to record; recorded questions are tagged with the key's name. The older track_questions field is still accepted on key creation but ignored. When a collection records your key, send an optional visitor_id (your own end-user id, up to 64 characters) with a query to count distinct users; only a one-way hash of it is stored. Note that even with allow_download on, individual files marked "downloadable": false stay blocked.

PATCH /account/keys/<key_id>

Update a key's monthly spend limit without rotating it. Body: {"monthly_spend_limit_usd": 10.0}.

DELETE /account/keys/<key_id>

Revoke a key. Subsequent requests using it return 401.

Models

Pass a model field in your query body to override the server default. Use one of the tier names below, not a raw provider model ID — which physical model backs each tier can change over time, so pinning a tier keeps working across those changes automatically.

TierNotes
fastDefault — fast and cheap, strong quality for most questions.
bestHighest quality, slower and more expensive.

Deep Research and Multilingual endpoints ignore the model field and use server-pinned models.

Errors

Errors return a JSON body: {"detail": "..."}.

StatusMeaning
401Missing, malformed, revoked, or expired key
402Account or key has hit its monthly spend cap — top up or raise the limit
403Key has no access to this collection, or a query-type key attempted a write
404Collection, folder, or file not found
413Uploaded payload exceeded the server limit
429Upstream model rate-limited you — retry with backoff