openapi: '3.0.0'
info:
  version: '0.1.1'
  title: 'OpenIndex.ai API'
  description: Run your RAG app on OpenIndex.ai. Create document collections, agents and chat with them.
servers:
  - url: https://www.openindex.ai/api
paths:
  /chat:
    get:
      summary: Retrieve user chats
      parameters:
        - in: query
          name: limit
          required: false
          schema:
            type: integer
          description: The number of chats to return.
        - in: query
          name: start_after
          required: false
          schema:
            type: integer
          description: The timestamp to start after.
        - in: query
          name: collection_id
          required: false
          schema:
            type: string
          description: The ID of the collection.
        - in: query
          name: agent_id
          required: false
          schema:
            type: string
          description: The ID of the agent. If no agent_id or collection_id is specified, the default agent "Jack Of All Trades" will be used.
        - in: query
          name: include_empty
          required: false
          schema:
            type: boolean
          description: Whether to include empty chats with collections and agents created by the user.
      responses:
        '200':
          description: A list of chats.
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                  chats:
                    type: array
                    items:
                      $ref: '#/components/schemas/Chat'
    post:
      summary: Send a message to an AI agent or collection.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatRequest'
      responses:
        '200':
          description: The response to the message from the language model.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatResponse'
        '403':
          description: Exceeded daily chat allowance.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Error running the language model.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /agents:
    get:
      summary: Retrieve agents authored by the user.
      responses:
        '200':
          description: A list of agents
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                  agents:
                    type: array
                    items:
                      $ref: '#/components/schemas/Agent'
    post:
      summary: Create or update an agent
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AgentRequest'
      responses:
        '200':
          description: The result of the agent creation or update.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentResponse'
        '400':
          description: Invalid name or description.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Exceeded agent allowance.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Error creating or updating agent.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /collections:
    get:
      summary: Retrieve user collections.
      responses:
        '200':
          description: A list of collections.
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                  collections:
                    type: array
                    items:
                      $ref: '#/components/schemas/Collection'
    post:
      summary: Create or update a collection.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CollectionRequest'
      responses:
        '200':
          description: The result of the collection creation or update.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CollectionResponse'
        '400':
          description: Invalid request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Exceeded collection allowance.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /collections/search:
    get:
      summary: Search collections
      parameters:
        - in: query
          name: q
          required: true
          schema:
            type: string
          description: The query to search for.
        - in: query
          name: limit
          required: false
          schema:
            type: integer
          description: The number of results to return.
        - in: query
          name: collection_id
          required: false
          schema:
            type: string
          description: You can restrict the search to a specific collection by passing its ID.
      responses:
        '200':
          description: A list of collections.
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                  results:
                    type: array
                    items:
                      $ref: '#/components/schemas/SearchResult'
