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

# Document reranking endpoint

> Ranks documents by relevance to a query using a reranker model.

**Concurrent Request Limits:** Each organization has a per-model concurrent request limit (default: 64).
When the limit is reached, new requests will fail with 429 status code. Wait for in-flight requests to complete before retrying.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/rerank
openapi: 3.1.0
info:
  title: NEAR AI Cloud API
  description: >-
    NEAR AI Cloud API for private AI model inference and organization
    administration.
  contact:
    name: NEAR AI Team
    email: support@near.ai
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://cloud-api.near.ai
    description: NEAR AI Cloud
security:
  - session_token: []
  - api_key: []
tags:
  - name: Chat
    description: Chat completion endpoints for AI model inference
  - name: Images
    description: Image generation endpoints
  - name: Audio
    description: Audio transcription endpoints
  - name: Rerank
    description: Document reranking endpoints
  - name: Score
    description: Text similarity scoring endpoints
  - name: Privacy
    description: Privacy classification (PII span detection) endpoints
  - name: Models
    description: Public model catalog and information
  - name: Responses
    description: >-
      Stateless response inference (`store: false` only). Raw request/response
      content, response items, and history are not persisted. Clients must
      include any prior context in each request. Every successful Responses
      inference makes exactly one Chat Completions call. Only custom `function`
      tools are supported. They are client-managed: Cloud returns
      `function_call` items but never executes them; a later `store: false`
      request replays the individual call (the raw item from output is accepted)
      with its matching `function_call_output`, alongside caller-managed message
      history and the same function tool definitions. The minimal replay path
      also accepts assistant `message` text parts of type `output_text`, but not
      reasoning or arbitrary full `response.output` items. Server-executed tools
      (`web_search`, `web_context_search`, `file_search`, `code_interpreter`,
      `computer`, and remote `mcp`) and image-generation/editing models are
      rejected. The separate `POST /mcp` endpoint continues to expose its
      `web_search` tool independently of Responses; use `/v1/images/*` for image
      generation/editing. Existing completed-response gateway attestation is
      preserved best-effort: when the signature write succeeds, `GET
      /v1/signature/resp_*` retrieves signatures over SHA-256 request/response
      digests, never raw content. Interrupted streams create no `resp_*`
      attestation record or legacy disconnect fallback. Conversations, response
      history, and file input are rejected.
  - name: Organizations
    description: Organization management
  - name: Organization Members
    description: Organization member and invitation management
  - name: Workspaces
    description: Workspace and API key management
  - name: Users
    description: User profile and token management
  - name: Invitations
    description: Token-based invitation handling
  - name: Usage
    description: Usage tracking and billing information
  - name: Reporting
    description: Read-only customer usage reporting
  - name: Billing
    description: Billing costs endpoint (HuggingFace integration)
  - name: Staking Farm
    description: House of Stake farm credit configuration and synchronization
  - name: Health
    description: Health check endpoints
  - name: Attestation
    description: Attestation and verification endpoints
  - name: Gateway
    description: Model gateway integration endpoints
  - name: Admin
    description: Administrative endpoints (admin access required)
  - name: Services
    description: Public platform services (e.g. web_search pricing)
paths:
  /v1/rerank:
    post:
      tags:
        - Rerank
      summary: Document reranking endpoint
      description: >-
        Ranks documents by relevance to a query using a reranker model.


        **Concurrent Request Limits:** Each organization has a per-model
        concurrent request limit (default: 64).

        When the limit is reached, new requests will fail with 429 status code.
        Wait for in-flight requests to complete before retrying.
      operationId: rerank
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RerankRequest'
        required: true
      responses:
        '200':
          description: Successful rerank
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RerankResponse'
        '400':
          description: Invalid request (empty documents, invalid model, etc.)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized (missing or invalid API key)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Model not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: >-
            Rate limited or overloaded — retry with backoff. Check error.type:
            rate_limit_exceeded or service_overloaded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Server error (billing failure, provider error)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    RerankRequest:
      type: object
      description: Request for document reranking
      required:
        - model
        - query
        - documents
      properties:
        documents:
          type: array
          items:
            type: string
          description: Documents to rerank
        model:
          type: string
          description: Model ID to use for reranking
        query:
          type: string
          description: Query to rerank documents against
        return_documents:
          type:
            - boolean
            - 'null'
          description: Whether to include document text in each result. Defaults to true.
        top_n:
          type:
            - integer
            - 'null'
          description: Maximum number of ranked results to return
          minimum: 0
    RerankResponse:
      type: object
      description: Response from document reranking
      required:
        - id
        - model
        - results
      properties:
        id:
          type: string
          description: Unique identifier for the rerank request
        model:
          type: string
          description: Model used for reranking
        results:
          type: array
          items:
            $ref: '#/components/schemas/RerankResult'
          description: Reranked results
        usage:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/RerankUsage'
              description: Usage information (optional)
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          $ref: '#/components/schemas/ErrorDetail'
    RerankResult:
      type: object
      description: Individual reranked result
      required:
        - index
        - relevance_score
      properties:
        document:
          description: The document (can be string or object depending on provider)
        index:
          type: integer
          format: int32
          description: Index of the document in the original input
        relevance_score:
          type: number
          format: double
          description: Relevance score (typically 0.0 to 1.0)
    RerankUsage:
      type: object
      description: Usage information for rerank request
      properties:
        prompt_tokens:
          type:
            - integer
            - 'null'
          format: int32
          description: Input tokens
        total_tokens:
          type:
            - integer
            - 'null'
          format: int32
          description: Total number of tokens used
    ErrorDetail:
      type: object
      required:
        - message
        - type
      properties:
        code:
          type:
            - string
            - 'null'
        message:
          type: string
        param:
          type:
            - string
            - 'null'
        type:
          type: string
  securitySchemes:
    session_token:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        JWT access token for user authentication (Authorization: Bearer
        <jwt_token>). Create via POST /users/me/access_tokens.
    api_key:
      type: http
      scheme: bearer
      bearerFormat: api_key
      description: 'API key for programmatic access (Authorization: Bearer sk-<api_key>)'

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.