VALID_SECURITY_TIERS = Set.of("standard", "high", "maximum");
-
/**
- * Standard security tier — GPU general secure inference.
+ * GPU general secure inference.
*/
public static final String SECURITY_TIER_STANDARD = "standard";
-
/**
- * High security tier — CPU/GPU for sensitive business data.
+ * CPU/GPU for sensitive business data.
*/
public static final String SECURITY_TIER_HIGH = "high";
-
/**
- * Maximum security tier — CPU only for PHI/classified data.
+ * CPU only for PHI/classified data.
*/
public static final String SECURITY_TIER_MAXIMUM = "maximum";
// ── Endpoint Paths ──────────────────────────────────────────────
/**
- * PKI public key endpoint path.
+ * PKI public key endpoint.
*/
public static final String PKI_PUBLIC_KEY_PATH = "/pki/public_key";
-
/**
- * Secure chat completion endpoint path.
+ * Secure chat completion endpoint.
*/
public static final String SECURE_COMPLETION_PATH = "/v1/chat/secure_completion";
@@ -143,24 +123,20 @@ public final class Constants {
* Content-Type for encrypted payloads.
*/
public static final String CONTENT_TYPE_OCTET_STREAM = "application/octet-stream";
-
/**
- * HTTP header name for payload ID.
+ * Header name for payload ID.
*/
public static final String HEADER_PAYLOAD_ID = "X-Payload-ID";
-
/**
- * HTTP header name for client public key.
+ * Header name for client public key.
*/
public static final String HEADER_PUBLIC_KEY = "X-Public-Key";
-
/**
- * HTTP header name for security tier.
+ * Header name for security tier.
*/
public static final String HEADER_SECURITY_TIER = "X-Security-Tier";
-
/**
- * HTTP header prefix for Bearer token authorization.
+ * Bearer token prefix.
*/
public static final String AUTHORIZATION_BEARER_PREFIX = "Bearer ";
@@ -170,17 +146,14 @@ public final class Constants {
* Default NOMYO router base URL.
*/
public static final String DEFAULT_BASE_URL = "https://api.nomyo.ai";
-
/**
- * Default key directory name for persisted keys.
+ * Default key directory name.
*/
public static final String DEFAULT_KEY_DIR = "client_keys";
-
/**
* Default private key file name.
*/
public static final String DEFAULT_PRIVATE_KEY_FILE = "private_key.pem";
-
/**
* Default public key file name.
*/
@@ -189,7 +162,7 @@ public final class Constants {
// ── Memory Protection Constants ─────────────────────────────────
/**
- * Page size used for memory locking calculations (typically 4096 bytes).
+ * Page size for memory locking calculations.
*/
public static final int PAGE_SIZE = 4096;
}
diff --git a/src/main/java/ai/nomyo/Main.java b/src/main/java/ai/nomyo/Main.java
index 26a9c4d..786f2bb 100644
--- a/src/main/java/ai/nomyo/Main.java
+++ b/src/main/java/ai/nomyo/Main.java
@@ -3,8 +3,7 @@ package ai.nomyo;
import ai.nomyo.errors.SecurityError;
/**
- * @author NieGestorben
- * Copyright© (c) 2026, All Rights Reserved.
+ * Entry point — loads RSA keys and validates key length.
*/
public class Main {
@@ -16,7 +15,7 @@ public class Main {
try {
secureCompletionClient.validateRsaKey(secureCompletionClient.getPrivateKey());
} catch (SecurityError e) {
- System.out.println("RSA Key is to short!");
+ System.out.println("RSA Key is too short!");
return;
}
diff --git a/src/main/java/ai/nomyo/SecureChatCompletion.java b/src/main/java/ai/nomyo/SecureChatCompletion.java
index 4823961..879c121 100644
--- a/src/main/java/ai/nomyo/SecureChatCompletion.java
+++ b/src/main/java/ai/nomyo/SecureChatCompletion.java
@@ -7,45 +7,7 @@ import java.util.List;
import java.util.Map;
/**
- * High-level OpenAI-compatible entrypoint for the NOMYO secure API.
- *
- * This class provides a familiar API surface matching {@code openai.ChatCompletion.create()}.
- * All requests are automatically encrypted using hybrid AES-256-GCM + RSA-4096 encryption
- * before being sent to the NOMYO router.
- *
- * Usage
- * {@code
- * SecureChatCompletion client = new SecureChatCompletion(
- * "https://api.nomyo.ai",
- * false,
- * "your-api-key",
- * true,
- * "/path/to/keys",
- * 2
- * );
- *
- * Map response = client.create(
- * "Qwen/Qwen3-0.6B",
- * List.of(Map.of("role", "user", "content", "Hello, world!"))
- * );
- * }
- *
- * Streaming
- * Streaming is not supported. The server rejects streaming requests with HTTP 400.
- * Always use {@code stream=false} (the default).
- *
- * Security Tiers
- * The {@code security_tier} parameter controls the hardware isolation level:
- *
- * - {@code "standard"} — GPU inference (general secure inference)
- * - {@code "high"} — CPU/GPU (sensitive business data)
- * - {@code "maximum"} — CPU only (PHI, classified data)
- *
- *
- * Key Persistence
- * Set {@code keyDir} to a directory path to persist RSA keys to disk.
- * Keys are generated on first use and reused across all calls.
- * Set {@code keyDir} to {@code null} for ephemeral keys (in-memory only, lost on restart).
+ * High-level OpenAI-compatible entrypoint with automatic hybrid encryption (AES-256-GCM + RSA-4096).
*/
@Getter
public class SecureChatCompletion {
@@ -55,83 +17,45 @@ public class SecureChatCompletion {
private final String keyDir;
/**
- * Constructs a {@code SecureChatCompletion} with default settings.
- *
- * Uses the default NOMYO router URL ({@code https://api.nomyo.ai}),
- * HTTPS-only, secure memory enabled, ephemeral keys, and 2 retries.
+ * Default settings: {@code https://api.nomyo.ai}, HTTPS-only, secure memory, ephemeral keys, 2 retries.
*/
public SecureChatCompletion() {
this(Constants.DEFAULT_BASE_URL, false, null, true, null, Constants.DEFAULT_MAX_RETRIES);
}
/**
- * Constructs a {@code SecureChatCompletion} with the specified settings.
- *
- * @param baseUrl NOMYO Router base URL (HTTPS enforced unless {@code allowHttp} is {@code true})
- * @param allowHttp permit {@code http://} URLs (development only)
- * @param apiKey Bearer token for authentication (can also be passed per-call via {@link #create})
- * @param secureMemory enable memory locking/zeroing (warns if unavailable)
- * @param keyDir directory to persist RSA keys; {@code null} = ephemeral (in-memory only)
- * @param maxRetries retries on 429/500/502/503/504 + network errors (exponential backoff: 1s, 2s, 4s…)
+ * @param baseUrl NOMYO Router base URL (HTTPS enforced unless {@code allowHttp})
+ * @param allowHttp permit {@code http://} URLs (development only)
+ * @param apiKey Bearer token (can also be passed per-call via {@link #create})
+ * @param secureMemory enable memory locking/zeroing
+ * @param keyDir RSA key directory; {@code null} = ephemeral
+ * @param maxRetries retries on 429/500/502/503/504 + network errors (exponential backoff)
*/
- public SecureChatCompletion(
- String baseUrl,
- boolean allowHttp,
- String apiKey,
- boolean secureMemory,
- String keyDir,
- int maxRetries
- ) {
+ public SecureChatCompletion(String baseUrl, boolean allowHttp, String apiKey, boolean secureMemory, String keyDir, int maxRetries) {
this.client = new SecureCompletionClient(baseUrl, allowHttp, secureMemory, maxRetries);
this.apiKey = apiKey;
this.keyDir = keyDir;
}
/**
- * Creates a chat completion with the specified parameters.
+ * Main entrypoint — same signature as {@code openai.ChatCompletion.create()}.
+ * All kwargs are passed through to the OpenAI-compatible API.
+ * Streaming is not supported (server rejects with HTTP 400).
+ * Security tiers: "standard", "high", "maximum".
*
- *
This is the main entrypoint, with the same signature as
- * {@code openai.ChatCompletion.create()}. Returns a map (not an object)
- * containing the OpenAI-compatible response.
- *
- * Parameters
- *
- * | Param | Type | Required | Description |
- * | {@code model} | {@code String} | yes | Model identifier, e.g. "Qwen/Qwen3-0.6B" |
- * | {@code messages} | {@code List | yes | OpenAI-format messages |
- * | {@code temperature} | {@code Double} | no | 0–2 |
- * | {@code maxTokens} | {@code Integer} | no | Maximum tokens in response |
- * | {@code topP} | {@code Double} | no | Top-p sampling parameter |
- * | {@code stop} | {@code String | List} | no | Stop sequences |
- * | {@code presencePenalty} | {@code Double} | no | -2.0 to 2.0 |
- * | {@code frequencyPenalty} | {@code Double} | no | -2.0 to 2.0 |
- * | {@code n} | {@code Integer} | no | Number of completions |
- * | {@code bestOf} | {@code Integer} | no | |
- * | {@code seed} | {@code Integer} | no | Reproducibility seed |
- * | {@code logitBias} | {@code Map} | no | Token bias map |
- * | {@code user} | {@code String} | no | End-user identifier |
- * | {@code tools} | {@code List | no | Tool definitions passed through to llama.cpp |
- * | {@code toolChoice} | {@code String} | no | "auto", "none", or specific tool name |
- * | {@code responseFormat} | {@code Map} | no | {"type": "json_object"} or {"type": "json_schema", ...} |
- * | {@code stream} | {@code Boolean} | no | NOT supported. Server rejects with HTTP 400. Always use {@code false}. |
- * | {@code baseUrl} | {@code String} | no | Per-call override (creates temp client internally) |
- * | {@code securityTier} | {@code String} | no | "standard", "high", or "maximum". Invalid values raise {@code ValueError}. |
- * | {@code apiKey} | {@code String} | no | Per-call override of instance {@code apiKey}. |
- *
- *
- * @param model model identifier (required)
- * @param messages OpenAI-format message list (required)
- * @param kwargs additional OpenAI-compatible parameters
- * @return OpenAI-compatible response map (see §6.2 of reference docs)
- * @throws SecurityError if encryption/decryption fails
- * @throws APIConnectionError if a network error occurs
- * @throws InvalidRequestError if the API returns 400
- * @throws AuthenticationError if the API returns 401
- * @throws ForbiddenError if the API returns 403
- * @throws RateLimitError if the API returns 429
- * @throws ServerError if the API returns 500
- * @throws ServiceUnavailableError if the API returns 503
- * @throws APIError for other errors
+ * @param model model identifier (required)
+ * @param messages OpenAI-format message list (required)
+ * @param kwargs additional OpenAI-compatible params (temperature, maxTokens, etc.)
+ * @return decrypted response map
+ * @throws SecurityError encryption/decryption failure
+ * @throws APIConnectionError network error
+ * @throws InvalidRequestError HTTP 400
+ * @throws AuthenticationError HTTP 401
+ * @throws ForbiddenError HTTP 403
+ * @throws RateLimitError HTTP 429
+ * @throws ServerError HTTP 500
+ * @throws ServiceUnavailableError HTTP 503
+ * @throws APIError other errors
*/
public Map create(String model, List