AISIX 1.7.1: Make Cross-Provider Stream Usage an Explicit Contract
October 27, 2026
Streaming clients often treat the final chat-completion frame as a convenient place to collect token usage. That works only until a provider reports usage on a different event—or a gateway makes one provider's behavior look like a portable contract.
AISIX 1.7.1, released October 27, 2026, changes how /v1/chat/completions streams expose stream_options.include_usage across supported upstreams. For a stream that completes without an error and has a usage report, AISIX prepares a usage-only chunk after the other chunks when the client requests it. A client that does not ask receives no usage in stream chunks. This response change does not itself change AISIX usage events, TPM limits, or billing.
Application code can decide whether it needs stream usage and parse the terminal shape when a report is available. An interrupted or failed stream, an upstream that provides no usage report, or an output guardrail that blocks held content may prevent that chunk from reaching the client. The accompanying 1.7.1 parameter changes address a separate compatibility question: whether a target platform accepts a field a caller sends.
The Upgrade Risk: Usage Was Not Previously Portable
Before 1.7.1, some upstreams exposed usage on their finish event even when the caller had not requested include_usage. That meant a client could appear to work with one provider while depending on a response detail that was absent—or differently timed—on another.
After the upgrade, request usage deliberately when the client consumes it:
{ "model": "your-model", "stream": true, "stream_options": { "include_usage": true }, "messages": [{ "role": "user", "content": "Summarize this report." }] }
When a stream finishes without error and the gateway has a usage report, AISIX emits a usage-only chunk with an empty choices array after the other chunks. In a local test using AISIX 1.7.1 and a simulated OpenAI-compatible upstream, the final portion was:
data: {"choices":[{"index":0,"delta":{},"finish_reason":"stop"}]} data: {"choices":[],"usage":{"prompt_tokens":21,"completion_tokens":5,"total_tokens":26}}
These excerpts omit envelope fields from the actual gateway response for readability; the upstream and token counts were simulated. They show the response shape for this completed test, not a provider charge or a guarantee for interrupted streams.
Do not assume that an event with finish_reason also has usage; in this contract, the usage-only chunk follows it. Conversely, when include_usage is omitted or false, no response chunk carries usage. AISIX can still record gateway usage for its own observability and controls; that recording is separate from what a streaming caller receives.
Build One Consumer Path for Every Supported Upstream
This change helps teams route an OpenAI-shaped client through Claude, Vertex Gemini, and OpenAI-compatible targets. Their upstream event formats differ; when a terminal usage report is available, callers can consume the normalized shape.
Use a consumer path that does three things:
- Render deltas while
choicescontains content. - Treat a chunk with a finish reason as completion of generated content, not as the usage record.
- When usage is requested and a usage-only chunk arrives, read it where
choicesis empty; handle its absence on errors, disconnects, missing upstream usage, or a guardrail block.
The tagged AISIX 1.7.1 E2E test exercises this with mocked Anthropic, Vertex Claude, Vertex Gemini, and OpenAI-compatible streams. In those test cases, each returns one usage-only terminal chunk with the same reported totals, while a request without include_usage exposes no usage chunk. The test also checks an adapter boundary: the OpenAI-compatible target receives stream_options, while the three mocked Claude and Gemini paths do not receive that OpenAI-specific field.
This is not a claim that all streaming behavior is identical. Content cadence, provider stop conditions, model availability, and upstream token reporting remain provider-specific. Applications that need an accounting decision should also keep gateway-recorded usage distinct from a provider invoice.
Audit the Compatibility Change Separately
AISIX 1.7.1 also changes how some request fields are handled. The release notes describe cases where values are forwarded in the target's form and an upstream rejection is surfaced. Mappings and omissions depend on the adapter and request: for example, the Anthropic adapter drops tool_choice when no tool survives translation. Validate each path rather than assuming every documented field is forwarded.
That difference is visible during an upgrade. A request that relied on the gateway silently dropping a field can now receive an upstream 400. The release notes call out examples including stop for some Bedrock models, temperature, top_p, or logprobs for a reasoning GPT on Bedrock, a tool strict value unsupported by a model, and a Gemini 2.5 thinking budget above the model ceiling.
Use this pre-production check for every provider/model pair that matters to an application:
- Send the application's actual streaming request with
include_usage: truewhen it reads usage. - Inventory optional parameters, especially sampling, stop, structured-output, tool, and reasoning fields.
- Confirm the target model documents each field and its allowed values.
- Test the failure response as well as the success response; an upstream
400is now an expected compatibility signal, not necessarily a gateway regression.
Do not generalize from one bridge to all targets. AISIX still drops OpenAI-only fields on Claude chat where sending them would cause an Anthropic error, and each provider adapter has its own documented mappings and limits.
For current product and deployment context, see the AISIX AI Gateway overview; its current capabilities are separate from the version-specific changes discussed here.
Keep Rolling Upgrades Safe
The release notes include one shared-cache constraint. During a rolling upgrade or rollback, a 1.7.1 gateway can write a response-cache entry that has multiple choices or logprobs; a 1.7.0-or-earlier gateway sharing that cache cannot read that entry and reports a cache error. Other cache entries are unaffected.
Plan the upgrade around that boundary:
- Identify mixed-version gateways that share a response cache.
- Exercise a representative multi-choice or
logprobsrequest before allowing old and new gateways to share the cache. - Coordinate rollback criteria with the cache behavior, not only with deployment health.
- Update stream consumers before expecting usage in the terminal response path.
AISIX 1.7.1 lets streaming clients request a consistent usage-only terminal shape when a report is available. Handle missing usage on failed or interrupted streams and guardrail blocks. Review the full release and upgrade notes before deploying, and validate each provider/model parameter set in a non-production environment.


