---
title: "Spring AI OpenAI starter with a custom base-url | BroadRouter"
description: "Point Spring AI's OpenAI chat starter at BroadNet Inference with spring.ai.openai.base-url, a BroadNet model ID and max-tokens, then call it from ChatClient."
url: https://broadrouter.com/guides/spring-ai-openai-base-url/
lang: en
updated: 2026-11-16
publisher: BroadRouter (a BroadNet site); API by BroadNet Inference, https://inference.broadnet.ai
---

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

Updated 2026-11-16

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

```xml
<dependency>
  <groupId>org.springframework.ai</groupId>
  <artifactId>spring-ai-starter-model-openai</artifactId>
</dependency>
```

## Configure

`application.properties`:

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

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

```java
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](https://broadrouter.com/pricing/).

## 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](https://broadrouter.com/guides/reasoning-tokens-empty-response/).
-   **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](https://broadrouter.com/guides/errors-and-retries/).

## Terms in this guide

[Pay-as-you-go](https://broadrouter.com/glossary/pay-as-you-go/)

Pay-as-you-go is a pricing model in which you pay only for what you use, metered per unit such as tokens, requests or audio minutes, with no subscription or minimum commitment. Most LLM APIs bill this way, from a prepaid balance or a periodic invoice.

[Token](https://broadrouter.com/glossary/token/)

A token is the unit of text a language model reads and writes: a word, part of a word, a punctuation mark or a byte sequence produced by the model's tokenizer. LLM APIs count, limit and usually bill usage in tokens.

[Base URL](https://broadrouter.com/glossary/base-url/)

A base URL is the fixed root address of an API, such as https://api.example.com/v1, that a client puts in front of every endpoint path, such as /chat/completions. In OpenAI-compatible SDKs, changing the base URL, together with the API key and model ID, points the same code at a different provider.

[Chat Completions API](https://broadrouter.com/glossary/chat-completions-api/)

The Chat Completions API is OpenAI's HTTP endpoint, POST /v1/chat/completions, that takes a model name and a list of role-tagged messages and returns the model's next message. Its request and response shape became the common format that OpenAI-compatible providers and SDKs reuse.

[Concurrency](https://broadrouter.com/glossary/concurrency/)

Concurrency is the number of requests a client has in flight at the same time. LLM APIs often cap it per key or plan, separately from requests per minute, because each open request holds GPU capacity until its response has finished.

[Context window](https://broadrouter.com/glossary/context-window/)

A context window is the maximum number of tokens a language model can work with in a single request. It covers the prompt, conversation history, tool definitions, images and the generated output, including any reasoning tokens. Anything that does not fit must be cut, summarised or split across several requests.

[Embeddings](https://broadrouter.com/glossary/embeddings/)

Embeddings are lists of floating-point numbers (vectors) that a model produces to represent a piece of text, an image or other input. Inputs with similar meaning get vectors that are close together, so distance between vectors can rank search results, cluster documents or find related items.

[Exponential backoff](https://broadrouter.com/glossary/exponential-backoff/)

Exponential backoff is a retry strategy in which a client waits longer after each failed attempt, typically doubling the delay up to a cap, before trying again. Adding random jitter to each wait spreads out retries from many clients so they do not hit the server at the same moment.

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

## Related guides

-   [Call BroadNet Inference from Go with the openai-go SDK](https://broadrouter.com/guides/openai-go-sdk/)
-   [Use the OpenAI Python SDK with BroadNet Inference](https://broadrouter.com/guides/openai-python-sdk/)
-   [Why a reasoning model returns an empty answer](https://broadrouter.com/guides/reasoning-tokens-empty-response/)
-   [BroadNet Inference error codes and when to retry](https://broadrouter.com/guides/errors-and-retries/)
-   [All tools that work with BroadNet Inference](https://broadrouter.com/integrations/): SDKs, coding agents, chat UIs and automation tools, with exact settings for each

Try it on your real workload. New accounts start with $5 of credit for Gemma and transcription. DeepSeek, GLM and Qwen3.8 need a top-up.

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=guides-spring-ai-openai-base-url&utm_content=page-cta) ·

**Sources**

-   [Spring AI reference, OpenAI Chat (2.0.2) (checked 2026-11-15)](https://docs.spring.io/spring-ai/reference/api/chat/openai-chat.html)
-   [Spring AI source at v2.0.2, OpenAiSetup.calculateBaseUrl (checked 2026-11-16)](https://github.com/spring-projects/spring-ai/blob/v2.0.2/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/setup/OpenAiSetup.java)
-   [BroadNet Inference API reference (checked 2026-11-15)](https://inference.broadnet.ai/docs?utm_source=broadrouter&utm_medium=referral&utm_campaign=guides-spring-ai-openai-base-url&utm_content=sources)
