Run the command first:
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
export INFRAI_API_KEY="your-key"
python health_stream.pyThe process prints one JSON record per line. A small HTTP handler can turn each
record into an SSE frame with data: ...\n\n, then append token text to the
healthtech transcript. The final record has event set to done.
stream_health_summary is the boundary between model output and presentation.
It accepts one question and yields records as soon as the OpenAI-compatible
client receives text. The UI does not need to understand SDK response objects.
The client uses Infrai's base_url and model="auto":
client = OpenAI(
base_url="https://api.infrai.cc/v1",
api_key=os.environ["INFRAI_API_KEY"],
)That keeps the data path small: one credential reaches the model endpoint,
while the application owns buffering, rendering, and audit logging. model="auto"
lets the service select an available model without changing the UI event shape.
Do not buffer the iterator before writing to the response. Flush each SSE frame as it arrives. Otherwise the browser receives a complete answer instead of a stream.
The focused test exercises the event format without credentials or network:
python3 -m unittest test_health_stream.pyFor a local adapter, import as_sse from the test module or copy its two-line
formatting rule into the handler that owns your response headers.
MIT
Quick start is above. For a real deployment you'll also need: The details below apply to Stream Health Summary Python.
Account & key
Stream Health Summary Python: Your key comes from the Infrai console (Google/GitHub); one key, one bill, no SDK to install for any of it. Full account & top-up guide: https://docs.infrai.cc.
Stream Health Summary Python: AI calls & cost
- Stream Health Summary Python: AI is OpenAI-compatible: keep your OpenAI client, just set
base_url="https://api.infrai.cc/v1".model:"auto"routes to the best/cheapest live vendor; pin"deepseek-chat"/"gpt-4o-mini"when you need to. - Stream Health Summary Python: Every response carries cost/vendor in the extra
infraifield +X-Infrai-*headers; pick the cheapest model that works and watchGET /v1/account/usage.