Skip Navigation
Show nav
Heroku Dev Center Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
Heroku Dev Center Dev Center
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
    • .NET
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log in or Sign up
View categories

Categories

  • Heroku Architecture
    • Compute (Dynos)
      • Dyno Management
      • Dyno Concepts
      • Dyno Behavior
      • Dyno Reference
      • Dyno Troubleshooting
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Buildpacks
    • Platform Principles
  • Developer Tools
    • AI Tools
    • Command Line
    • Heroku VS Code Extension
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery & Integration (Heroku Flow)
    • Continuous Integration
  • Language Support
    • Node.js
      • Working with Node.js
      • Node.js Behavior in Heroku
      • Troubleshooting Node.js Apps
    • Ruby
      • Rails Support
        • Working with Rails
      • Working with Bundler
      • Working with Ruby
      • Ruby Behavior in Heroku
      • Troubleshooting Ruby Apps
    • Python
      • Working with Python
      • Background Jobs in Python
      • Python Behavior in Heroku
      • Working with Django
    • Java
      • Java Behavior in Heroku
      • Working with Java
      • Working with Maven
      • Working with Spring Boot
      • Troubleshooting Java Apps
    • PHP
      • Working with PHP
      • PHP Behavior in Heroku
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
    • .NET
      • Working with .NET
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
      • Migrating to Heroku Postgres
    • Heroku Key-Value Store
    • Apache Kafka on Heroku
    • Other Data Stores
  • AI
    • Inference Essentials
    • Inference API
    • Inference Quick Start Guides
    • AI Models
    • Tool Use
    • AI Integrations
    • Vector Database
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
      • Single Sign-on (SSO)
    • Private Spaces
      • Infrastructure Networking
    • Compliance
  • Heroku Enterprise
    • Enterprise Accounts
    • Enterprise Teams
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
    • Heroku AppLink
      • Getting Started with Heroku AppLink
      • Working with Heroku AppLink
      • Heroku AppLink Reference
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
    • Other Salesforce Integrations
  • AI
  • Inference API
  • Managed Inference and Agents API /v1/rerank

Managed Inference and Agents API /v1/rerank

Table of Contents [expand]

  • Request Body Parameters
  • Request Headers
  • Response Format
  • Error Responses
  • Example Request
  • Example Response

Last updated January 15, 2026

The /v1/rerank endpoint ranks documents on their semantic relevance to a query. You can use this endpoint to improve response quality in retrieval-augmented generation (RAG) systems, semantic search, and question-answering applications.

View our available rerank models.

Request Body Parameters

Use parameters to control how documents are ranked.

Required Parameters

Field Type Description Example
model string ID of the rerank model to use "cohere-rerank-3-5"
query string search query or question used to rank documents "How do you create a Heroku App?"
documents array of strings list of text documents to rank
max strings in array: 1000 documents
["doc1", "doc2", "doc3"]

Optional Parameters

Field Type Description Default Example
top_n integer number of top-ranked results to return all documents 10

Request Headers

In the following example, we assume your model resource has an alias of “RERANK” (meaning you created the model resource with an --as RERANK flag).

Header Type Description
Authorization string your AI add-on’s ‘RERANK’ value (API bearer token)

All inference curl requests must include an Authorization header containing your Heroku Inference key.

Response Format

When a request is successful, the API returns a JSON object with the following structure:

Field Type Description
id string unique identifier for this response (UUID format)
results array of objects ranked documents, ordered by relevance (highest first)
meta object response metadata including API version and billing information

Results Object

Each object inside the results array includes:

Field Type Description
index integer original position of the document in the input array (0-indexed)
relevance_score float semantic relevance score (higher value = more relevant to query)

Meta Object

The meta object includes:

Field Type Description
api_version object API version information
always: 2
billed_units object billing information for request
billed_units.search_units integer number of search units consumed by request

Error Responses

Status Code Description Example Message
400 validation errors "model is required"
"query is required"
"documents array is required and cannot be empty"
"documents array exceeds maximum of 1000 items (received X). Please reduce the number of documents per request"
401 missing or invalid authorization token authentication errors
403 you don’t have access to the requested model authorization errors
404 invalid model ID model not found errors
429 rate limit exceeded exceeded 250 RPM (Cohere) or 200 RPM (Amazon)
500 internal server error backend service errors

Example Request

Let’s walk through an example /v1/rerank curl request.

First, use this command to set your Heroku environment variables as local variables.

export RERANK_MODEL_ID=$(heroku config:get -a $APP_NAME RERANK_MODEL_ID)
export RERANK_KEY=$(heroku config:get -a $APP_NAME RERANK_KEY)
export RERANK_URL=$(heroku config:get -a $APP_NAME RERANK_URL)

Next, send the curl request:

curl $RERANK_URL/v1/rerank \
  -H "Authorization: Bearer $RERANK_KEY" \
  -d @- <<EOF
{
  "model": "$RERANK_MODEL_ID",
  "query": "How do I optimize database connection pooling?",
  "documents": [
    "Connection pooling reduces overhead by reusing existing database connections instead of creating new ones for each request.",
    "You can monitor application performance using built-in metrics and logging tools.",
    "Set max pool size based on your dyno count and expected concurrent queries to prevent connection exhaustion.",
    "Regular database backups are essential for disaster recovery planning."
  ],
  "top_n": 2
}
EOF

Example Response

{
  "id": "f844c7c3-c357-4476-9a9d-d2de06f2106f",
  "results": [
    {
      "index": 0,
      "relevance_score": 0.6740
    },
    {
      "index": 2,
      "relevance_score": 0.5308
    }
  ],
  "meta": {
    "api_version": {
      "version": "2",
      "is_experimental": false
    },
    "billed_units": {
      "search_units": 1
    }
  }
}

Feedback

Log in to submit feedback.

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure
  • .NET

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing
  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Github
  • LinkedIn
  • © 2026 Salesforce, Inc. All rights reserved. Various trademarks held by their respective owners. Salesforce Tower, 415 Mission Street, 3rd Floor, San Francisco, CA 94105, United States
  • heroku.com
  • Legal
  • Terms of Service
  • Privacy Information
  • Responsible Disclosure
  • Trust
  • Contact
  • Cookie Preferences
  • Your Privacy Choices