> ## Documentation Index
> Fetch the complete documentation index at: https://pulze.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Policies

Every request to Pulze can be configured through our Policies. Policies is a way to customize the *behaviour* of your request, but it does not
affect model selection or labelling.

<Tip>As of now, you can only set the policies on a per-request basis. We are planning to add settings to the **Model Settings page** at some point in the future.</Tip>

## Policies

### Max cost (for the whole request)

```yaml theme={null}
key: max_cost
value: float
```

The maximum cost, in your Org's currency unit (currently only USD supported) of the whole request. If you have very complex queries
or large custom data sets, make sure to set this as a high value. *Use with caution*.

<Warning>This feature is not yet available!</Warning>

### Maximum number of times to retry a particular model

```yaml theme={null}
key: max_same_model_retries
value: int >= 0
```

The maximum number of times to retry a request to *any particular model*.

If set to `0`, the system won't retry the request to this model. In general, there will be up to `N+1` LLM calls performed to the same model (the original, and the retries.)

To be used in combination with [`max_switch_model_retries`](#maximum-number-of-different-models-to-try)

<Snippet file="max-num-retries-policy-math.mdx" />

### Maximum number of different models to try

```yaml theme={null}
key: max_switch_model_retries
value: int >= 0
```

The maximum number of *different models* to retry for any particular request.

If set to `0`, the system won't use any other models. In general, Pulze will try the request with `N+1` different LLM models (the best model, and one for each "retry".)

To be used in combination with [`max_same_model_retries`](#maximum-number-of-times-to-retry-a-particular-model)

<Snippet file="max-num-retries-policy-math.mdx" />

### Privacy level

```yaml theme={null}
key: privacy_level
value: 1, 2, 3
```

The level of privacy you want for this particular request, and all of its sub-requests.

1. (default) Store the `prompt`, `response`, and all the metadata associated with it (labels, weights, costs...)
2. Store all the metadata, but the `prompt` and the LLM's `response` will not be logged in any way. The log is still visible, labelled, and searcheable.
3. (stealth mode) The log is not stored\[\*], not visible, not searchable, and no `prompt`, `response` or labels are stored.

<Info>\[\*] Internally we must log the datetime and costs incurred, which we require for billing.</Info>

### Prompt

```yaml theme={null}
key: prompt_id
value: <PROMPT_ID>
```

In some cases, you want to wrap your prompt in a set of predefined instructions, which we call Prompts. Enter the Prompt ID to use it in the request. You can find such ID by clicking on an existing Prompt.
Alternatively, you can set a predefined Prompt by visiting the App's settings tab

## Example

<CodeGroup>
  ```python Policies theme={null}
  policies = {
    "max_retries": 3, # Retry up to 3 times if a request fails
    "privacy_level": 2, # Do not store request or response
    "max_cost": 0.03, # Allow to set a cap on the request cost
    "prompt_id": <PROMPT_ID> # Specify a prompt for the request
  }
  ```

  ```bash cURL request theme={null}
  curl ...
  -H "Authorization ..." \
  -H "Pulze-Policies: {\"max_retries\": 8}
  ```
</CodeGroup>

The above example will modify the policies *for that request only*.
<Tip>You can set *any*, *some*, or *all* the policies on every request</Tip>

If you send [`Pulze-Labels`](/features/custom-headers/labels) header, the policies will be stored as part of the [Labels](/features/labeling) in this format:

```json theme={null}
{
  "policies_max_retries": "8",
  "policies_max_cost": "0.05",
  ...
  "other-pulze-labels": "below",
  "foo": "bar",
  "my_obj": "{\"key\": \"value\"}"
}
```

<Snippet file="auto-store-labels-if-defined.mdx" />

<Warning>Note that `privacy_level` isn't stored at all</Warning>

<Snippet file="request-example-weights-labels-policies.mdx" />
