Documentation Index
Fetch the complete documentation index at: https://cognisafeltd.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Two patching modes
Cognisafe uses different integration strategies depending on whether the LLM provider’s API is OpenAI-compatible.Proxy mode
For OpenAI-compatible providers (OpenAI, Mistral, Ollama), the SDK rewrites the provider client’sbase_url to point to the Cognisafe proxy running on port 8080. The Go proxy:
- Receives the request from your app
- Forwards it to the upstream LLM provider (unchanged)
- Streams the response back to your app
- In parallel, POSTs the full request and response payload to
POST /internal/logon the FastAPI backend — non-blocking, so your app gets the response first
Direct mode
For providers whose API isn’t OpenAI-compatible (Anthropic, Cohere), the SDK wraps the provider client’screate / messages.create method. After the LLM responds:
- Your app receives the response immediately
- The SDK fires a background task that ships the payload to
POST /internal/log
| Provider | Mode | How |
|---|---|---|
| OpenAI | Proxy | base_url rewritten to http://localhost:8080 |
| Mistral | Proxy | base_url rewritten to http://localhost:8080 |
| Ollama | Proxy | base_url rewritten to http://localhost:8080 |
| Anthropic | Direct | messages.create wrapped |
| Cohere | Direct | chat method wrapped |
Async scoring pipeline
Safety scoring happens entirely off the hot path:POST /internal/logreceives the payload and writes it to thellm_requeststable in PostgreSQL (TimescaleDB).- It immediately pushes a job to the
safety_score_jobsRedis queue. - One or more
safety_workerprocesses read from the queue and run PyRIT scorers (currentlycontent_safety,pii_detection,jailbreak_detection,data_poisoning,vector_weakness,unbounded_consumption). - Scorer results are written to the
safety_scorestable — one row per scorer per request. - The dashboard polls for new scores and displays them.
docker compose up --scale safety_worker=N.
Data model
llm_requests
Every LLM API call captured by the proxy or SDK. A TimescaleDB hypertable partitioned on created_at for efficient time-range queries.
Key columns: id, project_id, model, provider, prompt_tokens, completion_tokens, cost_usd, latency_ms, request_body (JSONB), response_body (JSONB), created_at.
safety_scores
One row per scorer per request. Foreign key to llm_requests.
Key columns: id, request_id, scorer_name, score_value (1–5 Likert), score_label (safe / unsafe / unscored), rationale, created_at.
subscriptions
Per-project billing state managed by Stripe webhooks.
Key columns: project_id, tier (free / pro / team / enterprise), stripe_customer_id, stripe_subscription_id, requests_this_period, period_reset_at.
Rate limiting is enforced in POST /internal/log — the API returns HTTP 429 when requests_this_period exceeds the tier limit.
The @cognisafe.trace decorator
For non-standard LLM calls — custom HTTP clients, internal models, fine-tuned endpoints — use the generic decorator:
/internal/log in the background.

