> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ravan.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Upsert Document

> Upsert Document.

### Authorizations

<ParamField header="X-Api-Key" type="string" required>
  Your Agni API key used to authenticate the request. Pass it in the `X-Api-Key` header. Find or rotate it from your Ravan AI account settings.
</ParamField>

***

### Body

<ParamField body="org_id" type="string" required>
  The organization ID that owns the resource. Use the organization ID from your Agni account.
</ParamField>

<ParamField body="kb_id" type="string" required>
  The unique knowledge base ID. Use the ID returned by the knowledge base create or list endpoint.
</ParamField>

<ParamField body="doc_id" type="string" required>
  The unique document ID in the knowledge base. Use a stable ID so later upserts update the same document.
</ParamField>

<ParamField body="text" type="string">
  The text content to ingest, search, or store, depending on the endpoint.
</ParamField>

<ParamField body="url" type="string">
  A publicly reachable URL. Include the full protocol, for example `https://example.com/docs`.
</ParamField>

<ParamField body="urls" type="string[]">
  A list of publicly reachable URLs. Include the full protocol for each URL.
</ParamField>

<ParamField body="max_pages" type="integer">
  The maximum number of pages to crawl or ingest from the provided URL sources.
</ParamField>

<ParamField body="max_depth" type="integer">
  The maximum crawl depth when discovering or ingesting URLs. Higher values can include more nested pages.
</ParamField>

<ParamField body="metadata" type="object">
  Custom key-value data to attach to the resource. Use this for IDs or attributes from your own systems.
</ParamField>

***

### Response

<ResponseField name="success" type="boolean">
  Whether the request succeeded.
</ResponseField>

<ResponseField name="message" type="string">
  Human-readable status message.
</ResponseField>

<ResponseField name="data" type="object">
  Returned data.

  <Expandable title="data">
    <ResponseField name="doc_id" type="string">
      Document ID
    </ResponseField>

    <ResponseField name="kb_id" type="string">
      Knowledge Base ID
    </ResponseField>

    <ResponseField name="status" type="string">
      Document status
    </ResponseField>

    <ResponseField name="created_at" type="string">
      Creation timestamp
    </ResponseField>
  </Expandable>
</ResponseField>


## OpenAPI

````yaml POST /api/v1/rag/document
openapi: 3.0.1
info:
  title: Agni API
  version: 1.0.0
  description: >-
    Agni API for managing agents, tools, widget settings, telephony, and
    integrations.
servers:
  - url: https://api.ravan.ai
security:
  - X-Api-Key: []
tags:
  - name: AgentService
  - name: AgentToolService
  - name: WidgetSettingsService
  - name: PhoneService
  - name: AppointmentService
  - name: GHLService
  - name: CalComService
  - name: CampaignService
  - name: ContactService
  - name: CallingService
  - name: RAGService
  - name: ModelService
  - name: HealthService
paths:
  /api/v1/rag/document:
    post:
      tags:
        - RAGService
      summary: Upsert Document
      operationId: UpsertRAGDocument
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpsertRAGDocumentRequest'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetRAGDocumentResponse'
components:
  schemas:
    UpsertRAGDocumentRequest:
      type: object
      required:
        - org_id
        - kb_id
        - doc_id
      properties:
        org_id:
          type: string
          description: Organization ID
        kb_id:
          type: string
          description: Knowledge Base ID
        doc_id:
          type: string
          description: Document ID
        text:
          type: string
          description: Document text content
        url:
          type: string
          description: URL to crawl
        urls:
          type: array
          items:
            type: string
          description: Multiple URLs to crawl
        max_pages:
          type: integer
          description: Max pages to crawl
        max_depth:
          type: integer
          description: Max crawl depth
        metadata:
          type: object
          description: Document metadata
    GetRAGDocumentResponse:
      type: object
      properties:
        success:
          type: boolean
        message:
          type: string
        data:
          $ref: '#/components/schemas/RAGDocument'
    RAGDocument:
      type: object
      properties:
        doc_id:
          type: string
          description: Document ID
        kb_id:
          type: string
          description: Knowledge Base ID
        org_id:
          type: string
          description: Organization ID
        text:
          type: string
          description: Document text content
        url:
          type: string
          description: Source URL
        status:
          type: string
          description: Document status
        metadata:
          type: object
          description: Document metadata
        created_at:
          type: string
          description: Creation timestamp
        updated_at:
          type: string
          description: Last update timestamp
  securitySchemes:
    X-Api-Key:
      type: apiKey
      in: header
      name: X-Api-Key

````