Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

[Bug] Stream doesn't work with Deep Research modelΒ #322

@kenshin54

Description

@kenshin54

πŸ› Describe the Bug

We tested the streaming API with different models with same code, the first token received with Deep Research model is almost same as the non-streaming version.

βœ… Expected Behavior

The tokens should be streamed with Deep Research model.

❌ Actual Behavior

The time used between stream vs no stream are almost same.

πŸ”„ Steps to Reproduce

import OpenAI from 'openai';

async function noStream(model: string) {
  const client = new OpenAI({
    apiKey: process.env['PERPLEXITY_API_KEY'],
    baseURL: 'https://api.perplexity.ai',
  });

  const t1 = new Date().getTime();

  await client.chat.completions.create({
    messages: [
      {
        role: 'system',
        content: 'Be precise and concise.',
      },
      {
        role: 'user',
        content: 'How many stars are there in our galaxy?',
      },
    ],
    model,
    stream: false,
  });

  const t2 = new Date().getTime();
  console.log(`Model: ${model}, response time: ${t2 - t1}ms`);
}

async function stream(model: string) {
  const client = new OpenAI({
    apiKey: process.env['PERPLEXITY_API_KEY'],
    baseURL: 'https://api.perplexity.ai',
  });

  const t1 = new Date().getTime();

  const stream = await client.chat.completions.create({
    messages: [
      {
        role: 'system',
        content: 'Be precise and concise.',
      },
      {
        role: 'user',
        content: 'How many stars are there in our galaxy?',
      },
    ],
    model,
    stream: true,
  });

  for await (const _chunk of stream) {
    const t2 = new Date().getTime();
    console.log(`Model: ${model}, first token received in: ${t2 - t1}ms`);
    break;
  }
}

const models = [
  'sonar',
  'sonar-pro',
  'sonar-reasoning',
  'sonar-reasoning-pro',
  'sonar-deep-research',
];

console.log('No stream:');
for (const model of models) {
  await noStream(model);
}

console.log('Stream:');
for (const model of models) {
  await stream(model);
}

πŸ“Œ API Request & Response (if applicable)

🌍 Environment

  • API Version: sonar-deep-research
  • SDK (if applicable): I used OpenAI node client for chat completions API, but it should be same with raw HTTP call.
  • Operating System: MacOS
  • Authentication Type: API Key

πŸ“Ž Logs or Screenshots (if applicable)

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions