---
title: Push events for an Agent Observability experiment
description: Push spans and metrics for an Agent Observability experiment.
breadcrumbs: Documentación > API > Push events for an Agent Observability experiment
---

> For the complete documentation index, see [llms.txt](https://dnd37xeb23o8n.cloudfront.net/stefon.simmons/docs-astro-web-10435/llms.txt).

# Push events for an Agent Observability experiment

## v2 (latest)

{% alert level="warning" %}
**Note**: This endpoint is in preview and is subject to change.
If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help.md).
{% /alert %}

| Datadog site      | API endpoint                                                                            |
| ----------------- | --------------------------------------------------------------------------------------- |
| app.datadoghq.com | POST https://api.datadoghq.com/api/v2/llm-obs/v1/experiments/{experiment_id}/events     |
| us3.datadoghq.com | POST https://api.us3.datadoghq.com/api/v2/llm-obs/v1/experiments/{experiment_id}/events |
| us5.datadoghq.com | POST https://api.us5.datadoghq.com/api/v2/llm-obs/v1/experiments/{experiment_id}/events |
| app.datadoghq.eu  | POST https://api.datadoghq.eu/api/v2/llm-obs/v1/experiments/{experiment_id}/events      |
| ap1.datadoghq.com | POST https://api.ap1.datadoghq.com/api/v2/llm-obs/v1/experiments/{experiment_id}/events |
| ap2.datadoghq.com | POST https://api.ap2.datadoghq.com/api/v2/llm-obs/v1/experiments/{experiment_id}/events |
| uk1.datadoghq.com | POST https://api.uk1.datadoghq.com/api/v2/llm-obs/v1/experiments/{experiment_id}/events |
| app.ddog-gov.com  | POST https://api.ddog-gov.com/api/v2/llm-obs/v1/experiments/{experiment_id}/events      |
| us2.ddog-gov.com  | POST https://api.us2.ddog-gov.com/api/v2/llm-obs/v1/experiments/{experiment_id}/events  |

### Overview

Push spans and metrics for an Agent Observability experiment.

### Arguments

#### Path Parameters

| Field                      | Type   | Description                                   |
| -------------------------- | ------ | --------------------------------------------- |
| experiment_id [*required*] | string | The ID of the Agent Observability experiment. |

### Request

#### Body Data (required)

Experiment events payload.

