Skip to content

Streaming & Diffusion

Fresh

The Inception API provides two output modes for real-time responses.

Streaming

Get responses block-by-block for instant feedback. Ideal for chat UIs and live applications.

Enable Streaming

bash
curl https://api.inceptionlabs.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $INCEPTION_API_KEY" \
  -d '{
    "model": "mercury-2",
    "messages": [{"role": "user", "content": "Write a poem about AI"}],
    "max_tokens": 1000,
    "stream": true
  }'

Parsing SSE Responses (JavaScript)

javascript
const response = await fetch("https://api.inceptionlabs.ai/v1/chat/completions", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": `Bearer ${apiKey}`
  },
  body: JSON.stringify({
    model: "mercury-2",
    messages: [{ role: "user", content: "Hello" }],
    max_tokens: 1000,
    stream: true
  })
});

const reader = response.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  const chunk = decoder.decode(value);
  // Parse SSE data lines and extract content
  const lines = chunk.split('\n').filter(l => l.startsWith('data: '));
  for (const line of lines) {
    const json = JSON.parse(line.slice(6));
    if (json.choices?.[0]?.delta?.content) {
      process.stdout.write(json.choices[0].delta.content);
    }
  }
}

Diffusion Mode

Visualize how noisy outputs transform into refined text through the model's iterative denoising process. A unique feature of Mercury's diffusion-based architecture.

Enable Diffusion

json
{
  "model": "mercury-2",
  "messages": [{"role": "user", "content": "Explain gravity"}],
  "max_tokens": 1000,
  "stream": true,
  "diffusing": true
}

INFO

Streaming must be enabled (stream: true) for diffusion visualization to work.

Comparison

FeatureStreamingDiffusing
LatencyLow TTFBLow TTFB
Use CaseChat UIs, live appsDebug, visualization
Requiresstream: truestream: true + diffusing: true