Problems manually configuring perplexity sonar deep research

After trying to follow the instructions here with both OpenAI and OpenRouter providers, I finally got it to work by disabling streaming.

With OpenRouter, I was able to run a test with the Run test button in the LLM manual config screen for an gpt-4o. But running the test for perplexity/sonar-deep-research resulted in a 502 error and the following output in the console. It took quite a long time for this error to appear (~30 seconds or something) whereas testing other models returns immediately.

content_topFrameLifeline.js:1 Loading content_topFrameLifeline.js
content_topFrameLifeline.js:1 CONTENT <-> SERVICE LIFELINE: CONNECT
content_topFrameLifeline.js:1 CONTENT <-> SERVICE LIFELINE: MESSAGE Object
topic.js:404 ℹ️ Discourse v3.5.0.beta3-dev — https://github.com/discourse/discourse/commits/c3795177f2 — Ember v5.12.0
/admin/plugins/discourse-ai/ai-llms:1 Uncaught (in promise) Error: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received
content_topFrameLifeline.js:1 CONTENT <-> SERVICE LIFELINE: TIMEOUT
content_topFrameLifeline.js:1 CONTENT <-> SERVICE LIFELINE: CONNECT
content_topFrameLifeline.js:1 CONTENT <-> SERVICE LIFELINE: MESSAGE Object
test.json:1 
            
            
           Failed to load resource: the server responded with a status of 502 ()
client-error-handler.js:88 SyntaxError: Unexpected token '<', "<html>
<h"... is not valid JSON
    at x.parse [as parseJSON] (<anonymous>)
    at l (client-error-handler.js:88:1)
    at p (client-error-handler.js:88:1)
    at v.test (ai-llm-editor-form.js:210:1)
l @ client-error-handler.js:88
p @ client-error-handler.js:88
test @ ai-llm-editor-form.js:210

Both of these worked, so I was confused what I was doing wrong:

âžś curl --location 'https://api.perplexity.ai/chat/completions' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'Authorization: Bearer {token}' \
--data '{
  "model": "sonar-deep-research",
  "messages": [
    {
      "role": "system",
      "content": "Be precise and concise."
    },
    {
      "role": "user",
      "content": "How many stars are there in our galaxy?"
    }
  ]
}'
curl https://openrouter.ai/api/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {token}" \
  -d '{
  "model": "perplexity/sonar-deep-research",
  "messages": [
    {
      "role": "user",
      "content": "How many stars are in the sky"
    }
  ]

}'

Then I got the following answer from Discourse AI, which helped:

It looks like your cURL tests hit OpenRouter’s normal chat endpoint fine—but the Discourse AI “Run test” button actually uses the streaming endpoint by default. If that model (or your OpenRouter plan) doesn’t support streaming, you’ll get a 502 + HTML error blob after a long timeout.

To fix it in Admin → Settings → Plugins → Discourse AI / LLM:

  1. llm_provider: openrouter

  2. llm_provider_url: OpenRouter

  3. llm_provider_api_key: YOUR_KEY

  4. llm_model: perplexity/sonar-deep-research

  5. Turn off streaming so the test (and all calls) use the plain chat endpoint you proved works:
    • llm_use_streaming = false

    (This setting lives just below the llm_model dropdown.)

With streaming off, “Run test” will POST to /chat/completions (not the /stream variant) and you’ll get back valid JSON immediately instead of a 502 HTML page.

If you really need streaming you can point the plugin at OpenRouter’s stream URL— but only if your plan/model supports SSE there:

• llm_stream_url: {provider_url}/chat/completions/stream
• llm_use_streaming: true

Otherwise leave streaming off and you’re all set.

The result isn’t great because there is no streaming and the reasoning tokens are output as plain text before the “report” - but it works!

1 Like

The API is very slow, but it appears to work, see:

That said, the bug/issue here is that this is mostly useless till we parse the grounding links and citation urls, this is feasable, but not trivial:

Worth noting, that one reply linked cost me 70 cents! This is not a cheap model to say the least, I would be super careful with it.