1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! The mid-stream error projection of the OpenAI chat stream (§4.3): a
//! `data: {"error":…}` frame on a 2xx stream has no governing HTTP status, so its
//! `kind` decodes from the BODY (CR-10). The Chat Completions dialect is served by ONE
//! row across a heterogeneous class (OpenAI, Azure, OpenRouter, LiteLLM, vLLM, Mistral),
//! so the discriminator varies: a numeric `code` IS an HTTP status (the OpenRouter/proxy
//! convention — decoded through the shared table, the Google precedent §4.8), else the
//! string `type`/`code` is bucketed like the anthropic mid-stream table. The whole-body
//! HTTP case lives in the shared `json::http_error` — status is authoritative there.
//! `super::decode` dispatches into these.
use Value;
use crate;
use cratetext_of;
/// A mid-stream `{"error":…}` frame on a 2xx stream (§4.3): `kind` decodes from the
/// BODY (CR-10 — a 2xx stream has no governing status), `error.message` → `message`,
/// the whole `error` object → `provider_detail` verbatim. `retry_after_seconds` is
/// inherently `None` (no governing header on a mid-stream 2xx error, bl-135a). NEVER
/// folded into `Finish`, and it does NOT set `state.terminated` — an error is not a
/// clean terminal marker (the arch §5.6 marker set excludes it), so a bare EOF that
/// follows still fires the premature-EOF Transport, last-error-wins (§4.3).
pub
/// Mid-stream `error` object → `ErrorKind` (§4.3) — the in-band case only, where no
/// HTTP status governs. A numeric `code` IS an HTTP status (OpenRouter/LiteLLM/proxy)
/// and decodes through the shared `from_http_status` table; else the string `type`
/// (falling back to a string `code`) buckets like the anthropic mid-stream table:
/// rate-limit-ish → `Provider{429}`, server/overloaded-ish → `Provider{500}`, else
/// retryable `Transport` — the honest read of a kindless / client-error body.