Installation
Configuration
Configure the SDK once at application startup using the builder pattern:Configuration options
* Required if the corresponding environment variable is not set.
The SDK is thread-safe. Call
Cognisafe.configure() once at startup (e.g., in your Spring @Configuration class or main() method) — it initialises a shared singleton. Do not call configure() per-request.Patching the OpenAI Java client
Cognisafe.openAIClient() returns a standard OpenAIClient with the baseUrl pre-configured to point at the Cognisafe proxy. You can also configure your own client by setting the base URL manually:
The @CognisafeTrace annotation (Spring Boot)
For Spring Boot applications, use the @CognisafeTrace annotation on any method that calls an LLM. The SDK uses Spring AOP to intercept the call and log the inputs and outputs:
- Method arguments (serialised to JSON)
- Return value (serialised to JSON)
- Execution time (latency)
/internal/log in a background thread — the annotated method is not blocked.
@CognisafeTrace requires the cognisafe-sdk-spring module. Add it alongside the core SDK:Non-Spring usage (manual trace)
Without Spring AOP, wrap calls manually usingCognisafe.trace():

