Python 88.3%
TypeScript 7.6%
Shell 4.1%
1#!/usr/bin/env python32# STATUS: LIVE_VERIFIED — executed 2026-09-19 (exit 0 in 3.1s)3# Deferred chat completion with raw REST (scripts.live) — the OpenAI SDK has no helper for GET /v1/chat/deferred-completion/{id}.4import pathlib, sys, time5ROOT = pathlib.Path(__file__).resolve().parents[3]; sys.path.insert(0, str(ROOT))6from scripts import live # noqa: E4027st, b, _ = live.xai_request("POST", "/v1/chat/completions", {"model": "grok-4.3", "messages": [{"role": "user", "content": "Reply with OK."}], "max_completion_tokens": 32, "deferred": True}, est_cost_usd=0.0005, note="example xai/deferred/deferred.py start")8assert st == 200 and "request_id" in b, (st, b); rid = b["request_id"]9for i in range(15):10 st, r, _ = live.xai_request("GET", f"/v1/chat/deferred-completion/{rid}", note=f"example xai/deferred/deferred.py poll {i+1}")11 print("poll", i + 1, "->", st)12 if st == 200: break13 time.sleep(2)14assert st == 20015print(r["choices"][0]["message"]["content"], "| reasoning tokens:", r["usage"]["completion_tokens_details"]["reasoning_tokens"])16