Description
Bug description
I'm trying to use [Groq](https://groq.com) as an OpenAI-compatible provider with Spring AI (spring.ai.openai
) in version 1.0.0
. I have correctly configured the api-key
and base-url
. The same API key works as expected using curl
, but Spring AI consistently returns a 401 - Invalid API Key
when invoking ChatClient
.
Environment
- Spring AI version:
1.0.0
- Spring Boot version:
3.2.5
- Java version:
17
- Model:
llama3-70b-8192
- Groq base URL:
https://api.groq.com/openai
- API key format:
gsk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
(valid and confirmed viacurl
) - No vector store is used
Steps to reproduce
-
Configure
application.yml
as below:spring: ai: openai: api-key: gsk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx base-url: https://api.groq.com/openai chat: options: model: llama3-70b-8192 temperature: 0.7
-
Inject and use
ChatClient
:@Autowired private ChatClient chatClient; public String callGroq(String prompt) { return chatClient.prompt() .system("You are a helpful assistant.") .user(prompt) .call() .content(); }
-
Call the method.
Expected behavior
A valid chat completion response from Groq, the same as received when making the request via curl
.
Minimal Complete Reproducible example
Here’s the curl that works:
curl https://api.groq.com/openai/v1/chat/completions -s \
-H "Content-Type: application/json" \
-H "Authorization: Bearer gsk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-d '{
"model": "llama3-70b-8192",
"messages": [{"role": "user", "content": "Hello"}]
}'
This returns a valid response.
But with Spring AI, I receive this:
401 - {
"error": {
"message": "Invalid API Key",
"type": "invalid_request_error",
"code": "invalid_api_key"
}
}
Please advise if any custom headers or additional configuration is required to support Groq in Spring AI.
Let me know if you'd like to include a GitHub repo or sample project link as well to improve reproducibility.
Activity
KevinYe0725 commentedon May 27, 2025
Try adding the version number /v1/ to the URL part of application.yml .