Practical integration notesView API prices
Streaming lab

Node streaming lab: prove that chunk boundaries do not change your answer

A stream can look correct in a terminal and still lose text when network chunks arrive differently. This experiment uses a small Node 20+ file and a repeatable local protocol to check the application contract: the same event sequence must produce the same text, regardless of byte boundaries. It is a parser experiment, not a provider speed benchmark.

By Abliterated API Lab · 11 November 2026 · Published by UncensuredAI

Keep the experiment small

Download the companion JavaScript file and keep an unchanged copy for comparison. Node provides fetch and readable-stream primitives; the example targets Node 20 or later. Record your exact runtime version with the experiment results, because a runtime requirement alone does not establish that every supported version was tested.

The live endpoint is https://uncensuredai.com/v1/chat/completions. Authentication uses a Bearer API key, and the request needs an exact catalog model ID with streaming enabled. Keep the key outside the file and outside fixture output.

Companion Node example

Download stream.mjs

// Node.js 20+. A run sends one paid API request. No automatic retries.
import {pathToFileURL} from 'node:url';

export async function* readSSE(body) {
  const decoder=new TextDecoder();let buffer='';
  function parse(block){
    return block.split(/\r?\n/).filter(line=>line.startsWith('data:')).map(line=>line.slice(5).replace(/^ /,'')).join('\n');
  }
  for await(const chunk of body){
    buffer+=decoder.decode(chunk,{stream:true});
    let match;
    while((match=/\r?\n\r?\n/.exec(buffer))){
      const block=buffer.slice(0,match.index);buffer=buffer.slice(match.index+match[0].length);
      const data=parse(block);if(!data)continue;
      if(data==='[DONE]')return;
      yield JSON.parse(data);
    }
  }
  buffer+=decoder.decode();
  if(buffer.trim()){
    const data=parse(buffer);if(data==='[DONE]')return;if(data)yield JSON.parse(data);
  }
  throw new Error('Stream ended before [DONE]; treat the answer as incomplete.');
}

export async function streamAnswer({key,model='deepseek-v4.1-flash-abliterated',prompt='Explain token streaming in one paragraph.',fetchImpl=fetch,onText=t=>process.stdout.write(t)}){
  if(!key)throw new Error('Set UNCENSUREDAI_API_KEY in the server environment.');
  const response=await fetchImpl('https://uncensuredai.com/v1/chat/completions',{
    method:'POST',headers:{Authorization:`Bearer ${key}`,'Content-Type':'application/json'},
    body:JSON.stringify({model,messages:[{role:'user',content:prompt}],stream:true}),
    signal:AbortSignal.timeout(90000)
  });
  if(!response.ok)throw new Error(`HTTP ${response.status}; inspect the response and retry policy before resubmitting.`);
  if(!response.body)throw new Error('Response has no stream body.');
  let text='';
  for await(const event of readSSE(response.body)){
    if(event.error)throw new Error('Provider returned a stream error; no automatic retry was attempted.');
    const delta=event.choices?.[0]?.delta?.content;
    if(typeof delta==='string'){text+=delta;onText(delta);}
  }
  return text;
}
if(process.argv[1]&&import.meta.url===pathToFileURL(process.argv[1]).href){
  try{await streamAnswer({key:process.env.UNCENSUREDAI_API_KEY,model:process.env.MODEL||undefined});process.stdout.write('\n');}
  catch(error){console.error(error.name==='TimeoutError'?'Timed out. The request may have run; inspect usage before retrying.':error.message);process.exitCode=1;}
}

Replay identical events through different boundaries

Build a fixture containing several text deltas, a multibyte character and the completion marker. Feed the same bytes as one chunk, one byte at a time and several uneven chunks. Include boundaries inside a UTF-8 character and inside an event delimiter. Compare the final text exactly, including punctuation and whitespace.

Then supply malformed event data, an HTTP error and a stream that closes before completion. Record which cases terminate successfully and which produce an explicit error. A partial answer must remain distinguishable from a complete one; a clean socket close alone is not your success criterion.

Define the result your application accepts

Keep three observations separate: the HTTP outcome, the reconstructed response and whether the stream completed. On failure, retain enough diagnostic information to identify the fixture and processing stage. Do not silently discard malformed content and label the remaining text successful.

Use a single attempt. After output has started, automatically repeating the request could concatenate unrelated generations or spend additional credit. An ambiguous timeout also does not establish that the service did no work. Stop and present the incomplete or unknown outcome instead of automatically replaying it.

Move to a live run deliberately

Local fixtures exercise your parser and error handling without calling a model. They do not prove live compatibility, latency, billing or availability. Running the file against UncensuredAI makes a real API request and can consume paid credit at the selected model’s applicable rates.

Pass the local checks first, then run one small prompt. Compare the observed live behavior with the fixture contract, record the model ID and date, and consult the API reference before expanding the integration. Publish local and live results as separate evidence.

Put the idea to work.

Explore the current UncensuredAI catalog, create an API key or discuss the models you want to offer through your own service.

Sources and scope

Prices are USD per million tokens unless stated otherwise. Sources checked 11 Nov 2026. This is a first-party publishing project; see our method and disclosure.