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

# Rank Code

> Assess the relevance of each file in your codebase to a user's query.



## OpenAPI

````yaml POST /v2/code/rank
openapi: 3.0.1
info:
  title: Relace API
  description: API for accessing Relace code generation models.
  version: 1.0.0
  license:
    name: MIT
servers:
  - url: https://instantapply.endpoint.relace.run
    description: Server for code application endpoints
  - url: https://ranker.endpoint.relace.run
    description: Server for code ranking endpoints
  - url: https://embeddings.endpoint.relace.run
    description: Server for code embedding endpoints
  - url: https://api.relace.run
    description: Server for general infrastructure
security:
  - bearerAuth: []
paths:
  /v2/code/rank:
    post:
      description: Assess the relevance of each file in your codebase to a user's query.
      requestBody:
        description: Query and codebase context for relevance scoring
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CodeRerankerRequest'
            example:
              query: >-
                Optimize the search function for better performance with large
                arrays
              codebase:
                - filename: src/search.ts
                  content: >-
                    function findItem(array: Item[], targetId: string): Item |
                    undefined {\n  for (let i = 0; i < array.length; i++) {\n   
                    const item = array[i];\n    if (item.id === targetId)
                    {\n      return item;\n}\n}\n  return undefined;\n}
              token_limit: 100000
      responses:
        '200':
          description: Codebase reranked successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/v2CodeRerankerResponse'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error400'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error401'
        '404':
          description: API key not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error404'
        '429':
          description: Rate limit exceeded
          headers:
            X-RateLimit-Limit:
              schema:
                type: string
              description: Rate limit ceiling for the API key
            X-RateLimit-Remaining:
              schema:
                type: string
              description: Number of requests left for the time window
            X-RateLimit-Reset:
              schema:
                type: string
              description: Time at which the rate limit resets
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error429'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error500'
      servers:
        - url: https://ranker.endpoint.relace.run
components:
  schemas:
    CodeRerankerRequest:
      type: object
      required:
        - query
        - codebase
        - token_limit
      properties:
        query:
          type: string
          description: The natural language query describing the problem to solve
        codebase:
          type: array
          description: >-
            An array of files with their content, providing context for the
            query
          items:
            $ref: '#/components/schemas/CodeFile'
        token_limit:
          type: integer
          description: Maximum token limit for the response
          default: 100000
        relace_metadata:
          type: object
          description: >-
            Optional metadata for logging and tracking purposes. Removed before
            forwarding to origin server.
          additionalProperties: true
    v2CodeRerankerResponse:
      type: object
      properties:
        results:
          type: array
          description: Array of files ranked by relevance to the query, with their scores
          items:
            type: object
            properties:
              filename:
                type: string
                description: The name of the file including its path
              score:
                type: number
                description: The relevance score for this file (between 0 and 1)
                format: float
            required:
              - filename
              - score
          example:
            - filename: src/search.ts
              score: 0.953125
        usage:
          type: object
          properties:
            total_tokens:
              type: integer
              description: Total number of tokens used
              example: 96
          description: Token usage information for the request
    Error400:
      type: object
      properties:
        error:
          type: string
          description: Error message
          example: Invalid JSON in request body
    Error401:
      type: object
      properties:
        error:
          type: string
          description: Error message
          example: Authorized header required
    Error404:
      type: object
      properties:
        error:
          type: string
          description: Error message
          example: 'Bad Request: Route not found'
    Error429:
      type: object
      properties:
        error:
          type: string
          description: Error message
          example: Rate limit exceeded
    Error500:
      type: object
      properties:
        error:
          type: string
          description: Error message
          example: Error fetching from origin server
    CodeFile:
      type: object
      required:
        - filename
        - content
      properties:
        filename:
          type: string
          description: The name of the file including its path
        content:
          type: string
          description: The content of the file
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Relace API key Authorization header using the Bearer scheme.

````