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

> ## Agent Instructions
> - Base URLs: models `https://api.aisa.one/v1` (Gemini GenerateContent: `https://api.aisa.one/v1beta`); data APIs `https://api.aisa.one/apis/v1`. The `servers` of each operation in https://aisa.one/openapi.yaml is authoritative.
> - Auth: `Authorization: Bearer $AISA_API_KEY`. Never print, log, or commit the key.
> - MCP (preferred for agents): `https://mcp.aisa.one/mcp`, signed in with OAuth, so there is no key to paste.
> - Agent Skill: `npx skills add AIsa-team/agent-skills --skill aisa`. Fallback with the AIsa CLI: `aisa skills install aisa`.
> - Spending: docs, https://aisa.one/models, https://aisa.one/api, `/v1/models`, and MCP `search`, `list_categories`, `get_details`, `batch_quote`, and the `account` operation are free. Quote the exact calls before running them (MCP `batch_quote`, CLI `aisa quote --json`). If the quote reports `auto_execute_eligible: true`, run it unless the user set a tighter limit or asked only for a quote. Otherwise, tell the user in one message the planned calls, the quoted price, and a total USD budget for the task, then wait for approval. Direct HTTP calls follow the stricter rule at https://aisa.one/docs/get-started/cli.md#direct-http-fallback. Do not make paid calls to test availability. Full rule: https://aisa.one/llms.txt

# Rerank Documents

> Reorder documents by relevance to a query using Jina rerank, served through the OpenAI-compatible AIsa API.

Rerank a list of documents against a `query` using `jina-reranker-v3`. Provide a non-empty `query` and a non-empty `documents` array; results come back ordered by `relevance_score`. Use the optional `top_n` to return only the most relevant documents. This pairs naturally with embeddings-based retrieval: embed and shortlist candidates, then rerank for final ordering.

Served at the AIsa API path `/v1/rerank` — OpenAI-compatible. Billing is token-based; the `usage.total_tokens` field reports the tokens billed for each request.

```bash curl theme={null}
curl https://api.aisa.one/v1/rerank \
  -H "Authorization: Bearer $AISA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "jina-reranker-v3",
    "query": "What is the capital of France?",
    "documents": [
      "Paris is the capital of France.",
      "Berlin is the capital of Germany.",
      "The Eiffel Tower is in Paris."
    ],
    "top_n": 2
  }'
```

```python Python theme={null}
import requests

resp = requests.post(
    "https://api.aisa.one/v1/rerank",
    headers={"Authorization": "Bearer sk-aisa-..."},
    json={
        "model": "jina-reranker-v3",
        "query": "What is the capital of France?",
        "documents": [
            "Paris is the capital of France.",
            "Berlin is the capital of Germany.",
            "The Eiffel Tower is in Paris.",
        ],
        "top_n": 2,
    },
)
print(resp.json()["results"])
```

## Request contract

* **Method and path:** POST /rerank
* **Request URL template:** `https://api.aisa.one/v1/rerank`

[Complete OpenAPI definition](https://aisa.one/docs/reference-contracts/jina.json)

Effective request declaration (including authentication and referenced schemas):

```json theme={null}
{
  "operationId": "createRerank",
  "method": "POST",
  "path": "/rerank",
  "servers": [
    {
      "url": "https://api.aisa.one/v1"
    }
  ],
  "parameters": [],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "requestBody": {
    "content": {
      "application/json": {
        "example": {
          "documents": [
            "Paris is the capital of France.",
            "Berlin is the capital of Germany.",
            "The Eiffel Tower is in Paris."
          ],
          "model": "jina-reranker-v3",
          "query": "What is the capital of France?",
          "top_n": 2
        },
        "schema": {
          "properties": {
            "documents": {
              "description": "Non-empty array of document strings to rerank.",
              "example": [
                "Paris is the capital of France.",
                "Berlin is the capital of Germany.",
                "The Eiffel Tower is in Paris."
              ],
              "items": {
                "type": "string"
              },
              "minItems": 1,
              "type": "array"
            },
            "model": {
              "description": "Rerank model name.",
              "example": "jina-reranker-v3",
              "type": "string"
            },
            "query": {
              "description": "Non-empty query string to rank documents against.",
              "example": "What is the capital of France?",
              "type": "string"
            },
            "top_n": {
              "description": "Optional. Return only the top N most relevant documents.",
              "example": 2,
              "type": "integer"
            }
          },
          "required": [
            "model",
            "query",
            "documents"
          ],
          "type": "object"
        }
      }
    },
    "required": true
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "bearerFormat": "API Key",
        "scheme": "bearer",
        "type": "http"
      }
    }
  }
}
```


## OpenAPI

````yaml reference-contracts/jina.json POST /rerank
openapi: 3.0.3
info:
  description: >-
    Jina embeddings and reranking served via the AIsa relay (OpenAI-compatible)
    path. Includes text embeddings (jina-embeddings-v3 and
    jina-embeddings-v5-text-small, both 1024-dim) and document reranking
    (jina-reranker-v3). Billing is token-based for both endpoints.
  title: Jina Embeddings & Rerank API
  version: 1.0.0
servers:
  - url: https://api.aisa.one/v1
security:
  - BearerAuth: []
tags:
  - name: Embeddings & Rerank
paths:
  /rerank:
    post:
      summary: Rerank documents
      description: >-
        Rerank a list of documents against a query using jina-reranker-v3,
        returning documents ordered by relevance score. Served via the AIsa
        relay path /v1/rerank. Billing is token-based.
      operationId: createRerank
      requestBody:
        content:
          application/json:
            example:
              documents:
                - Paris is the capital of France.
                - Berlin is the capital of Germany.
                - The Eiffel Tower is in Paris.
              model: jina-reranker-v3
              query: What is the capital of France?
              top_n: 2
            schema:
              properties:
                documents:
                  description: Non-empty array of document strings to rerank.
                  example:
                    - Paris is the capital of France.
                    - Berlin is the capital of Germany.
                    - The Eiffel Tower is in Paris.
                  items:
                    type: string
                  minItems: 1
                  type: array
                model:
                  description: Rerank model name.
                  example: jina-reranker-v3
                  type: string
                query:
                  description: Non-empty query string to rank documents against.
                  example: What is the capital of France?
                  type: string
                top_n:
                  description: Optional. Return only the top N most relevant documents.
                  example: 2
                  type: integer
              required:
                - model
                - query
                - documents
              type: object
        required: true
      responses:
        '200':
          content:
            application/json:
              example:
                model: jina-reranker-v3
                results:
                  - document:
                      text: Paris is the capital of France.
                    index: 0
                    relevance_score: 0.98
                  - document:
                      text: The Eiffel Tower is in Paris.
                    index: 2
                    relevance_score: 0.71
                usage:
                  total_tokens: 27
              schema:
                properties:
                  model:
                    example: jina-reranker-v3
                    type: string
                  results:
                    items:
                      properties:
                        document:
                          properties:
                            text:
                              example: Paris is the capital of France.
                              type: string
                          type: object
                        index:
                          description: Index of the document in the original request array.
                          example: 0
                          type: integer
                        relevance_score:
                          example: 0.98
                          format: float
                          type: number
                      type: object
                    type: array
                  usage:
                    properties:
                      total_tokens:
                        example: 27
                        type: integer
                    type: object
                type: object
          description: Reranked results ordered by relevance.
components:
  securitySchemes:
    BearerAuth:
      bearerFormat: API Key
      scheme: bearer
      type: http

````

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