---
title: "Rerank API (v1)"
method: POST
path: "/v1/rerank"
---

# Rerank API (v1)

`POST /v1/rerank`

This endpoint takes in a query and a list of texts and produces an ordered array with each text assigned a relevance score.

## Headers

- `X-Client-Name` string

## Request body

- object
  - `model` string — The identifier of the model to use, eg `rerank-v3.5`.
  - `query` string, required — The search query
  - `documents` union[], required — A list of document objects or strings to rerank. If a document is provided the text fields is required and all other fields will be preserved in the response. The total max chunks (length of documents * max_chunks_per_doc) must be less than 10000. We recommend a maximum of 1,000 documents for optimal endpoint performance.
    - union
      - string
      - RerankDocument
        - `text` string, required — The text of the document to rerank.
  - `top_n` integer — The number of most relevant documents or indices to return, defaults to the length of the documents
  - `rank_fields` string[] — If a JSON object is provided, you can specify which keys you would like to have considered for reranking. The model will rerank based on order of the fields passed in (i.e. rank_fields=['title','author','text'] will rerank using the values in title, author, text sequentially. If the length of title, author, and text exceeds the context length of the model, the chunking will not re-consider earlier fields). If not provided, the model will use the default text field for ranking.
  - `return_documents` boolean — - If false, returns results without the doc text - the api will return a list of {index, relevance score} where index is inferred from the list passed into the request. - If true, returns results with the doc text passed in - the api will return an ordered list of {index, text, relevance score} where index + text refers to the list passed into the request.
  - `max_chunks_per_doc` integer — The maximum number of chunks to produce internally from a document

## Response `200`

OK

- object
  - `id` string
  - `results` object[], required — An ordered list of ranked documents
    - `document` object — If `return_documents` is set as `false` this will return none, if `true` it will return the documents passed in
      - `text` string, required — The text of the document to rerank
    - `index` integer, required — Corresponds to the index in the original list of documents to which the ranked document belongs. (i.e. if the first value in the `results` object has an `index` value of 3, it means in the list of documents passed in, the document at `index=3` had the highest relevance)
    - `relevance_score` number, float, required — Relevance scores are normalized to be in the range `[0, 1]`. Scores close to `1` indicate a high relevance to the query, and scores closer to `0` indicate low relevance. It is not accurate to assume a score of 0.9 means the document is 2x more relevant than a document with a score of 0.45
  - `meta` ApiMeta
    - `api_version` object
      - `version` string, required
      - `is_deprecated` boolean
      - `is_experimental` boolean
    - `billed_units` object
      - `images` number — The number of billed images.
      - `input_tokens` number — The number of billed input tokens.
      - `image_tokens` number — The number of billed image tokens.
      - `output_tokens` number — The number of billed output tokens.
      - `search_units` number — The number of billed search units.
      - `classifications` number — The number of billed classifications units.
    - `tokens` object
      - `input_tokens` number — The number of tokens used as input to the model.
      - `output_tokens` number — The number of tokens produced by the model.
    - `cached_tokens` number — The number of prompt tokens that hit the inference cache.
    - `warnings` string[]

## Other responses

- `400` — This error is returned when the request is not well formed. This could be because: - JSON is invalid - The request is missing required fields - The request contains an invalid combination of fields
- `401` — This error indicates that the operation attempted to be performed is not allowed. This could be because: - The api token is invalid - The user does not have the necessary permissions
- `403` — This error indicates that the operation attempted to be performed is not allowed. This could be because: - The api token is invalid - The user does not have the necessary permissions
- `404` — This error is returned when a resource is not found. This could be because: - The endpoint does not exist - The resource does not exist eg model id, dataset id
- `422` — This error is returned when the request is not well formed. This could be because: - JSON is invalid - The request is missing required fields - The request contains an invalid combination of fields
- `429` — Too many requests
- `498` — This error is returned when a request or response contains a deny-listed token.
- `499` — This error is returned when a request is cancelled by the user.
- `500` — This error is returned when an uncategorised internal server error occurs.
- `501` — This error is returned when the requested feature is not implemented.
- `503` — This error is returned when the service is unavailable. This could be due to: - Too many users trying to access the service at the same time
- `504` — This error is returned when a request to the server times out. This could be due to: - An internal services taking too long to respond

---

[API](https://skmtc.net/cohere-ai/apis/api-reference.md) · [All operations](https://skmtc.net/cohere-ai/apis/api-reference/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/cohere-ai/api-reference/versions/dbed69eda210/schema)
