Skip to content

Commit b1bfee3

Browse files
authored
Merge pull request #2106 from aniketpandey05/docs/1863-trlp-supported-endpoints
docs: clarify TokenRateLimitPolicy supported endpoints and response formats
2 parents 41ffdf0 + 1a75f95 commit b1bfee3

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

doc/overviews/token-rate-limiting.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Kuadrant's Token Rate Limit implementation extends the Envoy [Rate Limit Service
2222

2323
This approach ensures accurate usage-based rate limiting where limits are enforced based on actual AI/LLM token consumption rather than simple request counts.
2424

25-
**Important**: Currently, TokenRateLimitPolicy only supports non-streaming OpenAI-style API responses (where `stream: false` or is omitted in the request). Support for streaming responses is planned for future releases.
25+
**Important**: TokenRateLimitPolicy supports both non-streaming and streaming OpenAI-style API responses. For streaming, the request must include `"stream": true` and `"stream_options": { "include_usage": true }` for usage to be extracted from the final stream event. Only OpenAI-style completions responses are supported today — this includes `/v1/chat/completions` and `/v1/completions`, and any backend implementing the OpenAI-compatible API such as vLLM and kServe. Other provider formats (e.g. Anthropic, Google Gemini) are not yet parsed; see [#1864](https://github.com/Kuadrant/kuadrant-operator/issues/1864).
2626

2727
### The TokenRateLimitPolicy custom resource
2828

@@ -59,6 +59,7 @@ TokenRateLimitPolicy automatically extracts token usage from AI/LLM responses wi
5959

6060
- **Zero configuration**: Works out-of-the-box with OpenAI-compatible APIs
6161
- **Response parsing**: Automatically extracts `usage.total_tokens` from response bodies
62+
- **Provider scope**: Supports any backend returning that field, e.g. OpenAI `/v1/chat/completions` and `/v1/completions`, and OpenAI-compatible backends like vLLM, kServe, Ollama, Azure OpenAI, and Gemini's OpenAI-compat endpoint. Anthropic and Gemini's native response formats aren't supported yet — see [#1864](https://github.com/Kuadrant/kuadrant-operator/issues/1864)
6263
- **Accurate accounting**: Tracks actual token consumption, not estimates
6364
- **Graceful fallback**: If token parsing fails, falls back to request counting
6465

doc/reference/tokenratelimitpolicy.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ The policy automatically parses token usage from response bodies in the followin
113113

114114
This is compatible with OpenAI-style API responses and similar AI/LLM services.
115115

116+
**What's actually checked**: Token extraction looks for a single JSON pointer, `/usage/total_tokens`, in the response body. Any backend that returns that exact field works out of the box, including OpenAI Chat Completions (`/v1/chat/completions`), OpenAI legacy Completions (`/v1/completions`), OpenAI Embeddings, and OpenAI-compatible backends like vLLM, kServe, Ollama, Azure OpenAI, and Gemini's OpenAI-compatibility endpoint.
117+
118+
**Not currently supported**: Providers that return token usage under a different field name — Anthropic's `/v1/messages` (`usage.input_tokens` / `usage.output_tokens`, no `total_tokens`) or Google Gemini's native endpoint (`usageMetadata.totalTokenCount`) — are not parsed. Multi-provider support is tracked in [#1864](https://github.com/Kuadrant/kuadrant-operator/issues/1864).
119+
116120
**Streaming Support**: Both streaming and non-streaming responses are supported:
117121
- **Non-streaming**: Works with `stream: false` or when `stream` is omitted
118122
- **Streaming**: Requires `"stream": true` and `"stream_options": { "include_usage": true }` to extract usage from the final stream event

0 commit comments

Comments
 (0)