Skip to main content
POST
https://api.moorcheh.ai
/
v1
/
answer
curl -X POST "https://api.moorcheh.ai/v1/answer" \
  -H "Content-Type: application/json" \
  -H "x-api-key: your-api-key-here" \
  -d '{
    "namespace": "my-document-collection",
    "query": "What are the main benefits of Moorcheh?",
    "type": "text",
    "top_k": 5
  }'
{
  "answer": "Serverless architecture offers several benefits, including reduced operational costs as you only pay for what you use, automatic scaling to handle workload changes, and faster time-to-market since developers can focus on code instead of infrastructure management.",
  "model": "anthropic.claude-sonnet-4-5-20250929-v1:0",
  "contextCount": 3,
  "query": "What are the main benefits of using serverless architecture?"
}

Overview

Generate AI-powered answers to questions with two modes: Search Mode (with namespace) and Direct AI Mode (empty namespace). The API supports context-aware generation using your data or direct AI model calls.
Supports multiple AI models including Claude 3.7 Sonnet, Claude Sonnet 4, Llama 4 Maverick, and DeepSeek-R1. Use empty string "" as namespace for direct AI calls.

Authentication

x-api-key
string
required
Your API key for authentication
Content-Type
string
required
Must be application/json

Body Parameters

query
string
required
The user’s question or query to be answered
namespace
string
required
Namespace name for Search Mode, or empty string "" for Direct AI Mode
top_k
number
Number of top relevant chunks for your query across given namespace. Default is 10.
threshold
number
Minimum relevance score threshold (0-1) to filter out chunks below this relevance level. Required when kiosk_mode is true.
temperature
number
AI creativity level (0.0-2.0, default: 0.7). Higher = more creative
type
string
Search type: “text” (default)
aiModel
string
AI model ID (see Available Models table below)
kiosk_mode
boolean
Enable kiosk mode to filter chunks below certain relevance. When kiosk mode is on, threshold is required.
chatHistory
array
Previous conversation turns for context (default: [])
headerPrompt
string
Custom instruction for AI behavior
Custom instruction to append (default: “Provide a clear and concise answer.”)
structuredResponse
object
When set with enabled: true, the API returns a JSON object in structuredData matching a schema (default or custom). Optional: schema, toolName, toolDescription. See Structured Output below.

Available Models

Model IDNameProviderDescriptionCredits
anthropic.claude-sonnet-4-20250514-v1:0Claude Sonnet 4AnthropicHybrid reasoning, extended thinking, efficient code generation3
anthropic.claude-sonnet-4-5-20250929-v1:0Claude Sonnet 4.5AnthropicLatest Claude model with enhanced capabilities and agentic search3
anthropic.claude-opus-4-5-20251101-v1:0Claude Opus 4.5AnthropicMost advanced Claude model with superior reasoning and extended thinking capabilities3
meta.llama4-maverick-17b-instruct-v1:0Llama 4 Maverick 17BMeta1M token context, fine tuning, text summarization, function calling3
meta.llama3-3-70b-instruct-v1:0Llama 3.3 70BMetaAdvanced reasoning and decision making capabilities1
amazon.nova-pro-v1:0Amazon Nova ProAmazon300K context, chat optimized, complex reasoning, math2
deepseek.r1-v1:0DeepSeek R1DeepSeekAdvanced reasoning and code generation1
openai.gpt-oss-120b-1:0OpenAI GPT OSS 120BOpenAIHybrid reasoning, extended thinking, efficient research3
qwen.qwen3-32b-v1:0Qwen 3 32BQwenText generation and code generation2

Field Restrictions

Empty Namespace Mode: Only these fields are allowed: namespace, query, temperature, chatHistory, footerPrompt, headerPrompt, aiModel, structuredResponseProvided Namespace Mode: All fields are allowed: namespace, query, top_k, threshold, type, kiosk_mode, aiModel, chatHistory, headerPrompt, footerPrompt, temperature, structuredResponse
curl -X POST "https://api.moorcheh.ai/v1/answer" \
  -H "Content-Type: application/json" \
  -H "x-api-key: your-api-key-here" \
  -d '{
    "namespace": "my-document-collection",
    "query": "What are the main benefits of Moorcheh?",
    "type": "text",
    "top_k": 5
  }'
{
  "answer": "Serverless architecture offers several benefits, including reduced operational costs as you only pay for what you use, automatic scaling to handle workload changes, and faster time-to-market since developers can focus on code instead of infrastructure management.",
  "model": "anthropic.claude-sonnet-4-5-20250929-v1:0",
  "contextCount": 3,
  "query": "What are the main benefits of using serverless architecture?"
}

Response Fields

answer
string
The AI-generated answer based on the provided context and query
model
string
The ID of the AI model used to generate the answer
contextCount
number
Number of context chunks retrieved and used for generating the answer
query
string
The original query that was submitted
usedContext
boolean
When structured output is enabled: whether retrieved context was used (RAG vs Direct AI). Omitted when structuredResponse is not used.
structuredData
object
When structuredResponse.enabled is true: the JSON object matching your schema (or the default). Contains e.g. answer, confidence, sources, summary, topics, followUpQuestions. Omitted otherwise.

