spring-projects / spring-projects/spring-ai

Support for Extensible API Parameters in Chat Clients

Open
#4,969 2 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

Issue: Support for Extensible API Parameters in Chat Clients

Problem Description

Currently, when integrating with AI providers that are partially compatible with OpenAI but have additional or slightly different parameters, the Spring AI framework lacks extensibility. The existing ChatClient implementations only expose a limited set of parameters defined in their respective ChatOptions classes.

For example, when using Grok's API which supports web search functionality, the required parameter is:

{
    "search_parameters": {
        "mode": "auto"
    }
}

Whereas OpenAI uses web_search_options with different key structures. The current implementation doesn't allow passing these vendor-specific parameters without copying and modifying the entire spring-ai-starter-model-openai implementation.

Proposed Solution

I suggest adding extensibility mechanisms to allow users to pass additional vendor-specific parameters without breaking the existing API. Here are some possible approaches:

  1. Extensible Options Classes: Add a Map<String, Object> extraParams field to base option classes like OpenAiChatOptions that gets merged into the final request.

  2. Custom Parameter Interceptor: Support a pluggable interceptor mechanism that allows modifying requests before they're sent.

  3. Vendor-Specific Option Extensions: Create extension points for vendor-specific option classes while maintaining the core interface.

Example Usage

If implemented, users could easily add custom parameters:

// Approach 1: Using extra parameters map
OpenAiChatOptions options = OpenAiChatOptions.builder()
    .withModel("grok-4")
    .withExtraParam("search_parameters", Map.of("mode", "auto"))
    .build();

// Approach 2: Using vendor-specific options  
GrokChatOptions options = GrokChatOptions.builder()
    .withModel("grok-4")
    .withSearchParameters(Map.of("mode", "auto"))
    .build();
Benefits
  • Backward Compatible: Existing code continues to work unchanged
  • Flexible: Supports any current and future vendor-specific parameters
  • Clean Architecture: Avoids the need for users to copy-paste-modify entire implementations
  • Type Safety: Could be implemented with both type-safe and dynamic approaches
Workarounds Currently Required

Currently, users have to:

  1. Copy the entire OpenAiChatClient implementation
  2. Modify the request creation logic
  3. Maintain this fork separately

This is cumbersome and defeats the purpose of using a framework.

Additional Context
  • Spring AI Version: [Your Spring AI version]
  • Affected Modules: spring-ai-starter-model-openai, potentially other model starters
  • Related APIs: Any AI provider with OpenAI-compatible but extended APIs (Grok, Claude, etc.)

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 the ChatClient implementations and ChatOptions classes in spring-ai-starter-model-openai, especially the request creation logic described in the issue. Compare the proposed extra-parameter, interceptor, and vendor-specific extension approaches across the affected model starters. Done means vendor-specific parameters can be passed without copying the client, while existing usage remains compatible.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.