{% tabs %}
{% tab label="Model" %}
| Parent field | Field                     | Type           | Description                                                                                                                    |
| ------------ | ------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|              | data [*required*]         | object         | Data object for pushing experiment events.                                                                                     |
| data         | attributes [*required*]   | object         | Attributes for pushing experiment events including spans and metrics.                                                          |
| attributes   | metrics                   | [object]       | List of metrics to push for the experiment.                                                                                    |
| metrics      | assessment                | enum           | Assessment result for an Agent Observability experiment metric. Allowed enum values: `pass`, `fail`.                           |
| metrics      | boolean_value             | boolean        | Boolean value. Used when `metric_type` is `boolean`.                                                                           |
| metrics      | categorical_value         | string         | Categorical value. Used when `metric_type` is `categorical`.                                                                   |
| metrics      | error                     | object         | Error details for an experiment metric evaluation.                                                                             |
| error        | message                   | string         | Error message associated with the metric evaluation.                                                                           |
| metrics      | json_value                | object         | JSON value. Used when `metric_type` is `json`.                                                                                 |
| metrics      | label [*required*]        | string         | Label or name for the metric.                                                                                                  |
| metrics      | metadata                  | object         | Arbitrary metadata associated with the metric.                                                                                 |
| metrics      | metric_type [*required*]  | enum           | Type of metric recorded for an Agent Observability experiment. Allowed enum values: `score`, `categorical`, `boolean`, `json`. |
| metrics      | reasoning                 | string         | Human-readable reasoning for the metric value.                                                                                 |
| metrics      | score_value               | double         | Numeric score value. Used when `metric_type` is `score`.                                                                       |
| metrics      | span_id [*required*]      | string         | The ID of the span this metric measures.                                                                                       |
| metrics      | tags                      | [string]       | List of tags associated with the metric.                                                                                       |
| metrics      | timestamp_ms [*required*] | int64          | Timestamp when the metric was recorded, in milliseconds since Unix epoch.                                                      |
| attributes   | spans                     | [object]       | List of spans to push for the experiment.                                                                                      |
| spans        | dataset_id [*required*]   | string         | Dataset ID associated with this span.                                                                                          |
| spans        | duration [*required*]     | int64          | Duration of the span in nanoseconds.                                                                                           |
| spans        | meta                      | object         | Metadata associated with an experiment span.                                                                                   |
| meta         | error                     | object         | Error details for an experiment span.                                                                                          |
| error        | message                   | string         | Error message.                                                                                                                 |
| error        | stack                     | string         | Stack trace of the error.                                                                                                      |
| error        | type                      | string         | The error type or exception class name.                                                                                        |
| meta         | expected_output           | object         | Expected output for the span, used for evaluation.                                                                             |
| meta         | input                     | object <oneOf> | Represents any valid JSON value.                                                                                               |
| input        | Object 1                  | string         | A scalar value represented as a string.                                                                                        |
| input        | Object 2                  | double         | A scalar numeric value.                                                                                                        |
| input        | Object 3                  | object         | An arbitrary object value with additional properties.                                                                          |
| input        | Object 4                  | [<oneOf>]      | An array of arbitrary values.                                                                                                  |
| Object 4     | Object 1                  | string         | A scalar value represented as a string.                                                                                        |
| Object 4     | Object 2                  | double         | A scalar numeric value.                                                                                                        |
| Object 4     | Object 3                  | object         | An arbitrary object value with additional properties.                                                                          |
| Object 4     | Object 4                  | boolean        | A scalar boolean value.                                                                                                        |
| input        | Object 5                  | boolean        | A scalar boolean value.                                                                                                        |
| meta         | output                    | object <oneOf> | Represents any valid JSON value.                                                                                               |
| output       | Object 1                  | string         | A scalar value represented as a string.                                                                                        |
| output       | Object 2                  | double         | A scalar numeric value.                                                                                                        |
| output       | Object 3                  | object         | An arbitrary object value with additional properties.                                                                          |
| output       | Object 4                  | [<oneOf>]      | An array of arbitrary values.                                                                                                  |
| Object 4     | Object 1                  | string         | A scalar value represented as a string.                                                                                        |
| Object 4     | Object 2                  | double         | A scalar numeric value.                                                                                                        |
| Object 4     | Object 3                  | object         | An arbitrary object value with additional properties.                                                                          |
| Object 4     | Object 4                  | boolean        | A scalar boolean value.                                                                                                        |
| output       | Object 5                  | boolean        | A scalar boolean value.                                                                                                        |
| spans        | name [*required*]         | string         | Name of the span.                                                                                                              |
| spans        | project_id [*required*]   | string         | Project ID associated with this span.                                                                                          |
| spans        | span_id [*required*]      | string         | Unique identifier of the span.                                                                                                 |
| spans        | start_ns [*required*]     | int64          | Start time of the span in nanoseconds since Unix epoch.                                                                        |
| spans        | status [*required*]       | enum           | Status of the span. Allowed enum values: `ok`, `error`.                                                                        |
| spans        | tags                      | [string]       | List of tags associated with the span.                                                                                         |
| spans        | trace_id [*required*]     | string         | Trace ID for the span.                                                                                                         |
| data         | type [*required*]         | enum           | Resource type of an Agent Observability experiment. Allowed enum values: `experiments`.                                        |
{% /tab %}

{% tab label="Example" %}
```json
{
  "data": {
    "attributes": {
      "metrics": [
        {
          "assessment": "pass",
          "boolean_value": false,
          "categorical_value": "string",
          "error": {
            "message": "string"
          },
          "json_value": {},
          "label": "faithfulness",
          "metadata": {},
          "metric_type": "score",
          "reasoning": "string",
          "score_value": "number",
          "span_id": "span-7a1b2c3d",
          "tags": [],
          "timestamp_ms": 1705314600000
        }
      ],
      "spans": [
        {
          "dataset_id": "9f64e5c7-dc5a-45c8-a17c-1b85f0bec97d",
          "duration": 1500000000,
          "meta": {
            "error": {
              "message": "Model response timed out",
              "stack": "Traceback (most recent call last):\n  File \"main.py\", line 10, in <module>\n    response = model.generate(input)\n  File \"model.py\", line 45, in generate\n    raise TimeoutError(\"Model response timed out\")\nTimeoutError: Model response timed out",
              "type": "TimeoutError"
            },
            "expected_output": {},
            "input": {
              "description": "undefined",
              "type": "undefined"
            },
            "output": {
              "description": "undefined",
              "type": "undefined"
            }
          },
          "name": "llm_call",
          "project_id": "a33671aa-24fd-4dcd-9b33-a8ec7dde7751",
          "span_id": "span-7a1b2c3d",
          "start_ns": 1705314600000000000,
          "status": "ok",
          "tags": [],
          "trace_id": "abc123def456"
        }
      ]
    },
    "type": "experiments"
  }
}
```
{% /tab %}
{% /tabs %}

