spring-projects / spring-projects/spring-ai

Expose raw provider response (including custom fields) in Spring AI client responses

Open
#4,901 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

Summary

When using Spring AI with custom providers (or providers that include additional
fields such as usage cost, billing, model metadata, etc.), the framework does
not currently expose the raw provider response or a structured way to access
custom fields that are not mapped into Spring AI’s default response models.

This limits the ability to read provider-specific metadata (e.g., cost fields)
that exist in the underlying API response but are not mapped by Spring AI.

Problem

Many LLM providers return additional fields in their JSON response.
Examples:

  • token-level cost breakdown
  • provider usage metadata
  • custom domain-specific values
  • provider-specific debugging fields

Spring AI currently:

  • parses responses into internal domain classes (ChatResponse, Generation,
    Metadata, etc.)
  • but drops unrecognized fields
  • and does not expose the raw JSON returned by the provider

Because of this, there is currently no way to access provider-specific
metadata
, even via Metadata, Advisors, or Interceptors.

What I Tried
  • Using Advisors (CallAdvisor, StreamAdvisorChain, etc.) — they provide
    access only to Spring AI domain models, not raw JSON.
  • Custom Observation handlers — still no access to unmapped fields.
  • Looking for Interceptors in the OpenAI client — not available.
  • Checking if Metadata preserves unknown fields — it does not.
Requested Feature

I’d like Spring AI to provide one or both of the following:

1. Access to the raw provider response

For example:

ChatResponse response = client.call(prompt);
String rawJson = response.rawResponse();

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 by reviewing ChatResponse, Generation, Metadata, Advisors, and Interceptors to understand where provider responses are mapped and where unmapped fields are lost. Decide which requested raw-response or custom-metadata API is appropriate, then verify that provider-specific fields remain accessible through the resulting client response.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
ai, api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.