Documentation Index
Fetch the complete documentation index at: https://docs.cognisafe.uk/llms.txt
Use this file to discover all available pages before exploring further.
Installation
Configuration
Configure the SDK once at application startup using the builder pattern:Configuration options
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
apiKey | String | Yes* | COGNISAFE_API_KEY | Your project API key (csk_...) |
projectId | String | Yes* | COGNISAFE_PROJECT_ID | Project identifier for grouping requests |
proxyUrl | String | No | http://localhost:8080 | Cognisafe Go proxy URL |
apiUrl | String | No | http://localhost:8000 | Cognisafe FastAPI backend URL |
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():