### Response

{% tabs %}
{% tab label="202" %}
Accepted
{% /tab %}

{% tab label="400" %}
Bad Request

{% tabs %}
{% tab label="Model" %}
API error response.

| Parent field | Field               | Type     | Description                                                                     |
| ------------ | ------------------- | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail              | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                | object   | Non-standard meta-information about the error                                   |
| errors       | source              | object   | References to the source of the error.                                          |
| source       | header              | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter           | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer             | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status              | string   | Status code of the response.                                                    |
| errors       | title               | string   | Short human-readable summary of the error.                                      |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="401" %}
Unauthorized

{% tabs %}
{% tab label="Model" %}
API error response.

| Parent field | Field               | Type     | Description                                                                     |
| ------------ | ------------------- | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail              | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                | object   | Non-standard meta-information about the error                                   |
| errors       | source              | object   | References to the source of the error.                                          |
| source       | header              | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter           | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer             | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status              | string   | Status code of the response.                                                    |
| errors       | title               | string   | Short human-readable summary of the error.                                      |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="403" %}
Forbidden

{% tabs %}
{% tab label="Model" %}
API error response.

| Parent field | Field               | Type     | Description                                                                     |
| ------------ | ------------------- | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail              | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                | object   | Non-standard meta-information about the error                                   |
| errors       | source              | object   | References to the source of the error.                                          |
| source       | header              | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter           | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer             | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status              | string   | Status code of the response.                                                    |
| errors       | title               | string   | Short human-readable summary of the error.                                      |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="404" %}
Not Found

{% tabs %}
{% tab label="Model" %}
API error response.

| Parent field | Field               | Type     | Description                                                                     |
| ------------ | ------------------- | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail              | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                | object   | Non-standard meta-information about the error                                   |
| errors       | source              | object   | References to the source of the error.                                          |
| source       | header              | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter           | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer             | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status              | string   | Status code of the response.                                                    |
| errors       | title               | string   | Short human-readable summary of the error.                                      |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="429" %}
Too many requests

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}
{% /tabs %}

### Code Example

{% tabs %}
{% tab label="Curl" %}
```bash
# Path parameters
export experiment_id="3fd6b5e0-8910-4b1c-a7d0-5b84de329012"

# Set your Datadog site and credentials
export DD_SITE="datadoghq.com" # Or us3.datadoghq.com, us5.datadoghq.com, datadoghq.eu, ap1.datadoghq.com, ap2.datadoghq.com, uk1.datadoghq.com, ddog-gov.com, us2.ddog-gov.com
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/llm-obs/v1/experiments/${experiment_id}/events" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "metrics": [
        {
          "assessment": "pass",
          "label": "faithfulness",
          "metric_type": "score",
          "span_id": "span-7a1b2c3d",
          "timestamp_ms": 1705314600000
        }
      ],
      "spans": [
        {
          "dataset_id": "9f64e5c7-dc5a-45c8-a17c-1b85f0bec97d",
          "duration": 1500000000,
          "name": "llm_call",
          "project_id": "a33671aa-24fd-4dcd-9b33-a8ec7dde7751",
          "span_id": "span-7a1b2c3d",
          "start_ns": 1705314600000000000,
          "status": "ok",
          "trace_id": "abc123def456"
        }
      ]
    },
    "type": "experiments"
  }
}
EOF
```
{% /tab %}

