Skip to main content

Request

POST https://ninjachat.ai/api/v1/search
Authorization: Bearer nj_sk_YOUR_API_KEY
Content-Type: application/json
{
  "query": "latest developments in AI safety",
  "include_answer": true,
  "max_results": 10
}

Response

{
  "query": "latest developments in AI safety",
  "answer": "Recent developments in AI safety include...",
  "sources": [
    {
      "url": "https://example.com/article",
      "title": "AI Safety Progress in 2026",
      "content": "Summary of the article...",
      "published_date": "2026-03-01"
    }
  ],
  "follow_up_questions": [
    "What are the key AI safety organizations?",
    "How does RLHF improve AI safety?"
  ],
  "images": [],
  "cost": { "this_request": "$0.05" },
  "metadata": {
    "group": "web",
    "search_depth": "basic",
    "results_count": 10,
    "latency_ms": 2341
  }
}
The AI answer is in answer. Sources are in sources[].

Parameters

ParameterTypeRequiredDefaultDescription
querystringYesSearch query. Max 2,000 chars.
groupstringNowebweb, academic, or news
max_resultsintegerNo10Number of sources (1–20)
search_depthstringNobasicbasic (fast) or advanced (deeper)
topicstringNogeneralgeneral, news, or finance
include_answerbooleanNotrueGenerate an AI-synthesized answer
include_imagesbooleanNofalseInclude image results

Full working example

import os, requests

HEADERS = {"Authorization": f"Bearer {os.environ['NINJACHAT_API_KEY']}"}

def search(query, group="web", depth="basic"):
    r = requests.post("https://ninjachat.ai/api/v1/search",
        headers=HEADERS,
        json={
            "query": query,
            "group": group,
            "search_depth": depth,
            "include_answer": True,
        }
    )
    r.raise_for_status()
    return r.json()

# Web search
result = search("best Python web frameworks 2026")
print(result["answer"])
for src in result["sources"][:3]:
    print(f"  - {src['title']}: {src['url']}")

# Academic search
result = search("transformer architecture improvements", group="academic")
print(result["answer"])

# News search
result = search("AI regulation", group="news")
print(result["answer"])
Not ready to write code? Try this in the API Playground →

Search groups

GroupWhat it searchesUse for
webGeneral webDefault. Most use cases.
academicAcademic papers, researchRAG, research tools, citations
newsRecent news articlesNews aggregation, current events

Use with RAG

Combine search with chat for retrieval-augmented generation:
# 1. Search for context
results = search("What is quantum computing?")

# 2. Feed to a chat model with sources as context
context = "\n".join(f"- {s['title']}: {s['content']}" for s in results["sources"][:5])

r = requests.post("https://ninjachat.ai/api/v1/chat",
    headers=HEADERS,
    json={
        "model": "gpt-5",
        "messages": [
            {"role": "system", "content": f"Answer using these sources:\n{context}"},
            {"role": "user", "content": "Explain quantum computing with citations"},
        ]
    }
)
print(r.json()["message"]["content"])