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

# Log feedback

> Annotate model's completions with your feedback

Adaptive Engine allows you to easily log feedback on completions to monitor and improve your models.

All metric feedback must be logged against a `feedback_key` (see [Feedback](/v0.5/concepts/feedback)).

When you make an [inference request](/v0.5/guides/inference), the API response includes a `completion_id` UUID along with the
model’s output (see [Make inference requests](/v0.5/guides/inference) to learn more). You must log your feedback
for an output using its completion\_id.

<Warning>
  Make sure to use the response’s `completion_id` for logging, not its `id`.
</Warning>

You can access the `completion_id` for a Chat API response as follows:

<CodeGroup>
  ```python requests theme={null}
  completion_id = response.json()["choices"][0]["completion_id"]
  ```

  ```python Adaptive SDK / OpenAI Python theme={null}
  completion_id = response.choices[0].completion_id
  ```
</CodeGroup>

If you are passing `stream=True` to the Chat API to stream completions, you can find the same `completion_id` in each streamed chunk as follows:

```python Adaptive SDK / OpenAI Python theme={null}
for chunk in streaming_response:
  completion_id = chunk.choices[0].completion_id
```

## Log metric feedback

Metric feedback allows you to score a completion with scalar or boolean values.
For example, the code snippet below logs that Llama3.1 8B’s completion to your prompt scored a `CSAT` (customer satisfaction score) of 5.

<Info>
  [Create](/v0.5/concepts/authentication) an `Adaptive` client first
</Info>

<CodeGroup>
  ```python Adaptive SDK theme={null}
  response = adaptive.feedback.log_metric(
    value=5,
    feedback_key="CSAT",
    completion_id=completion_id,
    details="This answer was perfect" # optional text details of 
  )
  ```

  ```python requests theme={null}
  import requests

  headers = {"Authorization": "Bearer ADAPTIVE_API_KEY"}
  payload = { 
    "value": 5,
    "metric": "CSAT",
    "completion_id" : completion_id,
    "details": "This answer was perfect"
  }

  response = requests.post(
    url="ADAPTIVE_URL/api/v1/feedback",
    json=payload,
    headers=headers
  )
  ```
</CodeGroup>

As exemplified in the above code snippets, you can log textual `details` for more context or justification on the provided feedback.
See the [SDK Reference](https://adaptive-ml.github.io/adaptive-sdk-docs/adaptive_sdk/resources.html#Feedback.log_metric) to see the full method definition.

## Log preference feedback

Preference feedback allows you to log a pairwise comparison between 2 completions. You can also log a tie between the 2, as equally good or equally bad.

```python Adaptive SDK theme={null}
response = adaptive.feedback.log_preference(
  feedback_key="acceptance",
  preferred_completion="completion_id_1",
  other_completion="completion_id_2",
)
```

See the [SDK Reference](https://adaptive-ml.github.io/adaptive-sdk-docs/adaptive_sdk/resources.html#Feedback.log_preference) to see the full method definition.
