# Decision calls

Trace calls your own code makes to a classification model, with their questions, answers, tokens and cost.

A decision call is a call to a classification model: a model that answers a set of questions about a state, such as a ticket or a conversation. When your code calls one directly, Brizz cannot see it. Wrap the call and it shows in the conversation with its questions, answers, tokens and cost.

## Trace a call

:::tabs
:::tab[Python]
```python
import brizz

with brizz.decision_call(
    provider="microsoft", model="microsoft-decision-1", state=ticket, questions=questions
) as call:
    response = client.decide(ticket, questions)
    call.set_answers(response.answers)
    call.set_usage(input_tokens=response.usage.input, output_tokens=response.usage.output)
    call.set_cost(0.0001)  # optional, in USD
```

`adecision_call` is the `async with` form.
:::tab[TypeScript]
```typescript
import { decisionCall } from '@brizz/sdk';

const response = await decisionCall(
  { provider: 'microsoft', model: 'microsoft-decision-1', state, questions },
  async (call) => {
    const r = await client.decide(state, questions);
    call.setAnswers(r.answers);
    call.setUsage({ inputTokens: r.usage.input, outputTokens: r.usage.output });
    call.setCost(0.0001); // optional, in USD
    return r;
  },
);
```
:::

- `provider` and `model` name who served the call and the model that answered. Pass `request_model` / `requestModel` too when your request named a deployment or an alias instead.
- `state` is a string or any JSON value. `questions` and the answers are recorded as you pass them.
- If the call raises, it is recorded as failed and the error reaches your code unchanged.

## Record a call afterwards

For a call that already happened, pass everything at once, with optional start and end times:

:::tabs
:::tab[Python]
```python
brizz.record_decision_call(
    provider="microsoft", model="microsoft-decision-1", state=ticket, questions=questions,
    answers=answers, input_tokens=555, output_tokens=6, start_time=started_at, end_time=ended_at,
)
```
:::tab[TypeScript]
```typescript
import { recordDecisionCall } from '@brizz/sdk';

recordDecisionCall({
  provider: 'microsoft', model: 'microsoft-decision-1', state, questions,
  answers, inputTokens: 555, outputTokens: 6, startTime: startedAt, endTime: endedAt,
});
```
:::

Times are a `datetime` in Python (a naive one is read as UTC) and a `Date` in TypeScript.

## Sessions and properties

A decision call joins the current session and carries the current custom properties, like any other span. To set them for one call, wrap it in the usual helpers: `with_session_id` and `custom_properties` in Python, `callWithSessionId` and `callWithProperties` in TypeScript.

## Other spans inside the call

Inside the wrapped block, instrumentation is turned off so an instrumented HTTP or model client does not record the same call twice. In Python, a span your own code starts in the block is kept. In TypeScript, OpenTelemetry can only turn off every span, so your own spans inside the callback are dropped too.

## Sending the span yourself

Without the SDK, send a span with `gen_ai.operation.name` set to `classify`, `gen_ai.provider.name`, `gen_ai.request.model` / `gen_ai.response.model` and the usage counts. Put the state as a text part and the questions as a `<provider>.questions` part of `gen_ai.input.messages`, and the answers as a `<provider>.answers` part of `gen_ai.output.messages`.

---

[All Brizz documentation](https://docs.brizz.ai/llms.txt) · [Full documentation (single file)](https://docs.brizz.ai/llms-full.txt)
