spring-projects / spring-projects/spring-ai
OpenAI rate-limit metadata is always EmptyRateLimit in Spring AI 2.0.0
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
Bug description
When using the OpenAI chat model with Spring AI 2.0.0, the rate-limit metadata returned by ChatResponse is always an instance of EmptyRateLimit.
The completion, model metadata, and token usage are populated correctly, but the OpenAI rate-limit response headers do not appear to be mapped to ChatResponseMetadata.
I believe rate-limit metadata was available in earlier Spring AI 2.0.0 milestone versions, possibly up to 2.0.0-M1, but it is no longer available in the final 2.0.0 release.
Environment
Spring AI: 2.0.0
OpenAI chat model
Model: gpt-5-mini-2025-08-07
Java: 21
Steps to reproduce
ChatResponse chatResponse = chatClient.prompt()
.user("Which country has the largest population in Europe?")
.call()
.chatResponse();
log.info("completion = {}", chatResponse.getResult().getOutput().getText());
log.info("model = {}", chatResponse.getMetadata().getModel());
var usage = chatResponse.getMetadata().getUsage();
log.info("usage = {}", usage);
var rateLimit = chatResponse.getMetadata().getRateLimit();
log.info("rateLimit = {}", rateLimit);
The completion, model, and usage information are returned correctly.
model = gpt-5-mini-2025-08-07
usage = DefaultUsage{
promptTokens=20,
completionTokens=655,
totalTokens=675,
cacheReadInputTokens=0
}
rateLimit = org.springframework.ai.chat.metadata.EmptyRateLimit@24eecabf
chatResponse.getMetadata().getRateLimit() always returns EmptyRateLimit.
Expected behavior
The OpenAI rate-limit response headers should be mapped to ChatResponseMetadata, allowing request and token limits, remaining values, and reset times to be accessed through getRateLimit().
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how the ChatClient call populates ChatResponseMetadata, focusing on getRateLimit() and the OpenAI response-header mapping. Reproduce the issue with the provided snippet and verify that request and token limits, remaining values, and reset times are accessible through getRateLimit() instead of EmptyRateLimit.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100