spring-projects / spring-projects/spring-ai
[Vertex AI] `credentials-uri` property is ignored when transport is set to 'grpc'
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
I am using spring-ai-starter-model-vertex-ai-gemini to analyze audio files using the Gemini model.
I encountered an authentication issue specifically when switching the transport mode to gRPC.
- Scenario A (REST - Working): When
spring.ai.vertex.ai.gemini.transportis set torest(or left default), the application successfully authenticates using the JSON key file defined inspring.ai.vertex.ai.gemini.credentials-uri. - Scenario B (gRPC - Failing): When I explicitly set
spring.ai.vertex.ai.gemini.transport=GRPC(to handle larger payloads/timeouts), the application fails withUNAUTHENTICATED. It appears that thecredentials-uriproperty is ignored or not correctly propagated to the gRPC client builder. - Workaround: Setting the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable resolves the issue for gRPC mode. This confirms that the key file is valid, but the Spring property mapping forcredentials-uriis broken when using the gRPC transport.
Environment
- Spring AI version: 1.1.2
- Spring Boot version: 3.4.4
- Java version: 21
- Kotlin version: 1.9.25
- OS: macOS Tahoe 26.2
Steps to reproduce
- Configure
build.gradle.ktswith Spring AI 1.1.2 and Vertex AI Gemini starter. - Set
application.propertiesto use gRPC (transport=GRPC) and a file-based credential URI (credentials-uri=file:...). - Attempt to call
chatModel.call().
Minimal Complete Reproducible example
build.gradle.kts
plugins {
id("org.springframework.boot") version "3.4.4"
kotlin("jvm") version "1.9.25"
}
extra["springAiVersion"] = "1.1.2"
dependencies {
implementation("org.springframework.ai:spring-ai-starter-model-vertex-ai-gemini")
implementation(platform("org.springframework.ai:spring-ai-bom:${property("springAiVersion")}"))
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
}
application.properties
# Vertex AI Gemini Configuration
spring.ai.vertex.ai.gemini.project-id=my-project-id
spring.ai.vertex.ai.gemini.location=us-central1
spring.ai.vertex.ai.gemini.chat.options.model=gemini-2.5-flash
# [ISSUE HERE] This credential is ignored when transport is GRPC
spring.ai.vertex.ai.gemini.credentials-uri=file:src/main/resources/service-account-key.json
# If this is set to GRPC, authentication fails (UNAUTHENTICATED).
# If commented out (REST), it works.
spring.ai.vertex.ai.gemini.transport=GRPC
Controller (Kotlin)
@RestController
class TestController(private val chatModel: VertexAiGeminiChatModel) {
@GetMapping("/test")
fun test(): String {
// This call fails with UNAUTHENTICATED when transport=grpc
// unless GOOGLE_APPLICATION_CREDENTIALS env var is set.
return chatModel.call("Hello World")
}
}
Stack Trace
io.grpc.StatusRuntimeException: UNAUTHENTICATED: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential.
...
Caused by: java.net.SocketTimeoutException: Read timed out
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 at the VertexAiGeminiChatModel configuration entry point and trace how credentials-uri is passed when transport is set to GRPC. Reproduce the issue with the supplied application.properties and service-account key, then verify that the gRPC call authenticates without GOOGLE_APPLICATION_CREDENTIALS.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- google-cloud, grpc, java, kotlin, spring, spring-boot
- Domain
- api, backend, cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100