# Cookbook

Short recipes for the `whitecircle` Python SDK. Every snippet uses the real API; concepts and the HTTP reference
live at https://whitecircle.com/docs.

## Read this in two minutes

1. Skim "The model" below: it is everything the SDK assumes you know.
2. Read [Getting started](https://whitecircle.com/sdk/python/getting-started.md) for configuration and how to read a result.
3. Jump to the page for your task in the table. Pages are independent.
4. If a check returns no verdict (`result.checked` is `False`), read [Metadata and Conditions](https://whitecircle.com/sdk/python/metadata-and-conditions.md).

| Page | Task |
| --- | --- |
| [Getting started](https://whitecircle.com/sdk/python/getting-started.md) | Configure the client, run a first check, read the result |
| [Metadata and Conditions](https://whitecircle.com/sdk/python/metadata-and-conditions.md) | Choose which Policies run; debug "no verdict" |
| [Inline Policies](https://whitecircle.com/sdk/python/inline-policies.md) | Send a Policy's rules with the check, then reference it by `external_id` |
| [Context and resets](https://whitecircle.com/sdk/python/context.md) | Conversations, `Event.reset()`, backfilling history |
| [Agents and tools](https://whitecircle.com/sdk/python/agents-and-tools.md) | Tool calls, agent steps, parents and links, the run graph |
| [Streaming replies](https://whitecircle.com/sdk/python/streaming.md) | Show only checked text while the model generates it |
| [Images](https://whitecircle.com/sdk/python/images.md) | Check standalone images and images inside a conversation |
| [Managing Policies](https://whitecircle.com/sdk/python/managing-policies.md) | Create Policies, Metrics and Conditions; shadow mode to production |
| [Strikes and webhooks](https://whitecircle.com/sdk/python/strikes-and-webhooks.md) | User risk, strikes, appeals, user properties, verifying webhooks |
| [Usage](https://whitecircle.com/sdk/python/usage.md) | Read billed usage and cost per Event type (`client.billing.usage()`) |
| [Errors and testing](https://whitecircle.com/sdk/python/errors-and-testing.md) | Exceptions, retries, timeouts, logging, testing your code |
| [Recipe: support chatbot](https://whitecircle.com/sdk/python/chatbot.md) | All of the above in one async integration |

## The model

- You send **Events**: a user message, an assistant reply, a tool call, an agent step, an image.
- Each Event belongs to an **Environment** (`environment_id`, required on every Events call).
- Active **Conditions** on that Environment match the Event's `metadata` and select **Policies**. No match, no
  Policies, no verdict.
- You get `result.flagged`, a result per Policy in `result.policies`, and `result.checked` to tell "passed" from
  "not checked".
- Events with the same `external_session_id` form a conversation: earlier Events are context for later ones.

```python
from whitecircle import Event, WhiteCircle

client = WhiteCircle()  # WHITECIRCLE_API_KEY, WHITECIRCLE_ENVIRONMENT_ID

result = client.events.check(
    Event.user("Can you prescribe antibiotics?", metadata={"app": "pharmacy-bot"}),
    external_session_id="conversation_456",
)
print(result.checked, result.flagged, result.note)
```
