Kimi API streaming example — local verification
ChinaAI, 1 October 2026

Result: 28 checks passed (OK); process exit status 0.
Observed unittest duration: 0.025 seconds. This is a local test-run duration,
not API latency or a prediction of request performance.
Command: python -m unittest -v test_stream_request
The run used the workspace's bundled Python 3 runtime. No packages were
installed. The Python bytecode cache was disabled for this run.

No new provider request was sent. Tests block real socket creation and
http.client.HTTPSConnection use. Fake connection cases explicitly replace
the constructor with an in-memory test double while sockets remain blocked.
Only a dummy canary string was used as a key; no account key was read.

Checks cover:
  - One fixed request, correct endpoint and payload, no automatic retry.
  - Hidden key entry, environment priority, blank/cancelled input and the
    refusal to continue when hidden input falls back to visible entry.
  - Internal key control characters rejected before a connection is created.
    Invalid-header failures expose neither the dummy key nor raw exceptions.
  - Incremental UTF-8, a BOM, LF/CRLF/CR split across reads, comment lines,
    optional data-field spacing, multiline data and blank-line dispatch.
  - The preserved public record replayed from its saved JSON chunks as
    local SSE frames; visible answer, separate reasoning and usage retained.
  - Final top-level usage with empty choices, choice-level usage fallback,
    untrusted usage strings filtered and missing counts left unknown.
  - stop plus [DONE] plus nonempty text required for a complete text result;
    stop without [DONE], [DONE] without an answer and unframed [DONE] at EOF
    do not report success.
  - Length/tool finishes, tool deltas, conflicts and content after finish.
  - Malformed JSON/UTF-8/event shapes, provider errors, oversized frames,
    non-SSE responses, HTTP errors and exceptions without raw error output.
  - Partial text retained after disconnect, timeout or cancellation; elapsed
    reader-deadline checks; response and connection cleanup.
  - Default console output omits reasoning and treats absent usage as
    unknown rather than zero. A completed result does not verify its facts.

The preserved fixture is byte-identical to the public sanitized
k3-stream-result.json in the original September 25 evidence archive.
Its SHA256 is:
c5b1833d37cb3812d4ceed4306bf76689bf129ff4e17c379391141a69a9b2df2

The original evidence archive passed its ZIP integrity check and contains
eight files: README.txt, first_request.py, requests.json,
results-summary.json, k3-text-result.json, k3-stream-result.json,
k3-json-result.json and k26-no-thinking-result.json. It contains a saved
stream record but no separate streaming request program. That archive and
the four original trials have not been changed.

These local checks do not verify a current account's model access, price,
API compatibility, network behavior or provider billing. The example was
not run against the provider. The fixture retains the original answer and
its limitations; it is not a benchmark or a fresh product result.
