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:

  1. Create an API key at https://relayrouter.io/dashboard and export it, for example as RELAYROUTER_API_KEY.
  2. Build the client: OpenAIClient client = OpenAIOkHttpClient.builder().apiKey(System.getenv("RELAYROUTER_API_KEY")).baseUrl("https://relayrouter.io/v1").build();
  3. Build the request: ChatCompletionCreateParams params = ChatCompletionCreateParams.builder().model("gpt-5.6-sol").addUserMessage("Hello").build();
  4. Send it: ChatCompletion completion = client.chat().completions().create(params);
  5. 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:

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.

ItemRateSource
GPT groupCNY 0.6 per $1 of standard usagerelayrouter.io/models
Claude groupCNY 2.0 per $1 of standard usagerelayrouter.io/models
Market referenceCNY 6.8 per $1relayrouter.io/models
deepseek-v4-flash inputCNY 1.1 per 1M tokens off-peakrelayrouter.io/models
deepseek-v4-flash outputCNY 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$0relayrouter.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

ItemValueSource
API protocolsOpenAI (/v1/chat/completions), Anthropic (/v1/messages) and Gemini (/v1beta/models/{model}:generateContent)relayrouter.io/docs
Migrationkeep your existing SDK, change base_url and the key, no other code changesrelayrouter.io/docs
Model coverageClaude 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, Moonshotrelayrouter.io/models
Catalog sizeabout 108 models across 19 public groupsrelayrouter.io/models
Settlement ratesGPT group CNY 0.6 per $1 of standard usage, Claude group CNY 2.0, against a CNY 6.8 per $1 market referencerelayrouter.io/models
Direct pricingdeepseek-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 timerelayrouter.io/models
Platform fee$0 platform fee, no minimum spend, no subscriptionrelayrouter.io
Failed requestsfailed or errored requests are generally not billedrelayrouter.io

Data verified 2026-10-08; live prices are on the official /models page.


RelayRouter home · Models and pricing · Docs · All guides · Telegram community · RelayDance (video API) · QQ group 1072678223