> For the complete documentation index, see [llms.txt](https://docs.otari.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.otari.ai/api-reference/rerank.md).

# Rerank

## Create Rerank

> Rerank documents by relevance to a query.\
> \
> Billing: a model priced per request (\`\`unit: requests\`\`) is charged per\
> search unit the provider reports, or for one unit when it reports none. A\
> model priced per token is charged on the input tokens the provider reports.\
> \
> \`\`usage\`\` carries what the gateway metered: the provider's tokens, the\
> search units billed when the model is priced per request, and, when the\
> request was priced, \`\`cost\_usd\`\` and \`\`pricing\_source\`\` as a completion's\
> usage does. \`\`meta\`\` is the provider's own billing report, unchanged.\
> \
> Authentication modes:\
> \- Master key + user field: Use specified user (must exist)\
> \- API key + user field: Use specified user (must exist)\
> \- API key without user field: Use the shared "default" user

```json
{"openapi":"3.1.0","info":{"title":"otari","version":"0.33.0"},"security":[{"ApiKeyAuth":[]},{"XApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"description":"Enter your API key here (sent as Otari-Key header).","in":"header","name":"Otari-Key","type":"apiKey"},"XApiKeyAuth":{"description":"Anthropic-native clients send credentials here (no Bearer prefix).","in":"header","name":"x-api-key","type":"apiKey"}},"schemas":{"RerankRequest":{"description":"Rerank request.","properties":{"documents":{"description":"List of document strings to rerank","items":{"type":"string"},"minItems":1,"title":"Documents","type":"array"},"max_tokens_per_doc":{"anyOf":[{"exclusiveMinimum":0,"type":"integer"},{"type":"null"}],"description":"Per-document truncation limit","title":"Max Tokens Per Doc"},"model":{"description":"Provider-prefixed model ID, e.g. 'cohere:rerank-v3.5'","title":"Model","type":"string"},"query":{"description":"The search query to rerank documents against","title":"Query","type":"string"},"top_n":{"anyOf":[{"exclusiveMinimum":0,"type":"integer"},{"type":"null"}],"description":"Maximum number of results to return","title":"Top N"},"user":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"User ID for usage attribution","title":"User"}},"required":["model","query","documents"],"title":"RerankRequest","type":"object"},"RerankResponse":{"description":"Documents ordered by relevance, with the gateway's metered usage.","properties":{"id":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Provider-assigned response ID","title":"Id"},"meta":{"anyOf":[{"$ref":"#/components/schemas/RerankMeta"},{"type":"null"}],"description":"The provider's own billing report, unchanged"},"model":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"The model that served the request","title":"Model"},"results":{"description":"Results sorted by relevance_score, highest first","items":{"$ref":"#/components/schemas/RerankResult"},"title":"Results","type":"array"},"usage":{"$ref":"#/components/schemas/RerankUsage"}},"required":["results","usage"],"title":"RerankResponse","type":"object"},"RerankMeta":{"description":"The provider's own billing report, passed through as it sent it.","properties":{"billed_units":{"anyOf":[{"additionalProperties":{"type":"number"},"type":"object"},{"type":"null"}],"title":"Billed Units"},"tokens":{"anyOf":[{"additionalProperties":{"type":"integer"},"type":"object"},{"type":"null"}],"title":"Tokens"}},"title":"RerankMeta","type":"object"},"RerankResult":{"description":"One document's relevance to the query.","properties":{"index":{"description":"Zero-based index into the request's documents","title":"Index","type":"integer"},"relevance_score":{"description":"Relevance score, higher is more relevant","title":"Relevance Score","type":"number"}},"required":["index","relevance_score"],"title":"RerankResult","type":"object"},"RerankUsage":{"description":"What a rerank request was metered at, and what it cost.","properties":{"cost_usd":{"anyOf":[{"pattern":"^-?\\d+\\.\\d{6}$","type":"string"},{"type":"null"}],"description":"What the request cost, as a six-decimal USD string; absent when it was not priced","title":"Cost Usd"},"pricing_source":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Which rate priced the request: `organization`, `deployment` or `defaults`; absent when it was not priced","title":"Pricing Source"},"search_units":{"anyOf":[{"type":"integer"},{"type":"null"}],"description":"Search units the request was billed for, present only when the model is priced per request: the provider's count rounded up, or one when it reported none","title":"Search Units"},"total_tokens":{"anyOf":[{"type":"integer"},{"type":"null"}],"description":"Tokens the provider reported, or null","title":"Total Tokens"}},"title":"RerankUsage","type":"object"},"HTTPValidationError":{"properties":{"code":{"const":"invalid_request","description":"Stable error code, also sent as the Otari-Error-Code header.","title":"Code","type":"string"},"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"title":"Detail","type":"array"}},"title":"HTTPValidationError","type":"object"},"ValidationError":{"properties":{"ctx":{"title":"Context","type":"object"},"input":{"title":"Input"},"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"title":"Location","type":"array"},"msg":{"title":"Message","type":"string"},"type":{"title":"Error Type","type":"string"}},"required":["loc","msg","type"],"title":"ValidationError","type":"object"}}},"paths":{"/api/v1/rerank":{"post":{"description":"Rerank documents by relevance to a query.\n\nBilling: a model priced per request (``unit: requests``) is charged per\nsearch unit the provider reports, or for one unit when it reports none. A\nmodel priced per token is charged on the input tokens the provider reports.\n\n``usage`` carries what the gateway metered: the provider's tokens, the\nsearch units billed when the model is priced per request, and, when the\nrequest was priced, ``cost_usd`` and ``pricing_source`` as a completion's\nusage does. ``meta`` is the provider's own billing report, unchanged.\n\nAuthentication modes:\n- Master key + user field: Use specified user (must exist)\n- API key + user field: Use specified user (must exist)\n- API key without user field: Use the shared \"default\" user","operationId":"rerank-create_rerank","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RerankRequest"}}},"required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RerankResponse"}}},"description":"Successful Response"},"422":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}},"description":"Validation Error"}},"summary":"Create Rerank","tags":["rerank"]}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.otari.ai/api-reference/rerank.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
