api7 / api7/aisix

test(e2e): cover streaming usage chunk passthrough across providers

Open
#149 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement gap-with-litellm priority-normal
Dominant language
Rust
Stars
157
Forks
32
Avg merge
1h 25m
Merged PRs (30d)
145

Description

Background

Surfaced from #148 audit (M2). The cross-provider matrix non-stream test asserts `completion.usage.total_tokens` round-trips, but the streaming variant has no `usage` assertion — the test's mock SSE chunks don't include a `usage:` field.

Gap

OpenAI's streaming wire supports `stream_options: {include_usage: true}` which appends a final chunk like:

```
data: {"choices":[],"usage":{"prompt_tokens":N,"completion_tokens":M,"total_tokens":K}}
```

Today the matrix tests don't exercise that path, so a regression where the gateway:

  • drops the final usage-only chunk
  • mistranslates `usage` field names across providers
  • forwards usage on the wrong chunk

would not be caught.

Proposed coverage

Add a streaming case (per provider) that:

  1. Caller passes `stream_options: { include_usage: true }`
  2. Mock upstream emits the final usage-bearing chunk
  3. Test asserts the SDK surfaces `chunk.usage` on the matching chunk

References:

Priority

P2 — feature-coverage gap, not a regression. Track alongside other matrix-tightening tasks.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in tests/e2e/src/cases/cross-provider-matrix-e2e.test.ts and compare the existing non-stream usage assertion with the streaming cases and mock SSE chunks. Add the per-provider stream_options case with a final usage-bearing chunk, then verify that chunk.usage is surfaced on the matching chunk for every provider.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, testing-qa
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.