Commit de3e8db
publish the per-request id as a
Claude Code records the `request-id` response header into every transcript
record as `requestId`. This proxy never sent one, so proxied transcripts carry
no request id at all: measured on a real session, 0 of 4 usage-bearing records
had one, against 753 of 756 in a native Anthropic session.
That matters because a transcript legitimately repeats a record, and the
request id is what downstream consumers use to resolve the repeat. Without it
they double-count. Claude Code's own parser reported 4 turns and 47,986 fresh
input tokens for a session whose true figures were 2 turns and 23,966; with the
header present it reports both correctly, unchanged.
The id already existed. `dispatch_request` mints `req_id` per request and
threads it through logging and the monitor; it simply never reached the
response. `RequestMonitorGuard` already carries it, and every response path in
this module funnels through `monitor_response_body`, which destructures the
response parts before streaming the body. Stamping it there covers all return
sites at once, and applies to a streaming SSE response as well, which the
body-level `message.id` cannot do because a stream's id arrives inside
`message_start` rather than in the headers.
An upstream-supplied header is preserved rather than overwritten: relabelling a
real provider id with a local uuid would lose the more useful value.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>request-id response header (#105)1 parent dc61029 commit de3e8db
1 file changed
Lines changed: 95 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1783 | 1783 | | |
1784 | 1784 | | |
1785 | 1785 | | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
1786 | 1790 | | |
1787 | 1791 | | |
1788 | 1792 | | |
1789 | 1793 | | |
1790 | 1794 | | |
1791 | 1795 | | |
1792 | | - | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
1793 | 1811 | | |
1794 | 1812 | | |
1795 | 1813 | | |
| |||
2144 | 2162 | | |
2145 | 2163 | | |
2146 | 2164 | | |
| 2165 | + | |
| 2166 | + | |
| 2167 | + | |
| 2168 | + | |
| 2169 | + | |
| 2170 | + | |
| 2171 | + | |
| 2172 | + | |
| 2173 | + | |
| 2174 | + | |
| 2175 | + | |
| 2176 | + | |
| 2177 | + | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
| 2193 | + | |
| 2194 | + | |
| 2195 | + | |
| 2196 | + | |
| 2197 | + | |
| 2198 | + | |
| 2199 | + | |
| 2200 | + | |
| 2201 | + | |
| 2202 | + | |
| 2203 | + | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
| 2233 | + | |
| 2234 | + | |
| 2235 | + | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
| 2240 | + | |
2147 | 2241 | | |
2148 | 2242 | | |
2149 | 2243 | | |
| |||
0 commit comments