Integration guide

Java integration with Plugsky

Plugsky is a plain HTTPS JSON API with an OpenAI-compatible shape, so Java works with java.net.http.HttpClient. No Plugsky-specific Java package is required.

Short answer. Call Plugsky from Java with HttpClient. POST to https://api.plugsky.com/v1/chat/completions with a Bearer key and a plugsky-* model ID. Chat, streaming, tools and embeddings work.

What the Java integration covers

This page is for Java applications calling Plugsky. The API is OpenAI-compatible HTTPS JSON. There is no official Plugsky Java SDK; the examples use java.net.http.HttpClient (Java 11+) with Jackson or org.json for parsing. A community OpenAI-compatible Java client also works.

Chat completion

Java
import java.net.URI;
import java.net.http.*;
import java.net.http.HttpRequest.BodyPublishers;

var client = HttpClient.newHttpClient();
var body = "{"model":"plugsky-pro","messages":[{"role":"user","content":"What is an OpenAI-compatible API?"}]}";
var req = HttpRequest.newBuilder()
    .uri(URI.create("https://api.plugsky.com/v1/chat/completions"))
    .header("Authorization", "Bearer " + System.getenv("PLUGSKY_API_KEY"))
    .header("Content-Type", "application/json")
    .POST(BodyPublishers.ofString(body))
    .build();
var resp = client.send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(resp.body());

Parsing the response

Parse with Jackson: read choices[0].message.content and usage.total_tokens. Check the status code before parsing.

Async and concurrency

Use HttpClient.sendAsync for non-blocking calls and compose results with CompletableFuture. Reuse a single HttpClient instance across threads. On Java 21 and later, virtual threads make blocking calls cheap, but still reuse the client and set explicit timeouts.

Streaming

Set stream: true and read the response body line by line. Each data: line is a JSON chunk; the stream ends with data: [DONE].

Tool calling

Send tools as an array of function definitions and read choices[0].message.tool_calls. Execute the function and append a tool result message before the next call.

Embeddings

POST to /v1/embeddings with {"model":"plugsky-embed","input":"hello"}; read data[0].embedding, length 2048.

Limits and gotchas

Main text models: 262,144-token context; plugsky-mistral-medium and vision models: 131,072; plugsky-translate: 32,768; embeddings: 8,192 input. Builder: 256K input / 32K output per request; Scale: 512K input / 32K output. Concurrency: Builder 10 / 600 RPM, Scale 16 / 1,200 RPM, Hobby 4 / 120 RPM. Cap max_tokens at the plan output ceiling. Reuse a single HttpClient instance.

Common errors

  • 401: missing, revoked or wrong-host key.
  • 404: wrong base URL path or unknown model ID.
  • 400 (context): input plus reserved output exceeds the window.
  • 429: RPM, concurrency or daily quota exhausted. Honour Retry-After.
  • 5xx: retry with jittered backoff.

Production checklist

  • Pin model IDs; load keys from configuration or a secret manager.
  • Reuse a single HttpClient with timeouts.
  • Cap max_tokens; log request IDs, model ID, usage and latency.
  • Test 429 and context-overflow paths before launch.

What we did not verify

  • We did not benchmark latency or throughput.
  • We did not test every community Java client.
  • We used https://api.plugsky.com/v1; confirm the host in your account docs.

Java-specific tips

Use java.net.http.HttpClient with HTTP/2 for better throughput, and set HttpRequest.Builder.timeout to avoid hanging calls. For JSON, Jackson's ObjectMapper is thread-safe and reusable. When parsing streaming responses, read lines with a BufferedReader and handle data: [DONE] as the terminator. Close response bodies promptly to avoid connection leaks.

Frequently asked questions

Is there an official Plugsky Java SDK?

No. The API is OpenAI-compatible HTTPS JSON, so use java.net.http.HttpClient with Jackson or org.json.

What base URL should Java code use?

Use https://api.plugsky.com/v1, including the /v1 suffix and without a trailing slash.

Does streaming work in Java?

Yes. Set stream: true and read the response body line by line; each data: line is a JSON chunk and the stream ends with data: [DONE].

Does tool calling work?

Yes via the tools parameter with standard OpenAI function schemas.

What embedding dimensions should I expect?

2,048 dimensions with an 8,192-token input window.

How do I fix a 401 or 404?

Confirm the key and host api.plugsky.com; use https://api.plugsky.com/v1 and a model ID from GET /v1/models.

Which JSON library should I use?

Jackson is common, but any JSON library works because the payloads are standard OpenAI JSON.

Related pages

Run your Java service on Plugsky

Start free, test your request path, then choose the plan that matches your concurrency.

Start Free → Read the docs

Sources

API behaviour was checked against the OpenAI API reference on 20 November 2026. Plugsky limits were checked against its docs on the same date.

Official pages used for this integration guide
SourcePage checkedChecked
OpenAIplatform.openai.com/docs/api-reference20 Nov 2026
Plugskyplugsky.com/docs and plugsky.com/pricing20 Nov 2026
Plugskyplugsky.com/models20 Nov 2026

Last checked 20 November 2026. Plugsky's canonical plan numbers live at /pricing; this page explains the integration and does not replace the plan terms.

Sources and dated checks

Checked 20 November 2026. Primary sources checked 20 November 2026: OpenAI API reference, Anthropic API getting started, Cloudflare Workers AI. Confirm current limits and pricing in the provider console before capacity planning.