Java SDK
Send chat.completions requests to GonkaGate from Java with openai-java.
Send one chat.completions request from Java with openai-java, then reuse the same client shape in your application code.
Minimum working example
Add the SDK:
implementation("com.openai:openai-java:4.29.0")Then run one chat.completions request:
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.chat.completions.ChatCompletion;
import com.openai.models.chat.completions.ChatCompletionCreateParams;
public class BasicUsage {
public static void main(String[] args) {
String apiKey = System.getenv("GONKAGATE_API_KEY");
if (apiKey == null || apiKey.isBlank()) {
throw new IllegalStateException("missing GONKAGATE_API_KEY");
}
OpenAIClient client = OpenAIOkHttpClient.builder()
.apiKey(apiKey)
.baseUrl("https://api.gonkagate.com/v1")
.build();
ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
.addUserMessage("Say hello from GonkaGate in one sentence.")
.model("qwen/qwen3-235b-a22b-instruct-2507-fp8")
.build();
ChatCompletion completion = client.chat().completions().create(params);
completion.choices().forEach(choice ->
choice.message().content().ifPresent(System.out::println)
);
}
}Expected result: if this prints text, your Java client is wired correctly.
Use a current model ID from GET /v1/models. The example value above is only illustrative.
What you need before you run it
- Java
8+, because that is the minimum version required byopenai-java - A
gp-...API key stored inGONKAGATE_API_KEY - Enough available balance for the request
- A current GonkaGate model ID
- If you use Maven instead of Gradle, use the same coordinates:
com.openai:openai-java:4.29.0
Java-specific notes
- Set
.baseUrl("https://api.gonkagate.com/v1")before you build the client. - Reuse one client per application where possible. The SDK maintains connection pools and thread pools internally.
- The default client is synchronous. If you need
CompletableFuture-based execution, switch toclient.async()or create anOpenAIOkHttpClientAsync. - If you copy older snippets, update the dependency version together with the rest of the example.
Common errors and limits
- If you forget
.baseUrl("https://api.gonkagate.com/v1"), the client still points at the default OpenAI endpoint. 401 invalid_api_keyusually means the key is missing, malformed, revoked, or tied to an unavailable account state.404 model_not_foundmeans the model ID is no longer available. Refresh it from GET /v1/models.429 insufficient_quotameans the available prepaid USD balance is too low for the request.
See also
- OpenAI SDK compatibility for the shared base URL, key format, model-selection rules, and additive
usagefields across runtimes. - Authentication and API Keys for key creation, secure storage, and rotation.
- GonkaGate API Reference Overview when the first Java request works and you need exact request fields, streaming behavior, and failure policy.
- GET /v1/models for the current machine-readable model IDs.
- OpenAI to GonkaGate Migration Guide if you are switching already-working OpenAI code instead of starting from zero.
Was this page helpful?