Structured Output

Include structuredResponse: { enabled: true } in the request to get a type-safe JSON object in structuredData instead of (or in addition to) the plain answer string. Works in both Search Mode and Direct AI Mode.

Enabling

{
  "namespace": "my-namespace",
  "query": "What are the main benefits of product X?",
  "structuredResponse": { "enabled": true }
}
With only enabled: true, the default schema is used.

structuredResponse fields

FieldTypeRequiredDefaultDescription
enabledbooleanYesMust be true to enable structured output.
schemaobjectNo(default schema)JSON Schema for the structured object. Omit or null to use the default.
toolNamestringNo"structured_response"Internal tool name for structured output.
toolDescriptionstringNo"Generate a structured response based on the user's query and provided context"Description for the model.

Default schema

If schema is omitted or null, the default schema is used:
{
  "type": "object",
  "properties": {
    "answer": {
      "type": "string",
      "description": "The main answer to the user's query"
    },
    "confidence": {
      "type": "number",
      "description": "Confidence score from 0 to 1 indicating how confident the model is in the answer",
      "minimum": 0,
      "maximum": 1
    },
    "sources": {
      "type": "array",
      "description": "List of source references used to generate the answer",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "The identifier of the source document/chunk"
          },
          "relevance": {
            "type": "string",
            "description": "How relevant this source was to the answer",
            "enum": ["high", "medium", "low"]
          }
        },
        "required": ["id"]
      }
    },
    "summary": {
      "type": "string",
      "description": "A brief summary of the answer (max 200 characters)",
      "maxLength": 200
    },
    "topics": {
      "type": "array",
      "description": "Key topics or themes identified in the query/answer",
      "items": { "type": "string" }
    },
    "followUpQuestions": {
      "type": "array",
      "description": "Suggested follow-up questions the user might want to ask",
      "items": { "type": "string" }
    }
  },
  "required": ["answer", "confidence"]
}
  • Required: answer, confidence
  • Optional: sources, summary, topics, followUpQuestions

Custom schema

Pass your own JSON Schema in structuredResponse.schema. Use type, properties, required, items, enum, minimum, maximum, maxLength, etc. Keep required minimal so the model can fill all fields.
{
  "namespace": "docs",
  "query": "What is the return policy?",
  "structuredResponse": {
    "enabled": true,
    "schema": {
      "type": "object",
      "properties": {
        "answer": { "type": "string" },
        "risk_level": { "type": "string", "enum": ["low", "medium", "high"] }
      },
      "required": ["answer", "risk_level"]
    }
  }
}

Structured output errors

SituationHTTPNotes
enabled not trueNormal text response; no structuredData.
Invalid structuredResponse or disallowed body field400Rejected by validation.
Model does not return structured data500"Error generating structured AI response: Model did not return structured data via tool use".

API Modes

Search Mode (with namespace)

When you provide a namespace, the API searches your data for relevant context and uses it to generate contextual answers.

Direct AI Mode (empty namespace)

When you pass an empty string "" as namespace, the API makes a direct call to the AI model without searching your data.

Temperature Guide

  • 0.0-0.5: Conservative, factual responses - best for technical documentation
  • 0.5-1.0: Balanced creativity - good for general Q&A
  • 1.0-2.0: More creative and varied responses - use carefully for factual content

Relevance Score Threshold

Results are scored using Information Theoretic Similarity (ITS), providing nuanced relevance measurements:
LabelScore RangeDescription
Close Matchscore ≥ 0.894Near-perfect relevance to the query
Very High Relevance0.632 ≤ score < 0.894Strongly related content
High Relevance0.447 ≤ score < 0.632Significantly related content
Good Relevance0.316 ≤ score < 0.447Moderately related content
Low Relevance0.224 ≤ score < 0.316Minimally related content
Very Low Relevance0.1 ≤ score < 0.224Barely related content
Irrelevantscore < 0.1No meaningful relation to the query

Important Notes

  • Search Mode: The namespace must exist and contain indexed data for meaningful results
  • Search Mode: Higher top_k values provide more context but may increase response time
  • Search Mode: The threshold parameter can be used to filter low-relevance results
  • Direct AI Mode: Use empty string "" as namespace for direct AI model calls
  • Field Restrictions: Empty namespace mode only allows basic AI fields, not search-specific fields
  • Field Restrictions: Provided namespace mode allows all fields including search parameters
  • Chat history enables conversational context across multiple queries
  • Custom prompts allow fine-tuning of AI behavior and response format
  • Temperature controls creativity: 0.0 for deterministic, 2.0 for highly creative responses
  • Failed requests still count towards usage limits and are tracked in statistics
  • Some models may have different token limits and capabilities

Use Cases

  • Customer Support: Answer customer questions using your documentation
  • Internal Q&A: Help employees find answers in company knowledge bases
  • Educational Tools: Create AI tutors using educational content
  • Research Assistance: Get insights from research papers and publications
  • Technical Support: Provide technical answers based on documentation
  • Content Creation: Generate content based on existing materials