Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

anthropic-stream-failure-usage.spec.ts

27 lines882 Bytes

1import { test, expect } from './fixtures'
2​
3/**
4 * Regression for #1735. An Anthropic stream that fails after `message_start`
5 * ends in `RUN_ERROR`, and Anthropic bills the input tokens of that call. The
6 * `RUN_ERROR` must carry the counts that `message_start` reported.
7 */
8test.describe('anthropic stream that fails after message_start', () => {
9 test('RUN_ERROR carries the message_start usage', async ({ request }) => {
10 const res = await request.post('/api/anthropic-stream-failure-usage')
11 expect(res.ok()).toBe(true)
12​
13 const { ok, runError, error } = (await res.json()) as {
14 ok: boolean
15 error?: string
16 runError?: { usage?: Record<string, unknown> }
17 }
18​
19 expect(error ?? null).toBeNull()
20 expect(ok).toBe(true)
21 expect(runError?.usage).toEqual({
22 promptTokens: 18,
23 completionTokens: 1,
24 totalTokens: 19,
25 })
26 })
27})