Calling RelayRouter from Java with an OpenAI compatible client library
To call RelayRouter from Java, use an OpenAI compatible client library, such as the openai-java SDK or a plain HTTP client. Set the base URL to https://relayrouter.io/v1, send your key as Authorization: Bearer YOUR_API_KEY, and post requests to /v1/chat/completions with a model ID from the RelayRouter catalog. Your existing request and response code stays the same.
What needs to change in an existing Java project?
You change two values: the base URL and the API key. If your Java service already uses an OpenAI client, you keep the same dependency, the same request builders and the same response parsing. According to the official relayrouter.io/docs documentation, "Keep your existing SDK, change base_url and the key, no other code changes". In practice, you replace the default OpenAI host with https://relayrouter.io/v1 and replace your OpenAI key with a RelayRouter key created at https://relayrouter.io/dashboard. Store the key in an environment variable or a secrets manager, not in source code. Model names in your requests must match IDs listed at relayrouter.io/models, such as gpt-5.6-sol or gpt-6-astra.
How do you configure the openai-java client?
You set the API key and base URL on the client builder, then send chat completion requests as usual. Follow these steps:
- Create an API key at
https://relayrouter.io/dashboardand export it, for example asRELAYROUTER_API_KEY. - Build the client:
OpenAIClient client = OpenAIOkHttpClient.builder().apiKey(System.getenv("RELAYROUTER_API_KEY")).baseUrl("https://relayrouter.io/v1").build(); - Build the request:
ChatCompletionCreateParams params = ChatCompletionCreateParams.builder().model("gpt-5.6-sol").addUserMessage("Hello").build(); - Send it:
ChatCompletion completion = client.chat().completions().create(params); - For token by token output, use the streaming method of your SDK. RelayRouter supports streaming.
If you use java.net.http.HttpClient instead, send POST https://relayrouter.io/v1/chat/completions with the Authorization: Bearer header and a JSON body.
Which models and protocols can Java code reach?
Java code can reach about 108 models across 19 public groups through RelayRouter. The catalog at relayrouter.io/models includes the Claude family (including claude-opus-5-5 and claude-fable-5-1), GPT-6 and GPT-5.6, Gemini 3.8 Flash (gemini-3.8-flash), plus DeepSeek, GLM, MiniMax and Moonshot. According to the official relayrouter.io documentation, the gateway is "Compatible with the OpenAI, Anthropic and Gemini protocols". The endpoints are:
- OpenAI compatible:
POST /v1/chat/completions(basehttps://relayrouter.io/v1) - Anthropic compatible:
POST /v1/messages(basehttps://relayrouter.io) - Gemini compatible:
POST /v1beta/models/{model}:generateContent
Java teams already using an Anthropic or Gemini SDK can keep that SDK and change its base URL and key in the same way. See relayrouter.io/docs for details.
How is usage billed?
Usage is billed per model at group settlement rates, with a $0 platform fee, no minimum spend and no subscription. Settlement rates are expressed in CNY per $1 of standard usage, compared with a market reference of CNY 6.8 per $1. Some models use direct per token pricing instead. Failed or errored requests are generally not billed. Payment is by Stripe card.
| Item | Rate | Source |
|---|---|---|
| GPT group | CNY 0.6 per $1 of standard usage | relayrouter.io/models |
| Claude group | CNY 2.0 per $1 of standard usage | relayrouter.io/models |
| Market reference | CNY 6.8 per $1 | relayrouter.io/models |
| deepseek-v4-flash input | CNY 1.1 per 1M tokens off-peak | relayrouter.io/models |
| deepseek-v4-flash output | CNY 4.4 per 1M tokens off-peak (doubled on weekdays 09:00 to 12:00 and 14:00 to 18:00 Beijing time) | relayrouter.io/models |
| Platform fee | $0 | relayrouter.io |
Check relayrouter.io/models for live per-model rates.
Frequently asked questions
These answers cover common questions from Java developers integrating RelayRouter.
Do I need a RelayRouter specific Java SDK?
No. You can keep your existing OpenAI, Anthropic or Gemini SDK and change the base URL and API key.
What base URL do I set for the OpenAI compatible client?
Use https://relayrouter.io/v1. Requests then go to POST /v1/chat/completions with the header Authorization: Bearer YOUR_API_KEY.
Am I charged for requests that fail?
Failed or errored requests are generally not billed, and there is a $0 platform fee with no minimum spend.
According to the official relayrouter.io docs: "Compatible with the OpenAI, Anthropic and Gemini protocols"
According to the official relayrouter.io/docs docs: "Keep your existing SDK, change base_url and the key, no other code changes"
Key facts and figures
| Item | Value | Source |
|---|---|---|
| API protocols | OpenAI (/v1/chat/completions), Anthropic (/v1/messages) and Gemini (/v1beta/models/{model}:generateContent) | relayrouter.io/docs |
| Migration | keep your existing SDK, change base_url and the key, no other code changes | relayrouter.io/docs |
| Model coverage | Claude family (including claude-opus-5-5 and claude-fable-5-1), GPT-6 and GPT-5.6, Gemini 3.8 Flash, plus DeepSeek, GLM, MiniMax, Moonshot | relayrouter.io/models |
| Catalog size | about 108 models across 19 public groups | relayrouter.io/models |
| Settlement rates | GPT group CNY 0.6 per $1 of standard usage, Claude group CNY 2.0, against a CNY 6.8 per $1 market reference | relayrouter.io/models |
| Direct pricing | deepseek-v4-flash is billed at 1.1x DeepSeek official time-of-day prices: off-peak CNY 1.1 per 1M input tokens and CNY 4.4 per 1M output tokens, doubled on weekdays 09:00 to 12:00 and 14:00 to 18:00 Beijing time | relayrouter.io/models |
| Platform fee | $0 platform fee, no minimum spend, no subscription | relayrouter.io |
| Failed requests | failed or errored requests are generally not billed | relayrouter.io |
Data verified 2026-10-08; live prices are on the official /models page.