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

# Rerank documents



## OpenAPI

````yaml /openapi.json post /rerank
openapi: 3.1.0
info:
  title: NinjaChat API
  version: 1.0.0
  description: >-
    Clean-break NinjaChat v1. Chat and Responses bill actual token usage; images
    and videos use catalog unit pricing.
servers:
  - url: https://www.ninjachat.ai/api/v1
security: []
paths:
  /rerank:
    post:
      summary: Rerank documents
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RerankRequest'
      responses:
        '200':
          description: Document relevance and metered usage.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RerankResponse'
        '400':
          description: Invalid or unsupported request parameter.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Missing or invalid API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '402':
          description: Insufficient balance or project spend limit reached.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: Rate limit exceeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Gateway error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - bearerAuth: []
components:
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      schema:
        type: string
        minLength: 1
        maxLength: 255
      description: >-
        Safely retry the same logical write without duplicate billing or
        execution.
  schemas:
    RerankRequest:
      type: object
      properties:
        model:
          type: string
          enum:
            - rerank-2.5
            - rerank-2.5-lite
        query:
          type: string
          minLength: 1
        documents:
          type: array
          items:
            type: string
            minLength: 1
          minItems: 1
          maxItems: 1000
        top_n:
          type: integer
          exclusiveMinimum: 0
        return_documents:
          type: boolean
          default: false
        truncation:
          type: boolean
          default: false
      required:
        - model
        - query
        - documents
      additionalProperties: false
    RerankResponse:
      type: object
      properties:
        model:
          type: string
        provider:
          type: string
        results:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
                minimum: 0
              relevance_score:
                type: number
              document:
                type: object
                properties:
                  text:
                    type: string
                required:
                  - text
            required:
              - index
              - relevance_score
        usage:
          type: object
          properties:
            total_tokens:
              type: integer
              minimum: 0
          required:
            - total_tokens
        cost_usd:
          type: number
          minimum: 0
        request_id:
          type: string
      required:
        - model
        - provider
        - results
        - usage
        - cost_usd
        - request_id
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            code:
              type: string
            param:
              type:
                - string
                - 'null'
          required:
            - message
            - type
            - code
          additionalProperties: false
      required:
        - error
      additionalProperties: false
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: NinjaChat API key
      description: Use an API key created in the NinjaChat developer console.

````