The search_after_date_filter and search_before_date_filter parameters allow you to restrict search results to a specific publication date range. Only results with publication dates falling between these dates will be returned.

Dates must be provided in the “%m/%d/%Y” format (e.g., “3/1/2025”). These filters are optional—you may supply either one or both as needed.

Overview

The search_after_date_filter and search_before_date_filter parameters control which search results are returned by limiting them to a specific publication date range. This feature is useful when you need to: • Narrow down search results to a particular time period • Exclude outdated or overly recent content • Improve relevance by focusing on content published within a defined window

To constrain search results by publication date, include the following fields in your request payload:

"search_after_date_filter": "3/1/2025",
"search_before_date_filter": "3/5/2025"

These filters will be applied in addition to any other search parameters (for example, domain filters).

Examples

1. Limiting Results to a Specific Date Range

This example limits search results to content published between March 1, 2025, and March 5, 2025.

Request Example

curl --location 'https://api.perplexity.ai/chat/completions' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "sonar-pro",
    "messages": [
      {"role": "system", "content": "You are an expert on current events."},
      {"role": "user", "content": "Show me tech news published this week."}
    ],
    "search_after_date_filter": "3/1/2025",
    "search_before_date_filter": "3/5/2025",
    "search_recency_filter": "month"
}'

2. Filtering with a Single Date Parameter

If you only wish to restrict the results to those published on or after a specific date, include just the search_after_date_filter:

payload = {
    "model": "sonar-pro",
    "messages": [
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Show me news articles published after March 1, 2025."}
    ],
    "search_after_date_filter": "3/1/2025",
    "search_recency_filter": "month"
}

Best Practices

Date Format • Strict Format: Dates must match the “%m/%d/%Y” format exactly. For example, the date “3/1/2025” or “03/01/2025” is acceptable. • Consistency: Use one or both filters consistently based on your search needs. Combining both provides a clear range.

Client-Side Validation • Regex Check: Validate date strings on the client side (or via the API) using a regex such as:

date_regex='^(0?[1-9]|1[0-2])/(0?[1-9]|[12][0-9]|3[01])/[0-9]{4}$'

This ensures that dates conform to the required format before sending the request.

Performance Considerations • Narrowing the Search: Applying date range filters typically reduces the number of results, which may improve response times and result relevance. • Avoid Over-Restriction: Ensure that the date range is neither too narrow (limiting useful results) nor too broad (defeating the purpose of the filter).