BroadRouter

Use Spring AI with BroadNet Inference (OpenAI base-url)

Updated

Add spring-ai-starter-model-openai, then set spring.ai.openai.base-url to https://inference.broadnet.ai/v1, spring.ai.openai.api-key to your BroadNet key and spring.ai.openai.chat.model to a BroadNet ID such as broadnet/glm-5.3. Set spring.ai.openai.chat.max-tokens with room for reasoning. Spring AI 2.x uses the openai-java SDK, which appends /chat/completions to the base URL.

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, not max-completion-tokens. Spring AI’s docs say they are mutually exclusive and setting both is an error. BroadNet’s API reference describes max_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_content from OpenAI-compatible servers that return it. BroadNet’s API reference reports reasoning token counts in usage but doesn’t promise the reasoning text itself, so don’t depend on it.
  • Chat-only override. spring.ai.openai.chat.base-url and spring.ai.openai.chat.api-key take 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-attempts defaults 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

Prices for every model.

Troubleshooting

  • 401. The key is wrong, expired or out of allowance, or BROADNET_API_KEY isn’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 only broadnet/gemma-4-26b-a4b and the two Transcribe models.
  • Empty content(). Reasoning used the output budget. Raise max-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.

Questions

Should spring.ai.openai.base-url include /v1?

Yes. In Spring AI 2.x the value is passed unchanged to the openai-java client, whose own default is https://api.openai.com/v1. Use https://inference.broadnet.ai/v1.

Should I use max-tokens or max-completion-tokens with BroadNet?

max-tokens. Spring AI's docs say the two are mutually exclusive. BroadNet's API reference describes the max_tokens field, and reasoning counts toward it, so allow 1,000 tokens or more.

Does Spring AI tool calling work with BroadNet?

Use GLM 5.3 or Qwen3.8 27B, which BroadNet lists with tools. BroadNet's docs don't list tool calling for DeepSeek V4.1 Flash.

Can I keep OpenAI for embeddings and use BroadNet for chat?

Yes. spring.ai.openai.chat.base-url and spring.ai.openai.chat.api-key override the shared properties for the chat model only. BroadNet's API reference doesn't list an embeddings endpoint.

Read as MarkdownAsk ChatGPTAsk ClaudeAsk Perplexity