{% tab label="Go" %}
```go
// Push events for an Agent Observability experiment returns "Accepted" response

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
	"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)

func main() {
	body := datadogV2.LLMObsExperimentEventsRequest{
		Data: datadogV2.LLMObsExperimentEventsDataRequest{
			Attributes: datadogV2.LLMObsExperimentEventsDataAttributesRequest{
				Metrics: []datadogV2.LLMObsExperimentMetric{
					{
						Assessment:  datadogV2.LLMOBSMETRICASSESSMENT_PASS.Ptr(),
						Error:       &datadogV2.LLMObsExperimentMetricError{},
						Label:       "faithfulness",
						MetricType:  datadogV2.LLMOBSMETRICSCORETYPE_SCORE,
						SpanId:      "span-7a1b2c3d",
						Tags:        []string{},
						TimestampMs: 1705314600000,
					},
				},
				Spans: []datadogV2.LLMObsExperimentSpan{
					{
						DatasetId: "9f64e5c7-dc5a-45c8-a17c-1b85f0bec97d",
						Duration:  1500000000,
						Meta: &datadogV2.LLMObsExperimentSpanMeta{
							Error: &datadogV2.LLMObsExperimentSpanError{
								Message: datadog.PtrString("Model response timed out"),
								Stack: datadog.PtrString(`Traceback (most recent call last):
  File "main.py", line 10, in <module>
    response = model.generate(input)
  File "model.py", line 45, in generate
    raise TimeoutError("Model response timed out")
TimeoutError: Model response timed out`),
								Type: datadog.PtrString("TimeoutError"),
							},
							Input:  *datadogV2.NewNullableAnyValue(nil),
							Output: *datadogV2.NewNullableAnyValue(nil),
						},
						Name:      "llm_call",
						ProjectId: "a33671aa-24fd-4dcd-9b33-a8ec7dde7751",
						SpanId:    "span-7a1b2c3d",
						StartNs:   1705314600000000000,
						Status:    datadogV2.LLMOBSEXPERIMENTSPANSTATUS_OK,
						Tags:      []string{},
						TraceId:   "abc123def456",
					},
				},
			},
			Type: datadogV2.LLMOBSEVENTTYPE_EVENTS,
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	ctx = context.WithValue(ctx, datadog.ContextAccessToken, os.Getenv("DD_BEARER_TOKEN"))
	configuration := datadog.NewConfiguration()
	configuration.SetUnstableOperationEnabled("v2.CreateLLMObsExperimentEvents", true)
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewAgentObservabilityApi(apiClient)
	r, err := api.CreateLLMObsExperimentEvents(ctx, "experiment_id", body)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `AgentObservabilityApi.CreateLLMObsExperimentEvents`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}
}
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=go) and then save the example to `main.go` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"
```
{% /tab %}

{% tab label="Java" %}
```java
// Push events for an Agent Observability experiment returns "Accepted" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.AgentObservabilityApi;
import com.datadog.api.client.v2.model.LLMObsEventType;
import com.datadog.api.client.v2.model.LLMObsExperimentEventsDataAttributesRequest;
import com.datadog.api.client.v2.model.LLMObsExperimentEventsDataRequest;
import com.datadog.api.client.v2.model.LLMObsExperimentEventsRequest;
import com.datadog.api.client.v2.model.LLMObsExperimentMetric;
import com.datadog.api.client.v2.model.LLMObsExperimentMetricError;
import com.datadog.api.client.v2.model.LLMObsExperimentSpan;
import com.datadog.api.client.v2.model.LLMObsExperimentSpanError;
import com.datadog.api.client.v2.model.LLMObsExperimentSpanMeta;
import com.datadog.api.client.v2.model.LLMObsExperimentSpanStatus;
import com.datadog.api.client.v2.model.LLMObsMetricAssessment;
import com.datadog.api.client.v2.model.LLMObsMetricScoreType;
import java.util.Collections;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));
    defaultClient.setUnstableOperationEnabled("v2.createLLMObsExperimentEvents", true);
    AgentObservabilityApi apiInstance = new AgentObservabilityApi(defaultClient);

    LLMObsExperimentEventsRequest body =
        new LLMObsExperimentEventsRequest()
            .data(
                new LLMObsExperimentEventsDataRequest()
                    .attributes(
                        new LLMObsExperimentEventsDataAttributesRequest()
                            .metrics(
                                Collections.singletonList(
                                    new LLMObsExperimentMetric()
                                        .assessment(LLMObsMetricAssessment.PASS)
                                        .error(new LLMObsExperimentMetricError())
                                        .label("faithfulness")
                                        .metricType(LLMObsMetricScoreType.SCORE)
                                        .spanId("span-7a1b2c3d")
                                        .timestampMs(1705314600000L)))
                            .spans(
                                Collections.singletonList(
                                    new LLMObsExperimentSpan()
                                        .datasetId("9f64e5c7-dc5a-45c8-a17c-1b85f0bec97d")
                                        .duration(1500000000L)
                                        .meta(
                                            new LLMObsExperimentSpanMeta()
                                                .error(
                                                    new LLMObsExperimentSpanError()
                                                        .message("Model response timed out")
                                                        .stack(
                                                            """
Traceback (most recent call last):
  File "main.py", line 10, in <module>
    response = model.generate(input)
  File "model.py", line 45, in generate
    raise TimeoutError("Model response timed out")
TimeoutError: Model response timed out
""")
                                                        .type("TimeoutError"))
                                                .input(null)
                                                .output(null))
                                        .name("llm_call")
                                        .projectId("a33671aa-24fd-4dcd-9b33-a8ec7dde7751")
                                        .spanId("span-7a1b2c3d")
                                        .startNs(1705314600000000000L)
                                        .status(LLMObsExperimentSpanStatus.OK)
                                        .traceId("abc123def456"))))
                    .type(LLMObsEventType.EVENTS));

    try {
      apiInstance.createLLMObsExperimentEvents("3fd6b5e0-8910-4b1c-a7d0-5b84de329012", body);
    } catch (ApiException e) {
      System.err.println(
          "Exception when calling AgentObservabilityApi#createLLMObsExperimentEvents");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=java) and then save the example to `Example.java` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"
```
{% /tab %}

