Spring AI is the Spring project’s framework for AI in Java. Its OpenAI chat starter reads a base-url, so it can call any OpenAI-compatible server. BroadNet Inference serves standard chat completions at https://inference.broadnet.ai/v1. BroadRouter is BroadNet’s own site; this follows the Spring AI 2.0.2 reference.
Add the starter
With the Spring AI BOM in place (see Spring AI’s dependency management docs):
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-openai</artifactId>
</dependency>
Configure
application.properties:
spring.ai.openai.base-url=https://inference.broadnet.ai/v1
spring.ai.openai.api-key=${BROADNET_API_KEY}
spring.ai.openai.chat.model=broadnet/glm-5.3
spring.ai.openai.chat.max-tokens=2000
export BROADNET_API_KEY='your-broadnet-key'
Keep /v1 in the URL. In Spring AI 2.x the value goes to the openai-java client unchanged (OpenAiSetup.calculateBaseUrl returns it as is), and that client adds /chat/completions. The default it replaces is https://api.openai.com/v1.
Call it and test
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
@Bean
CommandLineRunner smokeTest(ChatClient.Builder builder) {
return args -> {
ChatClient chat = builder.build();
System.out.println(chat.prompt().user("Say hello in five words.").call().content());
};
}
Start the app. A printed answer means the key, URL and model ID are right.
Settings that matter for BroadNet
max-tokens, notmax-completion-tokens. Spring AI’s docs say they are mutually exclusive and setting both is an error. BroadNet’s API reference describesmax_tokens. DeepSeek V4.1 Flash, GLM 5.3 and Qwen3.8 27B reason first, and the reasoning counts toward the limit.- Reasoning text. Spring AI can expose
reasoning_contentfrom OpenAI-compatible servers that return it. BroadNet’s API reference reports reasoning token counts inusagebut doesn’t promise the reasoning text itself, so don’t depend on it. - Chat-only override.
spring.ai.openai.chat.base-urlandspring.ai.openai.chat.api-keytake precedence over the shared properties for the chat model. Use them if other Spring AI OpenAI models (such as embeddings) must stay on OpenAI. - Retries.
spring.ai.retry.max-attemptsdefaults to 10 with exponential backoff. On a pay-as-you-go key that can burn through the per-minute limit; consider lowering it.
Which model to pick
| Use | spring.ai.openai.chat.model |
|---|---|
| Tool calling, structured output | broadnet/glm-5.3 |
| Images or Arabic text | broadnet/qwen3.8-27b |
| Long documents, flat-rate plan | broadnet/deepseek-v4.1-flash |
| Free starting credit | broadnet/gemma-4-26b-a4b |
Troubleshooting
- 401. The key is wrong, expired or out of allowance, or
BROADNET_API_KEYisn’t set for the JVM. - 404. The base URL is missing
/v1, or the model ID is wrong. Paid models need a top-up; the $5 credit covers onlybroadnet/gemma-4-26b-a4band the two Transcribe models. - Empty
content(). Reasoning used the output budget. Raisemax-tokens. Why answers come back empty. - 400 with both token limits set. Remove
max-completion-tokens. - 429. A pay-as-you-go key allows 30 requests a minute and 4 in flight. See errors and retries.
