URLs with reserved characters throws error in search_domain_filter

:bug: Describe the Bug

If I pass this URL in search_domain_filter: https://seinfeld.fandom.com/wiki/The_Seinfeld_Chronicles the https://api.perplexity.ai/chat/completions works fine. If I instead use this URL: https://en.wikipedia.org/wiki/The_Stake_Out_(Seinfeld) I get this error: {ā€œerrorā€:{ā€œmessageā€:ā€œValidation error: search_domain_filters must be a valid domain name, but got https://en.wikipedia.org/wiki/The_Stake_Out\_%2528Seinfeld%2529",ā€œtypeā€:ā€œinvalid_search_domain_filterā€,"codeā€:400}}

:white_check_mark: Expected Behavior

The URL would work as other URLs work

:cross_mark: Actual Behavior

The error as described above.

:counterclockwise_arrows_button: Steps to Reproduce

  1. Call the API with the following request: As described above
  2. Observe the unexpected behavior.

Here is an example of two similar Perplexity API queries: one that works successfully and one that fails due to a validation error in the search_domain_filter field.


Working Query

The following query executes successfully:

curl --location 'https://api.perplexity.ai/chat/completions' \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --header "Authorization: Bearer $SONAR_API_KEY" \
  --data '{
    "model": "sonar",
    "messages": [
      {
        "role": "user",
        "content": "Give a short summary of Seinfeld episode 1 season 1"
      }
    ],
    "search_domain_filter": [
      "https://en.wikipedia.org/wiki/The_Seinfeld_Chronicles",
      "https://www.imdb.com/title/tt0098286/"
    ]
  }' | jq

Result:
The query works as expected.


Failing Query

The following query uses a similar structure but fails:

curl --location 'https://api.perplexity.ai/chat/completions' \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --header "Authorization: Bearer $SONAR_API_KEY" \
  --data '{
    "model": "sonar",
    "messages": [
      {
        "role": "user",
        "content": "Give a short summary of Seinfeld episode 2 season 1"
      }
    ],
    "search_domain_filter": [
      "https://en.wikipedia.org/wiki/The_Stake_Out_(Seinfeld)",
      "https://www.imdb.com/title/tt0697784/"
    ]
  }' | jq

Error Response

The failing query returns the following error:

{
  "error": {
    "message": "Validation error: search_domain_filters must be a valid domain name, but got https://en.wikipedia.org/wiki/The_Stake_Out_(Seinfeld)",
    "type": "invalid_search_domain_filter",
    "code": 400
  }
}

Note

  • The failing URL includes parentheses, which may trigger stricter validation.