{% tab label="Python" %}
```python
"""
Push events for an Agent Observability experiment returns "Accepted" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.agent_observability_api import AgentObservabilityApi
from datadog_api_client.v2.model.llm_obs_event_type import LLMObsEventType
from datadog_api_client.v2.model.llm_obs_experiment_events_data_attributes_request import (
    LLMObsExperimentEventsDataAttributesRequest,
)
from datadog_api_client.v2.model.llm_obs_experiment_events_data_request import LLMObsExperimentEventsDataRequest
from datadog_api_client.v2.model.llm_obs_experiment_events_request import LLMObsExperimentEventsRequest
from datadog_api_client.v2.model.llm_obs_experiment_metric import LLMObsExperimentMetric
from datadog_api_client.v2.model.llm_obs_experiment_metric_error import LLMObsExperimentMetricError
from datadog_api_client.v2.model.llm_obs_experiment_span import LLMObsExperimentSpan
from datadog_api_client.v2.model.llm_obs_experiment_span_error import LLMObsExperimentSpanError
from datadog_api_client.v2.model.llm_obs_experiment_span_meta import LLMObsExperimentSpanMeta
from datadog_api_client.v2.model.llm_obs_experiment_span_status import LLMObsExperimentSpanStatus
from datadog_api_client.v2.model.llm_obs_metric_assessment import LLMObsMetricAssessment
from datadog_api_client.v2.model.llm_obs_metric_score_type import LLMObsMetricScoreType

body = LLMObsExperimentEventsRequest(
    data=LLMObsExperimentEventsDataRequest(
        attributes=LLMObsExperimentEventsDataAttributesRequest(
            metrics=[
                LLMObsExperimentMetric(
                    assessment=LLMObsMetricAssessment.PASS,
                    error=LLMObsExperimentMetricError(),
                    label="faithfulness",
                    metric_type=LLMObsMetricScoreType.SCORE,
                    span_id="span-7a1b2c3d",
                    tags=[],
                    timestamp_ms=1705314600000,
                ),
            ],
            spans=[
                LLMObsExperimentSpan(
                    dataset_id="9f64e5c7-dc5a-45c8-a17c-1b85f0bec97d",
                    duration=1500000000,
                    meta=LLMObsExperimentSpanMeta(
                        error=LLMObsExperimentSpanError(
                            message="Model response timed out",
                            stack='Traceback (most recent call last):\n  File "main.py", line 10, in <module>\n    response = model.generate(input)\n  File "model.py", line 45, in generate\n    raise TimeoutError("Model response timed out")\nTimeoutError: Model response timed out',
                            type="TimeoutError",
                        ),
                        input=None,
                        output=None,
                    ),
                    name="llm_call",
                    project_id="a33671aa-24fd-4dcd-9b33-a8ec7dde7751",
                    span_id="span-7a1b2c3d",
                    start_ns=1705314600000000000,
                    status=LLMObsExperimentSpanStatus.OK,
                    tags=[],
                    trace_id="abc123def456",
                ),
            ],
        ),
        type=LLMObsEventType.EVENTS,
    ),
)

configuration = Configuration()
configuration.access_token = environ["DD_BEARER_TOKEN"]
configuration.unstable_operations["create_llm_obs_experiment_events"] = True
with ApiClient(configuration) as api_client:
    api_instance = AgentObservabilityApi(api_client)
    api_instance.create_llm_obs_experiment_events(experiment_id="experiment_id", body=body)
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=python) and then save the example to `example.py` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"
```
{% /tab %}