components:
  schemas:
    ModelName:
      type: string
      description: Name of the LLM model to use.
      enum:
        - gpt-3.5-turbo
        - gpt-3.5-turbo-16k
        - gpt-4
        - palm-2
        - llama-2-13b-chat
        - llama-2-70b-chat
        - codellama-13b-instruct
        - codellama-13b-python
        - mistral-7b
        - zephyr-7b
        - mistrallite-7b
        - llava-13b
        - fuyu-8b
        - causallm-14b
    ModelParameters:
      type: object
      description: Model parameters
      properties:
        temperature:
          type: number
          description: model temperature between 0 and 1.0
        topP:
          type: number
        frequencePenalty:
          type: number
        presencePenalty:
          type: number
    Tool:
      type: object
      properties:
        id:
          type: string
        checked:
          type: boolean
          description: "Set to true if you want to include the tool as a plugin to the LLM call"
    Source:
      type: object
      properties:
        id: 
          type: string
        name: 
          type: string
        embedded: 
          type: boolean
        error: 
          type: string
        lastIndexed: 
          type: integer
        mimeType: 
          type: string
        size: 
          type: integer
        type:
          type: string
          enum:
            - web
            - upload
        url: 
          type: string
    Privacy:
      type: string
      enum:
        - public
        - private
        - team
    Chat:
      type: object
      required:
        - id
        - userId
      properties:
        id:
          type: string
        userId:
          type: string
        createdAt:
          type: integer
        updatedAt:
          type: integer
        agentId:
          type: string
        collectionId:
          type: string
        status:
          type: string
        current:
          type: array
          items:
            type: object
        auto:
          type: object
        tools:
          type: array
          items:
            $ref: "#/components/schemas/Tool"
    ChatRequest:
      type: object
      properties:
        chatId:
          type: string
          description: Enter null to create a new conversation or an existing chatId to continue a conversation
        agentId:
          type: string
        collectionId:
          type: string
        message:
          type: string
        streaming:
          type: boolean
        tools:
          type: array
          items:
            $ref: "#/components/schemas/Tool"
        model:
          $ref: "#/components/schemas/ModelName"
          description: Override the model to use for this reply among the list of supported models.
        lastUploadedFile:
          type: string
          description: Publicly accessible URL of the last uploaded file. Typically used to feed an image to a multi-modal model.
        language:
          type: string
          default: en
          description: 2-letter ISO code of the language the model should use to reply.
    ChatResponse:
      type: object
      properties:
        ok:
          type: boolean
        message:
          type: string
        error:
          type: string
        sources:
          type: array
          items:
            type: string
        followup:
          type: object
        context:
          type: object
        chatId:
          type: string
        agentId:
          type: string
        collectionId:
          type: string
    Agent:
      type: object
      properties:
        id:
          type: string
        slug:
          type: string
        name:
          type: string
        description:
          type: string
        image:
          type: string
        privacy:
          type: string
        namespace:
          type: string
        prompt:
          type: string
        isAutonomous:
          type: boolean
        welcome:
          type: string
        model:
          $ref: "#/components/schemas/ModelName"
        params:
          $ref: "#/components/schemas/ModelParameters"
        tools:
          type: array
          items:
            $ref: "#/components/schemas/Tool"
        userId:
          type: string
        createdAt:
          type: integer
        updatedAt:
          type: integer
        status:
          type: string
        collections:
          type: array
          items:
            type: string
    AgentRequest:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        description:
          type: string
        image:
          type: string
        privacy:
          $ref: "#/components/schemas/Privacy"
        isAutonomous:
          type: boolean
        prompt:
          type: string
        welcome:
          type: string
        model:
          $ref: "#/components/schemas/ModelName"
        params:
          $ref: "#/components/schemas/ModelParameters"
        tools:
          type: array
          items:
            $ref: "#/components/schemas/Tool"
        collections:
          type: array
          items:
            type: string
    AgentResponse:
      type: object
      properties:
        ok:
          type: boolean
        agentId:
          type: string
    Collection:
      type: object
      properties:
        id:
          type: string
        slug:
          type: string
        userId:
          type: string
        active:
          type: boolean
        createdAt:
          type: integer
        updatedAt:
          type: integer
        name:
          type: string
        description:
          type: string
        image:
          type: string
        privacy:
          $ref: "#/components/schemas/Privacy"
        namespace:
          type: string
        sources:
          type: array
          items:
            $ref: "#components/schemas/Source"
        status:
          type: string
    CollectionRequest:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        description:
          type: string
        image:
          type: string
        privacy:
          $ref: "#/components/schemas/Privacy"
        knowledgeBase:
          type: string
          description: A list of URLs (one per row) to add to the collection. YouTube URLs will be transcripted. Use links(url) to index the direct links at url.
    CollectionResponse:
      type: object
      properties:
        ok:
          type: boolean
        collectionId:
          type: string
    SearchResult:
      type: object
      properties:
        snippet:
          type: string
          description: The text snippet that is relevant to the query.
        url:
          type: string
          description: The url of the document you can use as source.
        sourceId:
          type: string
        source:
          type: string
          enum: 
            - web
            - upload
        collection:
          $ref: '#/components/schemas/Collection'
        score:
          type: number
          description: The relevance score of the result between 0 and 1. Higher is better.
    Error:
      type: object
      properties:
        ok:
          type: boolean
        error:
          type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
security:
  - bearerAuth: []