Currently, Spring AI only provides a straightforward way to set custom HTTP headers in certain provider-specific integrations (e.g., spring.ai.azure.openai.custom-headers for Azure OpenAI). For other providers accessed via the ChatClient API — especially those using OpenAI-compatible endpoints like Google Gemini — there is no native mechanism to set provider-specific HTTP headers during client creation.
Expected Behavior Enable adding custom HTTP headers directly when building a ChatClient. For example:
ChatClient client = ChatClient.builder() .baseUrl("https://generativelanguage.googleapis.com/v1beta/openai/") .apiKey("...") .customHeader("X-Server-Throughput-Key", "my-throughput-token") .customHeader("Another-Header", "value") .build();
Benefits:
Simplifies integrating with providers that require extra headers (e.g., Gemini throughput provisioning keys, experimental API )
Context
I work for enterprise system. We have reserved provisioning throughput on vertex ai Gemini. But can't use it natively with Spring AI
Comment From: alanta335
have you tried using options
For example:
chatClient
.prompt()
.options(OpenAiChatOptions.builder()
.httpHeaders(Map.of("X-Server-Throughput-Key", "my-throughput-token"))
.build())