API protocol

POST · Rerank documents

Direct answerPOST /v1/rerank. Authentication, parameters, examples in three languages, result validation and error handling.

Updated · Reviewed

OpenFox · Rerank documents

POST https://api.openfox.vip/v1/rerank

Model ID: YOUR_MODEL_ID

Authentication

Authorization: Bearer $OPENFOX_API_KEY

Create a model API key in API Keys. Dashboard sessions and personal access tokens are not model API credentials.

Keep credentials in environment variables on your server. Do not paste real keys, cookies or account records into this guide.

Request parameters

  • model (body, string, Required): See schema details.
  • query (body, string, Required): 查询文本
  • documents (body, array, Required): 要重排序的文档列表
  • top_n (body, integer, Optional): 返回前 N 个结果
  • return_documents (body, boolean, Optional): See schema details.

Example values are not server defaults. Model-specific parameter support must be confirmed for the selected channel.

Model and channel limitations

Ranking returns results with index and relevance_score; it is not an embedding response.

Request example

Run one language example only. Creation requests may be charged; do not run every example or retry automatically.

Set OPENFOX_REQUEST_ID from the original X-Request-Id when recovering images. Set OPENFOX_TASK_ID from a real task creation response when querying tasks.

curl

# Bash / WSL; curl 7.76+ and jq. Run ONE language example, not all of them.
umask 077
RESULT=$(mktemp)
trap 'rm -f "$RESULT"' EXIT
: "${OPENFOX_API_KEY:?Set OPENFOX_API_KEY}"
curl --silent --show-error --fail-with-body --max-time 180 'https://api.openfox.vip/v1/rerank' \
  -H "Authorization: Bearer $OPENFOX_API_KEY" \
  -H "Content-Type: application/json" \
  --data-raw '{"model":"YOUR_MODEL_ID","query":"What is an API?","documents":["An API connects applications.","The sky is blue."],"return_documents":false}' \
  --output "$RESULT" || exit 1
jq -e 'type == "object" and (.error | not) and (.success != false) and (.code != false)' "$RESULT" >/dev/null || exit 1
# HTTP/business envelope checked only. Complete result validation is required:
# Require a results array with index and relevance_score. Ranking results are not embedding vectors.
# Use the Python or JavaScript example in this guide for result processing.

python

# Python 3.10+; install: pip install httpx
import asyncio, json, os
from urllib.parse import quote, urlparse
import httpx

async def main():
    url = "https://api.openfox.vip/v1/rerank"
    headers = {}
    headers["Authorization"] = "Bearer " + os.environ["OPENFOX_API_KEY"]
    params = {}
    async with httpx.AsyncClient(timeout=30, follow_redirects=False) as client:
        async def read(target, method='GET', payload=None):
            response = await client.request(method, target, headers=headers, params=params, json=payload)
            response.raise_for_status()
            value = response.json()
            if not isinstance(value, dict) or value.get('error') or value.get('success') is False or value.get('code') is False:
                raise RuntimeError('API business error')
            return value
        data = await read(url, "POST", json.loads("{\"model\":\"YOUR_MODEL_ID\",\"query\":\"What is an API?\",\"documents\":[\"An API connects applications.\",\"The sky is blue.\"],\"return_documents\":false}"))

    if not (isinstance(data.get('results'), list) and all(isinstance(x.get('index'), int) and isinstance(x.get('relevance_score'), (int, float)) for x in data['results'])):
        raise RuntimeError('Unexpected result')
    print('Response validated; private data is not logged.')

async def bounded():
    await asyncio.wait_for(main(), timeout=180)

asyncio.run(bounded())

javascript

// Node.js 20+; save as example.mjs and run: node example.mjs
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), 180000);
const signal = controller.signal;
try {
const url = new URL("https://api.openfox.vip/v1/rerank");
const headers = {"Content-Type":"application/json"};
if (!process.env.OPENFOX_API_KEY) throw Error('Set OPENFOX_API_KEY');
headers["Authorization"] = "Bearer " + process.env.OPENFOX_API_KEY;
const read = async (target, method = 'GET', payload) => {
  const response = await fetch(target, { method, headers, signal, redirect: 'error', body: payload === undefined ? undefined : JSON.stringify(payload) });
  if (!response.ok) throw Error('HTTP ' + response.status);
  const data = await response.json();
  if (!data || typeof data !== 'object' || data.error || data.success === false || data.code === false) throw Error('API business error');
  return data;
};
let data = await read(url, "POST", {
  "model": "YOUR_MODEL_ID",
  "query": "What is an API?",
  "documents": [
    "An API connects applications.",
    "The sky is blue."
  ],
  "return_documents": false
});

if (!(Array.isArray(data.results) && data.results.every(x => Number.isInteger(x.index) && Number.isFinite(x.relevance_score)))) throw Error('Unexpected result');
console.log('Response validated; private data is not logged.');
} finally { clearTimeout(timer); }

Results and success criteria

Require a results array with index and relevance_score. Ranking results are not embedding vectors.

Error handling

Check both HTTP status and business errors. A timeout does not prove the operation failed. Do not automatically retry creation requests; inspect the original request or usage first.

401/403: check credentials, scopes, model permissions and IP rules. 429: check quota and rate limits. 5xx: preserve a non-secret request ID and contact support.

Python and JavaScript share a 180-second network deadline. Read-only polling is bounded. Unknown or failure states stop the flow. Image decoding is local CPU work with byte and pixel limits.

Only the image editing example uploads a local file. Set OPENFOX_IMAGE_PATH to a supported image. Other examples do not upload files. Download external results without platform credentials. Task artifacts require format-specific verification.

Full request schema

{
  "parameters": [],
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "required": [
            "model",
            "query",
            "documents"
          ],
          "properties": {
            "model": {
              "type": "string",
              "example": "rerank-english-v2.0"
            },
            "query": {
              "type": "string",
              "description": "查询文本"
            },
            "documents": {
              "type": "array",
              "items": {
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "object",
                    "properties": {}
                  }
                ]
              },
              "description": "要重排序的文档列表"
            },
            "top_n": {
              "type": "integer",
              "description": "返回前 N 个结果"
            },
            "return_documents": {
              "type": "boolean",
              "default": false
            }
          }
        }
      }
    },
    "required": true
  }
}

Sources and verification

docs/openapi/relay.json · relaykit/dto/rerank.go · 2026-11-03

SHA-256: aeee6c35a35b2eaced964401f3826f369ad7ac8985c17989dcbbe08337d9fa01

source-reviewed; upstream-not-tested; legacy-schema-needs-field-review

Source review is not upstream business verification. Availability and billing depend on your account, group and channel.

Use cases

  • getting-started
  • troubleshooting

API protocols

  • /v1/rerank

FAQ

Does this guarantee model availability?

No. Check the exact model, group and endpoint permissions in the marketplace.

Do examples include live credentials?

No. Set environment variables on your server and replace YOUR_MODEL_ID with an available exact model ID.

Should I retry immediately after a timeout?

Do not automatically retry creation requests. Check the request ID, task status and usage to avoid duplicate charges.

Official sources

  1. OpenFox API Official