{% tab label="Ruby" %}
```ruby
# Push events for an Agent Observability experiment returns "Accepted" response

require "datadog_api_client"
DatadogAPIClient.configure do |config|
  config.access_token = ENV["DD_BEARER_TOKEN"]
  config.unstable_operations["v2.create_llm_obs_experiment_events".to_sym] = true
end
api_instance = DatadogAPIClient::V2::AgentObservabilityAPI.new

body = DatadogAPIClient::V2::LLMObsExperimentEventsRequest.new({
  data: DatadogAPIClient::V2::LLMObsExperimentEventsDataRequest.new({
    attributes: DatadogAPIClient::V2::LLMObsExperimentEventsDataAttributesRequest.new({
      metrics: [
        DatadogAPIClient::V2::LLMObsExperimentMetric.new({
          assessment: DatadogAPIClient::V2::LLMObsMetricAssessment::PASS,
          error: DatadogAPIClient::V2::LLMObsExperimentMetricError.new({}),
          label: "faithfulness",
          metric_type: DatadogAPIClient::V2::LLMObsMetricScoreType::SCORE,
          span_id: "span-7a1b2c3d",
          tags: [],
          timestamp_ms: 1705314600000,
        }),
      ],
      spans: [
        DatadogAPIClient::V2::LLMObsExperimentSpan.new({
          dataset_id: "9f64e5c7-dc5a-45c8-a17c-1b85f0bec97d",
          duration: 1500000000,
          meta: DatadogAPIClient::V2::LLMObsExperimentSpanMeta.new({
            error: DatadogAPIClient::V2::LLMObsExperimentSpanError.new({
              message: "Model response timed out",
              stack: 'Traceback (most recent call last):\n  File "main.py", line 10, in <module>\n    response = model.generate(input)\n  File "model.py", line 45, in generate\n    raise TimeoutError("Model response timed out")\nTimeoutError: Model response timed out',
              type: "TimeoutError",
            }),
            input: nil,
            output: nil,
          }),
          name: "llm_call",
          project_id: "a33671aa-24fd-4dcd-9b33-a8ec7dde7751",
          span_id: "span-7a1b2c3d",
          start_ns: 1705314600000000000,
          status: DatadogAPIClient::V2::LLMObsExperimentSpanStatus::OK,
          tags: [],
          trace_id: "abc123def456",
        }),
      ],
    }),
    type: DatadogAPIClient::V2::LLMObsEventType::EVENTS,
  }),
})
p api_instance.create_llm_obs_experiment_events("experiment_id", body)
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=ruby) and then save the example to `example.rb` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"
```
{% /tab %}

