spring-projects / spring-projects/spring-ai

[Vertex AI] `credentials-uri` property is ignored when transport is set to 'grpc'

Open
#5,218 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

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.transport is set to rest (or left default), the application successfully authenticates using the JSON key file defined in spring.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 with UNAUTHENTICATED. It appears that the credentials-uri property is ignored or not correctly propagated to the gRPC client builder.
  • Workaround: Setting the GOOGLE_APPLICATION_CREDENTIALS environment variable resolves the issue for gRPC mode. This confirms that the key file is valid, but the Spring property mapping for credentials-uri is 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

  1. Configure build.gradle.kts with Spring AI 1.1.2 and Vertex AI Gemini starter.
  2. Set application.properties to use gRPC (transport=GRPC) and a file-based credential URI (credentials-uri=file:...).
  3. 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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.