API Documentation

Programmatic access to search, ask AI, and manage your indexed content.

Base URL: https://search.needle.tools

lock Authentication

Search and Ask are public — no token needed, but rate-limited. A Bearer token lifts the rate limit and unlocks the rest of the API.

LevelAuth MethodEndpoints
PublicNone — 10 requests/min per IPGET /api/documents, GET /api/semantic-search, POST /api/ask
BearerAuthorization: Bearer <token>GET /api/search, plus the public endpoints without the rate limit
AdminBasic Auth or Bearer tokenAll POST, PATCH, DELETE endpoints
DashboardBasic Auth only/dashboard

Bearer Token

curl -X POST https://search.needle.tools/api/ask \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_SECRET_KEY" \
  -d '{"question": "How do I get started?"}'

Set the API_SECRET_KEY env var to enable bearer token authentication.

search Search

Full-text search across all messages and documents.

If exact matching finds nothing, short keyword queries can use a bounded one-edit typo fallback over the indexed vocabulary. Advanced FTS expressions and words shorter than four letters keep exact matching.

Web pages are deduplicated across chunks and Needle Engine API versions. Use source to search one platform by name (for example, Needle Engine Docs). Add visibility=public to exclude hidden sources even with a bearer token. Source-filtered searches return platform messages, not uploaded documents.

GET https://search.needle.tools/api/search?q=YOUR_QUERY Bearer

Example

curl "https://search.needle.tools/api/search?q=help" \
  -H "Authorization: Bearer YOUR_TOKEN"

Response

{
  "messages": [
    {
      "id": "...",
      "content": "message text",
      "timestamp": "2024-01-01T00:00:00Z",
      "username": "user",
      "channelName": "general",
      "channelSlug": "general",
      "platformName": "My Server",
      "platformType": "discord"
    }
  ],
  "documents": [
    {
      "id": "...",
      "title": "Doc Title",
      "slug": "doc-title",
      "content": "full content..."
    }
  ]
}

manage_search Semantic Search

Embedding-based semantic search. Returns ranked results with full content — no LLM in the loop. Designed for MCP tools, CLI, and AI agents.

GET https://search.needle.tools/api/semantic-search?q=YOUR_QUERY&limit=10 Public

Parameters

ParamTypeDescription
qstringSearch query (required)
limitnumberMax results, 1-20 (default 10)
max_charsnumberMax content chars per result, 200-10000 (default 2000)
booststringPer-request source boosting: comma-separated sourceId:multiplier pairs, e.g. boost=SOURCE_ID:2,OTHER_ID:1.5. Multiplies each source's ranking score; 0.1–10, values below 1 demote. A bare id defaults to 2. Source ids are shown on the sources page.
hydestringSet hyde=0 to embed the query verbatim, skipping the HyDE hypothetical-answer step. Faster, and better for exact phrases or code identifiers; the default (on) is better for natural-language questions.

Example

curl "https://search.needle.tools/api/semantic-search?q=how+to+add+physics&limit=5"

No token required. Add -H "Authorization: Bearer YOUR_TOKEN" to lift the 10 requests/min rate limit.

Response

{
  "query": "how to add physics",
  "results": [
    {
      "type": "document",
      "score": 0.87,
      "title": "Physics Components",
      "source": "Needle Engine Docs",
      "content": "full text of the matched chunk...",
      "contentLength": 4820,
      "truncated": true,
      "url": "https://engine.needle.tools/docs/physics#:~:text=..."
    }
  ],
  "durationMs": 142
}

smart_toy Ask AI

Ask a question using AI with RAG over indexed content. Supports streaming (SSE) and plain JSON responses.

POST https://search.needle.tools/api/ask Public

Request body

{
  "question": "What is the main topic discussed?",
  "messages": [                          // optional — conversation history
    { "role": "user",      "content": "Previous question" },
    { "role": "assistant", "content": "Previous answer"  }
  ]
}

Streaming (SSE)

curl -X POST https://search.needle.tools/api/ask \
  -H "Content-Type: application/json" \
  -H "Accept: text/event-stream" \
  -d '{"question": "What is the main topic discussed?"}'

Events emitted:

data: {"type":"sources","sources":[...]}
data: {"type":"token","token":"Based "}
data: {"type":"token","token":"on the..."}
data: {"type":"done","usage":{"prompt_tokens":1420,"completion_tokens":312,"total_tokens":1732}}

JSON

curl -X POST https://search.needle.tools/api/ask \
  -H "Content-Type: application/json" \
  -d '{"question": "What is the main topic discussed?"}'
{
  "answer": "Based on the indexed content...",
  "sources": [
    {
      "type": "message",
      "score": 0.89,
      "metadata": "user in #general",
      "preview": "message preview...",
      "sourceUrl": "https://..."
    }
  ],
  "usage": { "prompt_tokens": 1420, "completion_tokens": 312, "total_tokens": 1732 }
}

terminal Machine-Readable

Plain text documentation for LLMs and AI agents.

https://search.needle.tools/llms.txt

Describes available endpoints, parameters, and auth in a format optimized for AI agents.