{% tab label="Rust" %}
```rust
// Push events for an Agent Observability experiment returns "Accepted" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_agent_observability::AgentObservabilityAPI;
use datadog_api_client::datadogV2::model::LLMObsEventType;
use datadog_api_client::datadogV2::model::LLMObsExperimentEventsDataAttributesRequest;
use datadog_api_client::datadogV2::model::LLMObsExperimentEventsDataRequest;
use datadog_api_client::datadogV2::model::LLMObsExperimentEventsRequest;
use datadog_api_client::datadogV2::model::LLMObsExperimentMetric;
use datadog_api_client::datadogV2::model::LLMObsExperimentMetricError;
use datadog_api_client::datadogV2::model::LLMObsExperimentSpan;
use datadog_api_client::datadogV2::model::LLMObsExperimentSpanError;
use datadog_api_client::datadogV2::model::LLMObsExperimentSpanMeta;
use datadog_api_client::datadogV2::model::LLMObsExperimentSpanStatus;
use datadog_api_client::datadogV2::model::LLMObsMetricAssessment;
use datadog_api_client::datadogV2::model::LLMObsMetricScoreType;

#[tokio::main]
async fn main() {
    let body = LLMObsExperimentEventsRequest::new(LLMObsExperimentEventsDataRequest::new(
        LLMObsExperimentEventsDataAttributesRequest::new()
            .metrics(vec![LLMObsExperimentMetric::new(
                "faithfulness".to_string(),
                LLMObsMetricScoreType::SCORE,
                "span-7a1b2c3d".to_string(),
                1705314600000,
            )
            .assessment(LLMObsMetricAssessment::PASS)
            .error(LLMObsExperimentMetricError::new())
            .tags(vec![])])
            .spans(vec![LLMObsExperimentSpan::new(
                "9f64e5c7-dc5a-45c8-a17c-1b85f0bec97d".to_string(),
                1500000000,
                "llm_call".to_string(),
                "a33671aa-24fd-4dcd-9b33-a8ec7dde7751".to_string(),
                "span-7a1b2c3d".to_string(),
                1705314600000000000,
                LLMObsExperimentSpanStatus::OK,
                "abc123def456".to_string(),
            )
            .meta(
                LLMObsExperimentSpanMeta::new()
                    .error(
                        LLMObsExperimentSpanError::new()
                            .message("Model response timed out".to_string())
                            .stack(
                                r#"Traceback (most recent call last):
  File "main.py", line 10, in <module>
    response = model.generate(input)
  File "model.py", line 45, in generate
    raise TimeoutError("Model response timed out")
TimeoutError: Model response timed out"#
                                    .to_string(),
                            )
                            .type_("TimeoutError".to_string()),
                    )
                    .input(None)
                    .output(None),
            )
            .tags(vec![])]),
        LLMObsEventType::EVENTS,
    ));
    let mut configuration = datadog::Configuration::new();
    configuration.set_unstable_operation_enabled("v2.create_llm_obs_experiment_events", true);
    let api = AgentObservabilityAPI::with_config(configuration);
    let resp = api
        .create_llm_obs_experiment_events("experiment_id".to_string(), body)
        .await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=rust) and then save the example to `src/main.rs` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run
```
{% /tab %}

{% tab label="TypeScript" %}
```typescript
/**
 * Push events for an Agent Observability experiment returns "Accepted" response
 */

import { client, v2 } from "@datadog/datadog-api-client";

const configuration = client.createConfiguration({
  authMethods: {
    AuthZ: {
      accessToken: process.env.DD_BEARER_TOKEN as string,
    },
  },
});
configuration.unstableOperations["v2.createLLMObsExperimentEvents"] = true;
const apiInstance = new v2.AgentObservabilityApi(configuration);

const params: v2.AgentObservabilityApiCreateLLMObsExperimentEventsRequest = {
  body: {
    data: {
      attributes: {
        metrics: [
          {
            assessment: "pass",
            error: {},
            label: "faithfulness",
            metricType: "score",
            spanId: "span-7a1b2c3d",
            tags: [],
            timestampMs: 1705314600000,
          },
        ],
        spans: [
          {
            datasetId: "9f64e5c7-dc5a-45c8-a17c-1b85f0bec97d",
            duration: 1500000000,
            meta: {
              error: {
                message: "Model response timed out",
                stack: `Traceback (most recent call last):
  File "main.py", line 10, in <module>
    response = model.generate(input)
  File "model.py", line 45, in generate
    raise TimeoutError("Model response timed out")
TimeoutError: Model response timed out`,
                type: "TimeoutError",
              },
              input: undefined,
              output: undefined,
            },
            name: "llm_call",
            projectId: "a33671aa-24fd-4dcd-9b33-a8ec7dde7751",
            spanId: "span-7a1b2c3d",
            startNs: 1705314600000000000,
            status: "ok",
            tags: [],
            traceId: "abc123def456",
          },
        ],
      },
      type: "events",
    },
  },
  experimentId: "experiment_id",
};

apiInstance
  .createLLMObsExperimentEvents(params)
  .then((data: any) => {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data)
    );
  })
  .catch((error: any) => console.error(error));
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=typescript) and then save the example to `example.ts` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"
```
{% /tab %}
{% /tabs %}
