Skip to main content

Streaming Proxy

apitree supports streaming responses from LLM APIs (OpenAI, Anthropic, etc.) via Server-Sent Events (SSE). The proxy pipes chunks directly to the client without buffering.

How to Stream

Set either header to enable streaming:

  • Accept: text/event-stream
  • X-Stream: true

cURL Example

curl -N "https://apitree.ai/api/v1/proxy/openai-chat" \
  -H "Authorization: Bearer nxs_live_YOUR_KEY" \
  -H "Accept: text/event-stream" \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "Hello"}], "stream": true}'

SDK Example

import { ApitreeClient } from '@apitreedev/sdk';

const apitree = new ApitreeClient('nxs_live_YOUR_KEY');
const stream = await apitree.stream('openai-chat', {
  messages: [{ role: 'user', content: 'Explain MCP in 3 sentences' }],
  stream: true,
});

const reader = stream.getReader();
const decoder = new TextDecoder();
while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  process.stdout.write(decoder.decode(value));
}

Response Headers

  • X-Request-Id — unique request identifier
  • X-Stream: true — confirms streaming mode
  • X-Credits-Used — credits charged for the stream

Notes

  • • Credits are deducted at stream start (not per-chunk)
  • • Streaming responses bypass the response cache
  • • Usage is logged with full latency (stream start to finish)
  • • Response transformations are NOT applied to streams
apitree · AI-Native API Marketplace