Python 88.3%
TypeScript 7.6%
Shell 4.1%
1#!/usr/bin/env python32# STATUS: LIVE_VERIFIED — executed 2026-09-19 (exit 0 in 2.5s)3# Responses SSE on xAI: print the event type sequence incl. reasoning summary deltas and text deltas.4import os, pathlib, sys5ROOT = pathlib.Path(__file__).resolve().parents[3]; sys.path.insert(0, str(ROOT))6from scripts import live # noqa: E4027from openai import OpenAI # noqa: E40289client = OpenAI(api_key=os.environ["XAI_API_KEY"], base_url="https://api.x.ai/v1")10types, text, reasoning = [], "", ""11with client.responses.stream(model="grok-4.3", input="What is 17*23? Reply with the number only.", store=False, max_output_tokens=2000) as stream:12 for ev in stream:13 types.append(ev.type)14 if ev.type == "response.output_text.delta": text += ev.delta15 if ev.type == "response.reasoning_summary_text.delta": reasoning += ev.delta16live.log_request("xai", "POST", "/v1/responses", 200, 0.0005, "example xai/streaming/responses_stream.py")17print("events:", types)18print("reasoning summary:", reasoning or "(none)")19print("text:", text)20assert types[0] == "response.created" and types[-1] == "response.completed"21