Contextual AI Documents API

Ingest and manage documents within a datastore.

Documentation

Specifications

Other Resources

OpenAPI Specification

contextual-ai-documents-api-openapi.yml Raw ↑
openapi: 3.0.1
info:
  title: Contextual AI Platform Agents Documents API
  description: REST API for the Contextual AI enterprise RAG platform. Provides agents (create / query grounded RAG agents), datastores and documents (ingest and manage the knowledge corpus), and standalone component APIs - Generate (grounded generation with the GLM), Rerank (instruction-following reranker), Parse (document parsing into AI-ready markdown), and LMUnit (natural-language unit-test evaluation). All endpoints authenticate with a Bearer API key.
  termsOfService: https://contextual.ai/terms-of-service/
  contact:
    name: Contextual AI Support
    url: https://docs.contextual.ai
    email: support@contextual.ai
  version: '1.0'
servers:
- url: https://api.contextual.ai/v1
  description: Contextual AI production API
security:
- bearerAuth: []
tags:
- name: Documents
  description: Ingest and manage documents within a datastore.
paths:
  /datastores/{datastore_id}/documents:
    post:
      operationId: ingestDocument
      tags:
      - Documents
      summary: Ingest Document
      description: Ingest a document (PDF, HTML, DOC(X), PPT(X), PNG, JPG/JPEG) into a datastore. The document is parsed and chunked for retrieval.
      parameters:
      - $ref: '#/components/parameters/DatastoreId'
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
              - file
              properties:
                file:
                  type: string
                  format: binary
                  description: Binary file to ingest.
                metadata:
                  type: string
                  description: Stringified JSON with a custom_metadata object (max 15 fields, <= 2 KB encoded).
                configuration:
                  type: string
                  description: Stringified JSON overriding datastore settings for this document.
      responses:
        '200':
          description: Document accepted for ingestion.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IngestDocumentResponse'
        '422':
          $ref: '#/components/responses/ValidationError'
    get:
      operationId: listDocuments
      tags:
      - Documents
      summary: List Documents
      parameters:
      - $ref: '#/components/parameters/DatastoreId'
      - name: cursor
        in: query
        required: false
        schema:
          type: string
      - name: limit
        in: query
        required: false
        schema:
          type: integer
      responses:
        '200':
          description: A list of documents.
        '422':
          $ref: '#/components/responses/ValidationError'
  /datastores/{datastore_id}/documents/{document_id}:
    delete:
      operationId: deleteDocument
      tags:
      - Documents
      summary: Delete Document
      parameters:
      - $ref: '#/components/parameters/DatastoreId'
      - name: document_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      responses:
        '200':
          description: Document deleted.
        '422':
          $ref: '#/components/responses/ValidationError'
components:
  schemas:
    HTTPValidationError:
      type: object
      properties:
        detail:
          type: array
          items:
            $ref: '#/components/schemas/ValidationErrorDetail'
    IngestDocumentResponse:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: ID of the document being ingested.
    ValidationErrorDetail:
      type: object
      properties:
        loc:
          type: array
          items:
            oneOf:
            - type: string
            - type: integer
        msg:
          type: string
        type:
          type: string
  responses:
    ValidationError:
      description: Validation error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/HTTPValidationError'
  parameters:
    DatastoreId:
      name: datastore_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: ID of the datastore.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Contextual AI API key supplied as a Bearer token.