Installation
anthropic) and Cohere (cohere), or use [all] to get everything.
Configuration
Callcognisafe.configure() once at application startup, before any LLM calls are made.
Parameters
* Required if the corresponding environment variable is not set.
Environment variables
As an alternative to passing values toconfigure(), set these environment variables:
configure() reads these automatically when the keyword arguments are omitted.
Provider patches
OpenAI (proxy mode)
patch_openai() rewrites openai.base_url so all calls route through the proxy. The proxy forwards them to https://api.openai.com and logs each request asynchronously.
Anthropic (direct mode)
pip install "cognisafe[anthropic]". The SDK wraps messages.create and ships payloads to the backend after the response is returned.
Mistral (proxy mode)
Cohere (direct mode)
pip install "cognisafe[all]".
The @cognisafe.trace decorator
Use trace for any LLM call that doesn’t go through a patched provider — custom endpoints, fine-tuned models, internal APIs:
/internal/log in a background thread. The decorated function’s execution is not blocked.
